feisty meow concerns codebase  2.140
synchronizable.h
Go to the documentation of this file.
1 #ifndef SYNCHRONIZABLE_CLASS
2 #define SYNCHRONIZABLE_CLASS
3 
4 /*
5 * Name : synchronizable
6 * Author : Chris Koeritz
7 ***
8 * Copyright (c) 2002-$now By Author. This program is free software; you can *
9 * redistribute it and/or modify it under the terms of the GNU General Public *
10 * License as published by the Free Software Foundation; either version 2 of *
11 * the License or (at your option) any later version. This is online at: *
12 * http://www.fsf.org/copyleft/gpl.html *
13 * Please send any updates to: fred@gruntose.com *
14 \*****************************************************************************/
15 
16 #include <octopus/infoton.h>
17 #include <timely/time_stamp.h>
18 
19 namespace synchronic {
20 
22 
33 {
34 public:
36  ADDED, // the object is new.
37  CHANGED, // the object has been modified.
38  DELETED // the object got removed.
39  };
40 
42  // the type of change that has happened for this object. the derived
43  // class must pack this information in the derived pack() method and
44  // retrieve the modification info in unpack(). there are helper functions
45  // pack_mod() and unpack_mod() to automate that responsibility.
46 
48  // when this information was last updated. this should not be packed,
49  // since it is only locally relevant.
50 
51  synchronizable(const structures::string_array &object_id) : infoton(object_id) {}
52  // constructs the base portion of an attribute bundle for an object with
53  // the "object_id". the "object_id" must follow the rules for infoton
54  // classifiers. the last string in the object id is the list-unique
55  // identifier for this set of attributes.
56 
57  enum outcomes {
58  OKAY = basis::common::OKAY, // the operation completed successfully.
59  BAD_TYPE = basis::common::BAD_TYPE, // provided object had an incompatible type.
60  EMPTY = basis::common::IS_EMPTY // the merge resulted in clearing this entry.
61  };
62 
63  // helper functions for packing the modification information.
64  void pack_mod(basis::byte_array &packed_form) const;
65  bool unpack_mod(basis::byte_array &packed_form);
66  int packed_mod_size() const { return sizeof(int); }
68 
69  virtual basis::outcome merge(const synchronizable &to_merge) = 0;
70  // overwrites any attributes in "this" bundle with the contents found
71  // in "to_merge". this can fail if the object types are different.
72 
73  virtual basis::astring text_form() const = 0;
74  // provides a visual form of the data held in this bundle.
75 
76  // promote requirements of the infoton to derived objects.
77  virtual void pack(basis::byte_array &packed_form) const = 0;
78  virtual bool unpack(basis::byte_array &packed_form) = 0;
79  virtual clonable *clone() const = 0;
80  virtual int packed_size() const = 0;
81 };
82 
84 
85 // implementations.
86 
88 { structures::attach(packed_form, int(_mod)); }
89 
91 {
92  int temp;
93  if (!structures::detach(packed_form, temp)) return false;
94  _mod = (modifications)temp;
95  return true;
96 }
97 
98 } //namespace.
99 
100 #endif
101 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
infoton(const structures::string_array &classifier)
creates an infoton with the "classifier".
Definition: infoton.cpp:41
An array of strings with some additional helpful methods.
Definition: string_array.h:32
Encapsulates all of the attributes known for an object.
virtual void pack(basis::byte_array &packed_form) const =0
stuffs the data in the infoton into the "packed_form".
bool unpack_mod(basis::byte_array &packed_form)
synchronizable(const structures::string_array &object_id)
void pack_mod(basis::byte_array &packed_form) const
virtual bool unpack(basis::byte_array &packed_form)=0
restores an infoton from a packed form.
virtual basis::astring text_form() const =0
local version just makes text_form() more functional.
virtual clonable * clone() const =0
must be provided to allow creation of a copy of this object.
timely::time_stamp _updated
virtual int packed_size() const =0
reports how large the infoton will be when packed.
virtual basis::outcome merge(const synchronizable &to_merge)=0
int packed_mod_size() const
returns the size of the packed modifier.
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".