Big namespace cleaning

develop
Petr Mrázek 2010-06-05 00:02:02 +02:00
parent 115e969530
commit 6b7f3e1816
16 changed files with 208 additions and 214 deletions

@ -29,6 +29,55 @@ distribution.
using namespace DFHack;
/*
* Common data types
*/
namespace DFHack
{
struct t_type
{
t_type(uint32_t assign, uint32_t type, std::string classname)
:classname(classname),assign(assign),type(type){};
std::string classname;
uint32_t assign;
uint32_t type;
};
struct t_class
{
t_class(const t_class &old)
{
classname = old.classname;
vtable = old.vtable;
assign = old.assign;
type_offset = old.type_offset;
for(uint32_t i = 0; i < old.subs.size();i++)
{
t_type * t = new t_type (*old.subs[i]);
subs.push_back(t);
}
}
t_class ()
{
vtable = 0;
assign = 0;
type_offset = 0;
}
~t_class()
{
for(uint32_t i = 0; i < subs.size();i++)
{
delete subs[i];
}
subs.clear();
}
std::string classname;
uint32_t vtable;
uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass
std::vector<t_type *> subs;
};
}
/*
* Private data
*/

@ -1,6 +1,7 @@
#ifndef DFHACK_API_H
#define DFHACK_API_H
// DFHack core classes and types
#include "dfhack/DFIntegers.h"
#include "dfhack/DFGlobal.h"
#include "dfhack/DFError.h"
@ -10,7 +11,7 @@
#include "dfhack/DFProcess.h"
#include "dfhack/DFTypes.h"
// DFHack modules
#include "dfhack/modules/Buildings.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/modules/Position.h"
@ -22,5 +23,10 @@
#include "dfhack/modules/Vegetation.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/DFMiscUtils.h"
#ifdef DFHACK_WANT_MISCUTILS
#include "dfhack/DFMiscUtils.h"
#endif
#ifdef DFHACK_WANT_TILETYPES
#include "dfhack/DFTileTypes.h"
#endif
#endif

@ -35,7 +35,7 @@ distribution.
#include "dfhack/DFExport.h"
#include "dfhack/DFIntegers.h"
using namespace std;
using namespace DFHack;
typedef void DFHackObject;

@ -27,64 +27,13 @@ distribution.
#include "DFPragma.h"
#include "DFExport.h"
#include <map>
#include <vector>
#include <string>
namespace DFHack
{
/*
* Stubs
*/
class Process;
/*
* Common data types
*/
struct t_type
{
t_type(uint32_t assign, uint32_t type, std::string classname)
:classname(classname),assign(assign),type(type){};
std::string classname;
uint32_t assign;
uint32_t type;
};
struct t_class
{
t_class(const t_class &old)
{
classname = old.classname;
vtable = old.vtable;
assign = old.assign;
type_offset = old.type_offset;
for(uint32_t i = 0; i < old.subs.size();i++)
{
t_type * t = new t_type (*old.subs[i]);
subs.push_back(t);
}
}
t_class ()
{
vtable = 0;
assign = 0;
type_offset = 0;
}
~t_class()
{
for(uint32_t i = 0; i < subs.size();i++)
{
delete subs[i];
}
subs.clear();
}
std::string classname;
uint32_t vtable;
uint32_t assign;// index to typeclass array if multiclass. return value if not.
uint32_t type_offset; // offset of type data for multiclass
vector<t_type *> subs;
};
struct t_class;
class DFHACK_EXPORT memory_info
{
@ -184,7 +133,7 @@ namespace DFHack
/**
* Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR!
*/
const vector<std::string> * getClassIDMapping();
const std::vector<std::string> * getClassIDMapping();
};
}
#endif // MEMINFO_H_INCLUDED

@ -136,13 +136,13 @@ namespace DFHack
virtual void write(uint32_t address, uint32_t length, uint8_t* buffer) = 0;
/// read an STL string
virtual const string readSTLString (uint32_t offset) = 0;
virtual const std::string readSTLString (uint32_t offset) = 0;
/// read an STL string
virtual size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) = 0;
/// write an STL string
virtual void writeSTLString(const uint32_t address, const std::string writeString) = 0;
/// get class name of an object with rtti/type info
virtual string readClassName(uint32_t vptr) = 0;
virtual std::string readClassName(uint32_t vptr) = 0;
/// read a null-terminated C string
virtual const std::string readCString (uint32_t offset) = 0;
@ -155,9 +155,9 @@ namespace DFHack
virtual bool isIdentified() = 0;
/// find the thread IDs of the process
virtual bool getThreadIDs(vector<uint32_t> & threads ) = 0;
virtual bool getThreadIDs(std::vector<uint32_t> & threads ) = 0;
/// get virtual memory ranges of the process (what is mapped where)
virtual void getMemRanges( vector<t_memrange> & ranges ) = 0;
virtual void getMemRanges(std::vector<t_memrange> & ranges ) = 0;
/// get the flattened Memory.xml entry of this process
virtual memory_info *getDescriptor() = 0;
@ -182,7 +182,7 @@ namespace DFHack
private:
Private * const d;
public:
NormalProcess(uint32_t pid, vector <memory_info *> & known_versions);
NormalProcess(uint32_t pid, std::vector <memory_info *> & known_versions);
~NormalProcess();
bool attach();
bool detach();
@ -214,11 +214,11 @@ namespace DFHack
void read( uint32_t address, uint32_t length, uint8_t* buffer);
void write(uint32_t address, uint32_t length, uint8_t* buffer);
const string readSTLString (uint32_t offset);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
std::string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset);
@ -226,8 +226,8 @@ namespace DFHack
bool isAttached();
bool isIdentified();
bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges );
bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor();
int getPID();
// get module index by name and version. bool 1 = error
@ -246,7 +246,7 @@ namespace DFHack
Private * const d;
public:
SHMProcess(uint32_t PID, vector <memory_info *> & known_versions);
SHMProcess(uint32_t PID, std::vector <memory_info *> & known_versions);
~SHMProcess();
// Set up stuff so we can read memory
bool attach();
@ -279,11 +279,11 @@ namespace DFHack
void read( uint32_t address, uint32_t length, uint8_t* buffer);
void write(uint32_t address, uint32_t length, uint8_t* buffer);
const string readSTLString (uint32_t offset);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
std::string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset);
@ -291,8 +291,8 @@ namespace DFHack
bool isAttached();
bool isIdentified();
bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges );
bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor();
int getPID();
// get module index by name and version. bool 1 = error
@ -311,7 +311,7 @@ namespace DFHack
Private * const d;
public:
WineProcess(uint32_t pid, vector <memory_info *> & known_versions);
WineProcess(uint32_t pid, std::vector <memory_info *> & known_versions);
~WineProcess();
bool attach();
bool detach();
@ -343,11 +343,11 @@ namespace DFHack
void read( uint32_t address, uint32_t length, uint8_t* buffer);
void write(uint32_t address, uint32_t length, uint8_t* buffer);
const string readSTLString (uint32_t offset);
const std::string readSTLString (uint32_t offset);
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
void writeSTLString(const uint32_t address, const std::string writeString){};
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
std::string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset);
@ -355,8 +355,8 @@ namespace DFHack
bool isAttached();
bool isIdentified();
bool getThreadIDs(vector<uint32_t> & threads );
void getMemRanges( vector<t_memrange> & ranges );
bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor();
int getPID();
// get module index by name and version. bool 1 = error

@ -37,7 +37,7 @@ namespace DFHack
bool Finish();
// read a vector of names
bool ReadCustomWorkshopTypes(map <uint32_t, string> & btypes);
bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
// returns -1 on error, >= 0 for real value
int32_t GetCustomWorkshopType(t_building & building);

@ -84,81 +84,70 @@ namespace DFHack
struct t_matglossOther
{
char rawname[128];
char rawname[128];
};
struct t_creatureextract
{
char rawname[128];
char rawname[128];
};
// this doesn't transfer well across the shm gap...
struct t_creaturetype
{
char rawname[128];
std::vector <t_creaturecaste> castes;
std::vector <t_creatureextract> extract;
uint8_t tile_character;
struct
{
uint16_t fore;
uint16_t back;
uint16_t bright;
} tilecolor;
std::vector <t_creaturecaste> castes;
std::vector <t_creatureextract> extract;
uint8_t tile_character;
struct
{
uint16_t fore;
uint16_t back;
uint16_t bright;
} tilecolor;
};
// this structure describes what are things made of in the DF world
struct t_material
{
int16_t itemType;
int16_t subType;
int16_t subIndex;
int32_t index;
uint32_t flags;
int16_t itemType;
int16_t subType;
int16_t subIndex;
int32_t index;
uint32_t flags;
};
class DFHACK_EXPORT Materials
{
public:
Materials(DFHack::DFContextShared * _d);
~Materials();
std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;
std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);
bool ReadOthers (void);
void ReadAllMaterials(void);
std::string getDescription(t_material & mat);
/*
bool ReadInorganicMaterials (std::vector<t_matgloss> & output);
bool ReadOrganicMaterials (std::vector<t_matgloss> & output);
bool ReadWoodMaterials (std::vector<t_matgloss> & output);
bool ReadPlantMaterials (std::vector<t_matgloss> & output);
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
*/
private:
class Private;
Private* d;
};
public:
Materials(DFHack::DFContextShared * _d);
~Materials();
std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic;
std::vector<t_matgloss> tree;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
std::vector<t_descriptor_color> color;
std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);
bool ReadOthers (void);
void ReadAllMaterials(void);
std::string getDescription(t_material & mat);
private:
class Private;
Private* d;
};
}
#endif

@ -23,7 +23,7 @@ distribution.
*/
#include "dfhack-c/modules/Buildings_C.h"
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
@ -70,33 +70,27 @@ int Buildings_GetCustomWorkshopType(DFHackObject* b_Ptr, t_building* building)
int Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr, void* (*t_customWorkshop_buffer_create)(uint32_t))
{
if(b_Ptr != NULL)
{
int i;
t_customWorkshop* cw_Ptr;
map<uint32_t, string> bTypes;
map<uint32_t, string>::iterator bIter;
bool result = ((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes);
if(!result)
return 0;
cw_Ptr = (t_customWorkshop*)((*t_customWorkshop_buffer_create)(bTypes.size()));
for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++)
{
cw_Ptr[i].index = (*bIter).first;
size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256);
cw_Ptr[i].name[length] = '\0';
}
return 1;
}
return -1;
if(b_Ptr != NULL)
{
int i;
t_customWorkshop* cw_Ptr;
std::map<uint32_t, string> bTypes;
map<uint32_t, string>::iterator bIter;
if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return 0;
cw_Ptr = (t_customWorkshop*)((*t_customWorkshop_buffer_create)(bTypes.size()));
for(i = 0, bIter = bTypes.begin(); bIter != bTypes.end(); bIter++, i++)
{
cw_Ptr[i].index = (*bIter).first;
size_t length = (*bIter).second.copy(cw_Ptr[i].name, 256);
cw_Ptr[i].name[length] = '\0';
}
return 1;
}
return -1;
}
#ifdef __cplusplus

@ -5,8 +5,10 @@
#include <sstream>
#include <climits>
#include <vector>
using namespace std;
#include <stdio.h>
//using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
int main (int argc,const char* argv[])
@ -27,14 +29,14 @@ int main (int argc,const char* argv[])
}
else if(argc == 3)
{
string s = argv[2]; //blah. I don't care
istringstream ins; // Declare an input string stream.
std::string s = argv[2]; //blah. I don't care
std::istringstream ins; // Declare an input string stream.
ins.str(s); // Specify string to read.
ins >> lines; // Reads the integers from the string.
mode = 1;
}
map <uint32_t, string> custom_workshop_types;
std::map <uint32_t, std::string> custom_workshop_types;
DFHack::ContextManager DFMgr ("Memory.xml");
DFHack::Context *DF;
@ -43,9 +45,9 @@ int main (int argc,const char* argv[])
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
catch (std::exception& e)
{
cerr << e.what() << endl;
std::cerr << e.what() << std::endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -62,17 +64,17 @@ int main (int argc,const char* argv[])
Bld->ReadCustomWorkshopTypes(custom_workshop_types);
if(mode)
{
cout << numBuildings << endl;
vector < uint32_t > addresses;
std::cout << numBuildings << std::endl;
std::vector < uint32_t > addresses;
for(uint32_t i = 0; i < numBuildings; i++)
{
DFHack::t_building temp;
Bld->Read(i, temp);
if(temp.type != 0xFFFFFFFF) // check if type isn't invalid
{
string typestr;
std::string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
cout << typestr << endl;
std::cout << typestr << std::endl;
if(typestr == argv[1])
{
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
@ -83,7 +85,7 @@ int main (int argc,const char* argv[])
else
{
// couldn't translate type, print out the vtable
cout << "unknown vtable: " << temp.vtable << endl;
std::cout << "unknown vtable: " << temp.vtable << std::endl;
}
}
interleave_hex(DF,addresses,lines / 4);
@ -105,7 +107,7 @@ int main (int argc,const char* argv[])
&& (uint32_t)z == temp.z
)
{
string typestr;
std::string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
printf("Address 0x%x, type %d (%s), %d/%d/%d\n",temp.origin, temp.type, typestr.c_str(), temp.x1,temp.y1,temp.z);
printf("Material %d %d\n", temp.material.type, temp.material.index);
@ -120,12 +122,12 @@ int main (int argc,const char* argv[])
}
else
{
cout << numBuildings << endl;
std::cout << numBuildings << std::endl;
for(uint32_t i = 0; i < numBuildings; i++)
{
DFHack::t_building temp;
Bld->Read(i, temp);
string typestr;
std::string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
printf("Address 0x%x, type %d (%s), %d/%d/%d\n",temp.origin, temp.type, typestr.c_str(), temp.x1,temp.y1,temp.z);
}
@ -135,12 +137,12 @@ int main (int argc,const char* argv[])
}
else
{
cerr << "buildings not supported for this DF version" << endl;
std::cerr << "buildings not supported for this DF version" << std::endl;
}
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
std::cout << "Done. Press any key to continue" << std::endl;
cin.ignore();
#endif
return 0;

@ -7,8 +7,9 @@
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#include <stdio.h>
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
using namespace DFHack;
@ -21,9 +22,9 @@ int main (int numargs, const char ** args)
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
catch (std::exception& e)
{
cerr << e.what() << endl;
std::cerr << e.what() << std::endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -51,7 +52,7 @@ int main (int numargs, const char ** args)
printf("Construction %d/%d/%d @ 0x%x\n", con.x, con.y, con.z,con.origin);
// inorganic stuff - we can recognize that
printf("Material: form %d, type %d, index %d\n",con.form, con.mat_type, con.mat_idx);
string matstr = "unknown";
std::string matstr = "unknown";
if(con.mat_type == 0)
{
if(con.mat_idx != 0xffffffff)

@ -4,8 +4,10 @@
#include <climits>
#include <string.h>
#include <vector>
#include <stdio.h>
using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
enum likeType

@ -11,6 +11,7 @@
using namespace std;
#include <DFHack.h>
#include <dfhack/DFVector.h>
DFHack::Materials * Materials;

@ -8,7 +8,7 @@
#include <ctime>
#include <cstdio>
using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
using namespace DFHack;

@ -9,6 +9,7 @@
#include <cstdio>
using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
int main (int numargs, const char ** args)
@ -45,7 +46,6 @@ int main (int numargs, const char ** args)
int32_t x,y,z;
pos->getCursorCoords(x,y,z);
uint32_t numVegs = 0;
v->Start(numVegs);
if(x == -30000)

@ -15,8 +15,9 @@ using namespace std;
#include <locale.h>
#include <math.h>
#define DFHACK_WANT_MISCUTILS
#define DFHACK_WANT_TILETYPES
#include <DFHack.h>
#include <dfhack/DFTileTypes.h>
using namespace DFHack;

@ -7,10 +7,10 @@
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#define DFHACK_WANT_MISCUTILS
#define DFHACK_WANT_TILETYPES
#include <DFHack.h>
#include <dfhack/DFTileTypes.h>
using namespace DFHack;
int main (int numargs, const char ** args)
@ -22,9 +22,9 @@ int main (int numargs, const char ** args)
{
DF->Attach();
}
catch (exception& e)
catch (std::exception& e)
{
cerr << e.what() << endl;
std::cerr << e.what() << std::endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
@ -68,59 +68,59 @@ int main (int numargs, const char ** args)
int16_t tiletype = block.tiletypes[tileX][tileY];
naked_designation &des = block.designation[tileX][tileY].bits;
uint32_t &desw = block.designation[tileX][tileY].whole;
print_bits<uint32_t>(block.designation[tileX][tileY].whole,cout);
cout << endl;
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,cout);
cout << endl;
print_bits<uint32_t>(block.designation[tileX][tileY].whole,std::cout);
std::cout << endl;
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,std::cout);
std::cout << endl;
// tiletype
cout <<"tiletype: " << tiletype;
std::cout <<"tiletype: " << tiletype;
if(tileTypeTable[tiletype].name)
cout << " = " << tileTypeTable[tiletype].name;
cout << endl;
std::cout << " = " << tileTypeTable[tiletype].name;
std::cout << std::endl;
cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << endl;
cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << endl;
std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl;
std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl;
// biome, geolayer
cout << "biome: " << des.biome << endl;
cout << "geolayer: " << des.geolayer_index << endl;
std::cout << "biome: " << des.biome << std::endl;
std::cout << "geolayer: " << des.geolayer_index << std::endl;
// liquids
if(des.flow_size)
{
if(des.liquid_type == DFHack::liquid_magma)
cout <<"magma: ";
else cout <<"water: ";
cout << des.flow_size << endl;
std::cout <<"magma: ";
else std::cout <<"water: ";
std::cout << des.flow_size << std::endl;
}
if(des.flow_forbid)
cout << "flow forbid" << endl;
std::cout << "flow forbid" << std::endl;
if(des.pile)
cout << "stockpile?" << endl;
std::cout << "stockpile?" << std::endl;
if(des.rained)
cout << "rained?" << endl;
std::cout << "rained?" << std::endl;
if(des.smooth)
cout << "smooth?" << endl;
std::cout << "smooth?" << std::endl;
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
printf("designation offset: 0x%x\n", designato);
if(des.light)
cout << "Light ";
std::cout << "Light ";
else
cout << " ";
std::cout << " ";
if(des.skyview)
cout << "SkyView ";
std::cout << "SkyView ";
else
cout << " ";
std::cout << " ";
if(des.subterranean)
cout << "Underground ";
std::cout << "Underground ";
else
cout << " ";
cout << endl;
std::cout << " ";
std::cout << std::endl;
}
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
std::cout << "Done. Press any key to continue" << std::endl;
cin.ignore();
#endif
return 0;