-
Code's Tags
-
Your Codes
-
Reffers
-
Linked Codes
|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- struct BaseType
- {
- bool IsStored;
- enum BaseValueState {bvsStore, bvsSet, bvsGet, bvsErase};
- BaseType():IsStored(false)
- {
- }
- virtual ~BaseType()
- {
- if(IsStored)
- {
- int tempInt = int();
- double tempDbl = double();
- UnicodeString tempStr;
- FieldStorage("", tempInt, bvsErase);
- FieldStorage("", tempStr, bvsErase);
- FieldStorage("", tempDbl, bvsErase);
- }
- }
- virtual void StoreValue() = 0;
- virtual void Free() = 0;
-
- template <class T>
- void FieldStorage(const UnicodeString &Tag, T& Value,
BaseValueState State = bvsStore)
- {
- typedef std::map<void*, std::map<UnicodeString, T*> > FieldMap;
- static FieldMap Values;
- static T Empty = T();
- if (!IsStored)
- IsStored = true;
- switch(State)
- {
- case bvsStore:
- Values[this][Tag] = &Value;
- break;
- case bvsSet:
- {
- T* Ptr = Values[this][Tag];
- if (Ptr)
- *Ptr = Value;
- }
- break;
- case bvsGet:
- {
- T* Ptr = Values[this][Tag];
- Value = (Ptr) ? *Ptr : Empty;
- }
- break;
- case bvsErase:
- Values.erase(this);
- break;
- }
- }
-
- template <typename T>
- void GetField(const UnicodeString& Tag, T& Value)
- {
- FieldStorage(Tag, Value, bvsGet);
- }
-
- template <typename T>
- void SetField(const UnicodeString& Tag, T& Value)
- {
- FieldStorage(Tag, Value, bvsSet);
- }
-
- template <typename T>
- T GetField(const UnicodeString& Tag)
- {
- T Value;
- FieldStorage(Tag, Value, bvsGet);
- return Value;
- }
- };
|