Fixed exceptions on GCC

Fixed dfbauxte tool - no longer includes internal headers
Moved part of DFVector into a .cpp file
develop
Petr Mrázek 2010-02-28 05:35:54 +01:00
parent 029f1a6cf8
commit f4f566e7c4
5 changed files with 87 additions and 49 deletions

@ -30,6 +30,7 @@ DFMemInfo.cpp
DFMemInfoManager.cpp DFMemInfoManager.cpp
DFHackAPI.cpp DFHackAPI.cpp
DFTileTypes.cpp DFTileTypes.cpp
DFVector.cpp
md5/md5.cpp md5/md5.cpp
md5/md5wrapper.cpp md5/md5wrapper.cpp
tinyxml/tinystr.cpp tinyxml/tinystr.cpp

@ -25,6 +25,7 @@ distribution.
#ifndef ERROR_H_INCLUDED #ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED #define ERROR_H_INCLUDED
#include "Export.h"
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <exception> #include <exception>
@ -33,7 +34,7 @@ namespace DFHack
{ {
namespace Error namespace Error
{ {
class NoProcess : public exception class DFHACK_EXPORT NoProcess : public std::exception
{ {
public: public:
virtual const char* what() const throw() virtual const char* what() const throw()
@ -42,7 +43,7 @@ namespace DFHack
} }
}; };
class CantAttach : public exception class DFHACK_EXPORT CantAttach : public std::exception
{ {
public: public:
virtual const char* what() const throw() virtual const char* what() const throw()
@ -51,7 +52,7 @@ namespace DFHack
} }
}; };
class NoMapLoaded : public exception class DFHACK_EXPORT NoMapLoaded : public std::exception
{ {
public: public:
virtual const char* what() const throw() virtual const char* what() const throw()
@ -60,7 +61,7 @@ namespace DFHack
} }
}; };
class BadMapDimensions : public exception class DFHACK_EXPORT BadMapDimensions : public std::exception
{ {
public: public:
BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {} BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {}
@ -74,7 +75,7 @@ namespace DFHack
}; };
// a call to DFHack::mem_info::get* failed // a call to DFHack::mem_info::get* failed
class MissingMemoryDefinition : public exception class DFHACK_EXPORT MissingMemoryDefinition : public std::exception
{ {
public: public:
MissingMemoryDefinition(const char* _type, const char* _key) : type(_type), key(_key) {} MissingMemoryDefinition(const char* _type, const char* _key) : type(_type), key(_key) {}
@ -86,6 +87,8 @@ namespace DFHack
s << _key; s << _key;
key = s.str(); key = s.str();
} }
virtual ~MissingMemoryDefinition() throw()
{};
// (perhaps it should be an enum, but this is intended for easy printing/logging) // (perhaps it should be an enum, but this is intended for easy printing/logging)
// type can be any of the following: // type can be any of the following:

@ -0,0 +1,44 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "Tranquility.h"
#include "DFCommonInternal.h"
using namespace DFHack;
DfVector::DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size): start(_start),size(_size),item_size(_item_size)
{
data = (uint8_t *) new char[size * item_size];
g_pProcess->read(start,size*item_size, (uint8_t *)data);
};
DfVector::DfVector()
{
data = 0;
};
DfVector::~DfVector()
{
if(data)
delete [] data;
};

@ -26,10 +26,11 @@ distribution.
#define DFVECTOR_H_INCLUDED #define DFVECTOR_H_INCLUDED
#include "Tranquility.h" #include "Tranquility.h"
#include "Export.h"
namespace DFHack namespace DFHack
{ {
class DfVector class DFHACK_EXPORT DfVector
{ {
private: private:
// starting offset // starting offset
@ -40,40 +41,20 @@ namespace DFHack
uint8_t* data; uint8_t* data;
public: public:
DfVector() DfVector();
{ DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size);
data = 0; ~DfVector();
};
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
start(_start),size(_size),item_size(_item_size)
{
data = (uint8_t *) new char[size * item_size];
g_pProcess->read(start,size*item_size, (uint8_t *)data);
};
/*
DfVector(const DfVector & vec)
{
start = vec.start;
size = vec.size;
item_size = vec.item_size;
data = (uint8_t *) new char[size * item_size];
memcpy(data,vec.data,item_size * size);
};*/
~DfVector()
{
if(data)
delete [] data;
}
// get offset of the specified index // get offset of the specified index
inline void* operator[] (uint32_t index) inline void* operator[] (uint32_t index)
{ {
assert(index < size); // FIXME: vector out of bounds exception
//assert(index < size);
return data + index*item_size; return data + index*item_size;
}; };
// get offset of the specified index // get offset of the specified index
inline void* at (uint32_t index) inline void* at (uint32_t index)
{ {
assert(index < size); //assert(index < size);
return data + index*item_size; return data + index*item_size;
}; };
// get vector size // get vector size

@ -5,10 +5,28 @@ Author: Alex Legg
Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack
*/ */
#include "DFCommonInternal.h" //#include <DFCommonInternal.h>
#include <sstream> #include <sstream>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <assert.h>
#include <string>
#include <vector>
using namespace std; using namespace std;
#include <integers.h>
#include <Export.h>
#include <DFError.h>
#include <DFVector.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
using namespace DFHack;
int main () int main ()
{ {
DFHack::Process *proc; DFHack::Process *proc;
@ -32,9 +50,7 @@ int main ()
DF.Suspend(); DF.Suspend();
/* // Find out which material is bauxite
* Find out which material is bauxite
*/
if(!DF.ReadStoneMatgloss(stoneMat)) if(!DF.ReadStoneMatgloss(stoneMat))
{ {
cout << "Materials not supported for this version of DF, exiting." << endl; cout << "Materials not supported for this version of DF, exiting." << endl;
@ -63,23 +79,15 @@ int main ()
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* // Get some basics needed for full access
* Get some basics needed for full access
*/
proc = DF.getProcess(); proc = DF.getProcess();
meminfo = proc->getDescriptor(); meminfo = proc->getDescriptor();
/* // Get the object name/ID mapping
* Get the object name/ID mapping
*/
/*
vector <string> objecttypes;
DF.getClassIDMapping (objecttypes);
*/
//FIXME: work on the 'supported features' system required //FIXME: work on the 'supported features' system required
/*
* Check availability of required addresses and offsets (doing custom stuff here) // Check availability of required addresses and offsets (doing custom stuff here)
*/
items = meminfo->getAddress("items"); items = meminfo->getAddress("items");
item_material_offset = meminfo->getOffset("item_materials"); item_material_offset = meminfo->getOffset("item_materials");
if( !items || ! item_material_offset) if( !items || ! item_material_offset)
@ -145,5 +153,6 @@ int main ()
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif #endif
return 0; return 0;
} }