00001 #ifndef CKPTOBJECTKEY_H_
00002 #define CKPTOBJECTKEY_H_
00003
00004 #include <saAis.h>
00005 #include <saCkpt.h>
00006 #include <string>
00007
00012 class CkptObjectKey {
00013 public:
00015 static const unsigned int MAX_SECTION_NAME_LENGTH=64;
00016 CkptObjectKey() {
00017 _sectionId.id = NULL;
00018 _sectionId.idLen = 0;
00019 _sectName = NULL;
00020 }
00021
00025 CkptObjectKey(unsigned long ulongKeyVal) {
00026 _sectionId.idLen = sizeof(unsigned long);
00027 _sectName = (char*)malloc(_sectionId.idLen);
00028 memcpy(_sectName, (char*)&ulongKeyVal, _sectionId.idLen);
00029 _sectName[_sectionId.idLen] = 0;
00030 _sectionId.id = (SaUint8T*)_sectName;
00031 }
00032
00036 CkptObjectKey(std::string stringKeyVal) {
00037 _sectionId.idLen = ((stringKeyVal.length() > MAX_SECTION_NAME_LENGTH) ? MAX_SECTION_NAME_LENGTH : stringKeyVal.length() );
00038 _sectName = (char*)malloc(_sectionId.idLen+1);
00039 strncpy(_sectName, stringKeyVal.c_str(), _sectionId.idLen);
00040 _sectName[_sectionId.idLen++] = 0;
00041 _sectionId.id = (SaUint8T*)_sectName;
00042 }
00043
00045 CkptObjectKey(const CkptObjectKey &rKey) {
00046 _sectionId.idLen = rKey._sectionId.idLen;
00047 _sectName = (char*)malloc(_sectionId.idLen);
00048 memcpy(_sectName, rKey._sectName, _sectionId.idLen);
00049 _sectionId.id = (SaUint8T*)_sectName;
00050 }
00051
00052 virtual ~CkptObjectKey() {
00053 if (_sectName != NULL) free(_sectName);
00054 }
00055
00056 CkptObjectKey& operator=(const CkptObjectKey &rhs) {
00057
00058 if (this == &rhs)
00059 return *this;
00060
00061 if (_sectName != NULL) free(_sectName);
00062 _sectionId.idLen = rhs._sectionId.idLen;
00063 _sectName = (char*)malloc(_sectionId.idLen);
00064 memcpy(_sectName, rhs._sectName, _sectionId.idLen);
00065 _sectionId.id = (SaUint8T*)_sectName;
00066
00067 return *this;
00068 }
00069
00070 bool operator==(const CkptObjectKey &rKey) {
00071 return ((_sectionId.idLen == rKey._sectionId.idLen) &&
00072 (memcmp(_sectionId.id, rKey._sectionId.id, _sectionId.idLen)==0));
00073 }
00074
00075 bool operator!=(const CkptObjectKey &rKey) {
00076 return !(*this == rKey);
00077 }
00078
00083 SaCkptSectionIdT* sectionIdValue() { return &_sectionId; }
00084
00085 private:
00086 SaCkptSectionIdT _sectionId;
00087 char* _sectName;
00088 };
00089
00090 #endif