00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __SCOPED_SERIALIZE_H
00034 #define __SCOPED_SERIALIZE_H
00035
00036 #include "Serializable.h"
00037 #include "Printable.h"
00038
00068 template<typename STRING, typename ORIGIN>
00069 class ScopedSerialize {
00070 private:
00071 STRING& str;
00072 const ORIGIN* constObject;
00073 ORIGIN* object;
00074 public:
00076 ScopedSerialize(STRING& s, const ORIGIN& obj) : str(s), constObject(&obj), object(NULL)
00077 {
00078 ADD_SELECTORS("ScopedSerialize");
00079 static const bool printSS = (params::containsKey("MACE_SIMULATE_NODES") ||
00080 params::containsKey("LOG_SCOPED_SERIALIZE"));
00081 str = mace::serialize(constObject);
00082 if (printSS) {
00083 maceout << HashString::hash(str) << " " << *constObject << Log::endl;
00084
00085
00086 }
00087 }
00089 ScopedSerialize(STRING& s, ORIGIN& obj) : str(s), constObject(&obj), object(&obj)
00090 {
00091 ADD_SELECTORS("ScopedSerialize");
00092 static const bool printSS = (params::containsKey("MACE_SIMULATE_NODES") ||
00093 params::containsKey("LOG_SCOPED_SERIALIZE"));
00094 str = mace::serialize(constObject);
00095 if (printSS) {
00096 maceout << HashString::hash(str) << " " << *constObject << Log::endl;
00097
00098
00099 }
00100 }
00101 ~ScopedSerialize() {
00102 ADD_SELECTORS("ScopedSerialize");
00103 static const bool printSS = (params::containsKey("MACE_SIMULATE_NODES") ||
00104 params::containsKey("LOG_SCOPED_SERIALIZE"));
00105 if (object) {
00106 mace::deserialize(str, object);
00107 if (printSS) {
00108 maceout << HashString::hash(str) << " " << *object << Log::endl;
00109
00110
00111 }
00112 object = NULL;
00113 }
00114 constObject = NULL;
00115 }
00116 };
00117
00118 template<typename STRING, typename ORIGIN>
00119 class ScopedDeserialize {
00120 private:
00121 STRING* str;
00122 const STRING* constStr;
00123 ORIGIN& object;
00124 public:
00126 ScopedDeserialize(const STRING& s, ORIGIN& obj) : str(0), constStr(&s), object(obj)
00127 {
00128 ADD_SELECTORS("ScopedDeserialize");
00129
00130 mace::deserialize(*constStr, &object);
00131
00132
00133
00134 }
00136 ScopedDeserialize(STRING& s, ORIGIN& obj) : str(&s), constStr(&s), object(obj)
00137 {
00138 ADD_SELECTORS("ScopedDeserialize");
00139
00140 mace::deserialize(*constStr, &object);
00141
00142
00143
00144 }
00145 ~ScopedDeserialize() {
00146 ADD_SELECTORS("ScopedDeserialize");
00147
00148 if (str) {
00149 *str = mace::serialize(&object);
00150
00151
00152
00153 }
00154 }
00155 };
00156
00157
00162 #endif //__SCOPED_SERIALIZE_H