From b33d56354f4740f6f8a332b66d4011cd55934d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 23 Aug 2010 19:28:53 +0200 Subject: [PATCH] OffsetGroup class (unfinished) --- library/VersionInfo.cpp | 312 ++++++++++++++------------- library/include/dfhack/VersionInfo.h | 51 ++--- 2 files changed, 193 insertions(+), 170 deletions(-) diff --git a/library/VersionInfo.cpp b/library/VersionInfo.cpp index 152133ac7..57cd54c7b 100644 --- a/library/VersionInfo.cpp +++ b/library/VersionInfo.cpp @@ -82,50 +82,183 @@ namespace DFHack }; } +/* + * Private data + */ +namespace DFHack +{ + class OffsetGroupPrivate + { + public: + map addresses; + map offsets; + map hexvals; + map strings; + map groups; + }; +} + + +void OffsetGroup::setOffset (const string & key, const string & value) +{ + int32_t offset = strtol(value.c_str(), NULL, 16); + d->offsets[key] = offset; +} + + +void OffsetGroup::setAddress (const string & key, const string & value) +{ + uint32_t address = strtol(value.c_str(), NULL, 16); + d->addresses[key] = address; +} + + +void OffsetGroup::setHexValue (const string & key, const string & value) +{ + uint32_t hexval = strtol(value.c_str(), NULL, 16); + d->hexvals[key] = hexval; +} + + +void OffsetGroup::setString (const string & key, const string & value) +{ + d->strings[key] = value; +} + + +// Get named address +uint32_t OffsetGroup::getAddress (const char *key) +{ + map ::iterator iter = d->addresses.find(key); + + if(iter != d->addresses.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("address", key); +} + + +// Get named offset +int32_t OffsetGroup::getOffset (const char *key) +{ + map ::iterator iter = d->offsets.find(key); + if(iter != d->offsets.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("offset", key); +} + + +// Get named numerical value +uint32_t OffsetGroup::getHexValue (const char *key) +{ + map ::iterator iter = d->hexvals.find(key); + if(iter != d->hexvals.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("hexvalue", key); +} + + +// Get named address +uint32_t OffsetGroup::getAddress (const string &key) +{ + map ::iterator iter = d->addresses.find(key); + + if(iter != d->addresses.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("address", key.c_str()); +} + + +// Get named offset +int32_t OffsetGroup::getOffset (const string &key) +{ + map ::iterator iter = d->offsets.find(key); + if(iter != d->offsets.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("offset", key.c_str()); +} + + +// Get named numerical value +uint32_t OffsetGroup::getHexValue (const string &key) +{ + map ::iterator iter = d->hexvals.find(key); + if(iter != d->hexvals.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("hexvalue", key.c_str()); +} + + +// Get named string +std::string OffsetGroup::getString (const string &key) +{ + map ::iterator iter = d->strings.find(key); + if(iter != d->strings.end()) + { + return (*iter).second; + } + throw Error::MissingMemoryDefinition("string", key.c_str()); +} + + /* * Private data */ -class VersionInfo::Private +namespace DFHack { - public: - map addresses; - map offsets; - map hexvals; - map strings; + class VersionInfoPrivate + { + public: + map addresses; + map offsets; + map hexvals; + map strings; - vector professions; - vector jobs; - vector skills; - vector levels; - vector< vector > traits; - vector moods; - map labors; + vector professions; + vector jobs; + vector skills; + vector levels; + vector< vector > traits; + vector moods; + map labors; - // storage for class and multiclass - vector classes; + // storage for class and multiclass + vector classes; - // cache for faster name lookup, indexed by classID - vector classnames; - // map between vptr and class id, needs further type id lookup for multi-classes, not inherited - map classIDs; + // cache for faster name lookup, indexed by classID + vector classnames; + // map between vptr and class id, needs further type id lookup for multi-classes, not inherited + map classIDs; - // index for the next added class - uint32_t classindex; + // index for the next added class + uint32_t classindex; - int32_t base; - Process * p; // the process this belongs to + int32_t base; + Process * p; // the process this belongs to - string version; - OSType OS; - std::string md5; - uint32_t PE_timestamp; -}; + string version; + VersionInfo::OSType OS; + std::string md5; + uint32_t PE_timestamp; + }; +} // normal constructor VersionInfo::VersionInfo() -:d(new Private) +:d(new VersionInfoPrivate) { d->base = 0; d->p = 0; @@ -139,7 +272,7 @@ VersionInfo::VersionInfo() // copy constructor VersionInfo::VersionInfo(const VersionInfo &old) -:d(new Private) +:d(new VersionInfoPrivate) { copy(&old); } @@ -289,33 +422,6 @@ void VersionInfo::setBase (const uint32_t b) } -void VersionInfo::setOffset (const string & key, const string & value) -{ - int32_t offset = strtol(value.c_str(), NULL, 16); - d->offsets[key] = offset; -} - - -void VersionInfo::setAddress (const string & key, const string & value) -{ - uint32_t address = strtol(value.c_str(), NULL, 16); - d->addresses[key] = address; -} - - -void VersionInfo::setHexValue (const string & key, const string & value) -{ - uint32_t hexval = strtol(value.c_str(), NULL, 16); - d->hexvals[key] = hexval; -} - - -void VersionInfo::setString (const string & key, const string & value) -{ - d->strings[key] = value; -} - - void VersionInfo::setLabor(const string & key, const string & value) { uint32_t keyInt = strtol(key.c_str(), NULL, 10); @@ -600,92 +706,6 @@ void VersionInfo::RebaseVTable(int32_t offset) } -// Get named address -uint32_t VersionInfo::getAddress (const char *key) -{ - map ::iterator iter = d->addresses.find(key); - - if(iter != d->addresses.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("address", key); -} - - -// Get named offset -int32_t VersionInfo::getOffset (const char *key) -{ - map ::iterator iter = d->offsets.find(key); - if(iter != d->offsets.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("offset", key); -} - - -// Get named numerical value -uint32_t VersionInfo::getHexValue (const char *key) -{ - map ::iterator iter = d->hexvals.find(key); - if(iter != d->hexvals.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("hexvalue", key); -} - - -// Get named address -uint32_t VersionInfo::getAddress (const string &key) -{ - map ::iterator iter = d->addresses.find(key); - - if(iter != d->addresses.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("address", key.c_str()); -} - - -// Get named offset -int32_t VersionInfo::getOffset (const string &key) -{ - map ::iterator iter = d->offsets.find(key); - if(iter != d->offsets.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("offset", key.c_str()); -} - - -// Get named numerical value -uint32_t VersionInfo::getHexValue (const string &key) -{ - map ::iterator iter = d->hexvals.find(key); - if(iter != d->hexvals.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("hexvalue", key.c_str()); -} - - -// Get named string -std::string VersionInfo::getString (const string &key) -{ - map ::iterator iter = d->strings.find(key); - if(iter != d->strings.end()) - { - return (*iter).second; - } - throw Error::MissingMemoryDefinition("string", key.c_str()); -} - - // Get Profession string VersionInfo::getProfession (const uint32_t key) const { @@ -811,11 +831,11 @@ std::string VersionInfo::PrintOffsets() switch (getOS()) { case OS_LINUX: - ss << "" << endl; + ss << "" << endl; break; case OS_WINDOWS: - ss << "" << endl; - ss << "" << endl; + ss << "" << endl; + ss << "" << endl; break; default: ss << " UNKNOWN" << endl; diff --git a/library/include/dfhack/VersionInfo.h b/library/include/dfhack/VersionInfo.h index 5f00cdc55..7bc4f0c2e 100644 --- a/library/include/dfhack/VersionInfo.h +++ b/library/include/dfhack/VersionInfo.h @@ -41,13 +41,37 @@ namespace DFHack class OffsetGroupPrivate; class DFHACK_EXPORT OffsetGroup { - private: + protected: OffsetGroupPrivate * d; public: - + int32_t getOffset (const std::string&); + uint32_t getAddress (const std::string&); + uint32_t getHexValue (const std::string&); + std::string getString (const std::string&); + + int32_t getOffset (const char *); + uint32_t getAddress (const char *); + uint32_t getHexValue (const char *); + std::string getString (const char *); + + void setOffset (const std::string &, const int32_t); + void setAddress (const std::string &, const uint32_t); + void setHexValue (const std::string &, const uint32_t); + + void setOffset (const std::string &, const char *); + void setAddress (const std::string &, const char *); + void setHexValue (const std::string &, const char *); + void setString (const std::string &, const char *); + + void setOffset (const std::string &, const std::string &); + void setAddress (const std::string &, const std::string &); + void setHexValue (const std::string &, const std::string &); + void setString (const std::string &, const std::string &); + + OffsetGroup & getGroup (const std::string name); }; - class DFHACK_EXPORT VersionInfo + class DFHACK_EXPORT VersionInfo : public OffsetGroup { private: VersionInfoPrivate * d; @@ -76,13 +100,6 @@ namespace DFHack void setPE (uint32_t PE_); uint getPE(); - int32_t getOffset (const std::string&); - uint32_t getAddress (const std::string&); - uint32_t getHexValue (const std::string&); - int32_t getOffset (const char *); - uint32_t getAddress (const char *); - uint32_t getHexValue (const char *); - std::string getMood(const uint32_t moodID); std::string getString (const std::string&); std::string getProfession(const uint32_t) const; @@ -105,20 +122,6 @@ namespace DFHack void setOS(const OSType); OSType getOS() const; - void setOffset (const std::string &, const int32_t); - void setAddress (const std::string &, const uint32_t); - void setHexValue (const std::string &, const uint32_t); - - void setOffset (const std::string &, const char *); - void setAddress (const std::string &, const char *); - void setHexValue (const std::string &, const char *); - void setString (const std::string &, const char *); - - void setOffset (const std::string &, const std::string &); - void setAddress (const std::string &, const std::string &); - void setHexValue (const std::string &, const std::string &); - void setString (const std::string &, const std::string &); - void setProfession(const std::string & id, const std::string & name); void setJob(const std::string &, const std::string &); void setSkill(const std::string &, const std::string &);