HANDLE handleDF;
// proceed to find and retrieve handle for dwarf fortress process and detect
// version and load correct memory map definitions etc) /* for the rest of mock code, assume:
suffix of Sptr to be shared/smart ptr.
??MemMap to be a memory map instance
??Object is like a io formatter for a memory address and a particular map
In short, ??MemMap just denotes where the offsets to certain known
attributes are, ??Object is the one that tries to interpret a memory
location as the speicified ??.
*/
// Optional phase to verify that all things we are going to use are
// defined. If not, should probably terminate the application with
// error messages where appropriate.
// start of testing.
MemMapBaseConstSptr mmap;
ComplexMemoryObjectSptr temp;
// **** verify main process map ****
// verify required memmap exists
mmap = MemMapRegistry::GetMap("main");
ASSERT(mmap)
// verify required memmap attributes exists
ASSERT( mmap->GetMapping("main_creature_vector_loc") );
// **** verify creature struct map ****
// verify required memmap exists
mmap = MemMapRegistry::GetMap("creature");
ASSERT(mmap)
// verify required memmap attributes exists
ASSERT( mmap->GetMapping("first_name") );
ASSERT( mmap->GetMapping("nick_name") );
// end of testing
/*
Note that each tool applciation does not need to verify the whole memory
structure. It only have to verify those that it uses. For example,
foreman.exe uses labour settings and professions. It does not need to
verify things like inventory or health.
*/
// call to registry to return shared ptr to a memory map called "main"
MemMapSpr spDFMemMap = MemMapRegistry::GetMap("main") ;
if( spDFMemMap == NULL )
{
// report error. memory map not found.
// redundant if testing is done before
}
else
{
ComplexMemoryObjectSptr spMainDF =
ComplexMemoryObject::New( 0 // no offset address
, handleDF // process handle of dwarfort.exe
, spDFMemMap
);
ASSERT( spMainDF != NULL ); // assume no prob
VectorObjectSptr creature_vector = VectorObject::New(
spMainDF->GetSubObject("main_creature_vector_loc")
, MemMapRegistry::GetMap("pointer") ) ;
// need to specify a map with known size to make vector iterable.
ASSERT( creature_vector != NULL ); // assume no prob
// iterate through creature vector
for( VectorObject::Iterator it = creature_vector->Begin()
; it != creature_vector->End()
; ++ it )
{
ComplexMemoryObjectSptr creature =
ComplexMemoryObject::New( PtrObject(*it).Dereference()
, MemMapRegistry::GetMap("creature")
);
ASSERT( creature != NULL ); // assume no prob
// retrieve first and nick names
std::string first_name =
StringObject(creature->GetSubObject("first_name")).GetValue();
// declare var for nick name instead to allow easier write back
StringObject nick =
StringObject(creature->GetSubObject("nick_name"));
std::string nick_name = nick.GetValue();
// change nickname and rewrite it back. Note that if new string is
// longer than existing string capacity, it gets truncated. I don't
// think it is feasible to try to do cross-process string reallocation.
nick_name = "Newbie";
nick.SetValue(nick_name);
// note: should throw exception if in exception enabled and failed.
}
}