00001 #ifndef ATTRIBUTE_BUNDLE_CLASS 00002 #define ATTRIBUTE_BUNDLE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : attribute_bundle * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 2002-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "dll_list_synch.h" 00019 00020 #include <mechanisms/time_stamp.h> 00021 #include <octopus/infoton.h> 00022 00024 00034 class LIST_SYNCHRONIZER_CLASS_STYLE attribute_bundle : public infoton 00035 { 00036 public: 00037 enum modifications { 00038 ADDED, // the object is new. 00039 CHANGED, // the object has been modified. 00040 DELETED // the object got removed. 00041 }; 00042 00043 modifications _mod; 00044 // the type of change that has happened for this object. the derived 00045 // class must pack this information in the derived pack() method and 00046 // retrieve the modification info in unpack(). there are helper functions 00047 // pack_mod() and unpack_mod() to automate that responsibility. 00048 00049 time_stamp _updated; 00050 // when this information was last updated. this should not be packed, 00051 // since it is only locally relevant. 00052 00053 attribute_bundle(const string_array &object_id) : infoton(object_id) {} 00054 // constructs the base portion of an attribute bundle for an object with 00055 // the "object_id". the "object_id" must follow the rules for infoton 00056 // classifiers. the last string in the object id is the list-unique 00057 // identifier for this set of attributes. 00058 00059 enum outcomes { 00060 OKAY = common::OKAY, // the operation completed successfully. 00061 BAD_TYPE = common::BAD_TYPE, // provided object had an incompatible type. 00062 EMPTY = common::IS_EMPTY // the merge resulted in clearing this entry. 00063 }; 00064 00065 // helper functions for packing the modification information. 00066 void pack_mod(byte_array &packed_form) const; 00067 bool unpack_mod(byte_array &packed_form); 00068 int packed_mod_size() const { return sizeof(int); } 00070 00071 virtual outcome merge(const attribute_bundle &to_merge) = 0; 00072 // overwrites any attributes in "this" bundle with the contents found 00073 // in "to_merge". this can fail if the object types are different. 00074 00075 virtual istring text_form() const = 0; 00076 // provides a visual form of the data held in this bundle. 00077 00078 // promote requirements of the infoton to derived objects. 00079 virtual void pack(byte_array &packed_form) const = 0; 00080 virtual bool unpack(byte_array &packed_form) = 0; 00081 virtual clonable *clone() const = 0; 00082 virtual int packed_size() const = 0; 00083 }; 00084 00085 #endif 00086
1.5.1