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
DFHackAPI.cpp
DFTileTypes.cpp
DFVector.cpp
md5/md5.cpp
md5/md5wrapper.cpp
tinyxml/tinystr.cpp

@ -25,6 +25,7 @@ distribution.
#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED
#include "Export.h"
#include <string>
#include <sstream>
#include <exception>
@ -33,7 +34,7 @@ namespace DFHack
{
namespace Error
{
class NoProcess : public exception
class DFHACK_EXPORT NoProcess : public std::exception
{
public:
virtual const char* what() const throw()
@ -42,7 +43,7 @@ namespace DFHack
}
};
class CantAttach : public exception
class DFHACK_EXPORT CantAttach : public std::exception
{
public:
virtual const char* what() const throw()
@ -51,7 +52,7 @@ namespace DFHack
}
};
class NoMapLoaded : public exception
class DFHACK_EXPORT NoMapLoaded : public std::exception
{
public:
virtual const char* what() const throw()
@ -60,7 +61,7 @@ namespace DFHack
}
};
class BadMapDimensions : public exception
class DFHACK_EXPORT BadMapDimensions : public std::exception
{
public:
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
class MissingMemoryDefinition : public exception
class DFHACK_EXPORT MissingMemoryDefinition : public std::exception
{
public:
MissingMemoryDefinition(const char* _type, const char* _key) : type(_type), key(_key) {}
@ -86,6 +87,8 @@ namespace DFHack
s << _key;
key = s.str();
}
virtual ~MissingMemoryDefinition() throw()
{};
// (perhaps it should be an enum, but this is intended for easy printing/logging)
// 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
#include "Tranquility.h"
#include "Export.h"
namespace DFHack
{
class DfVector
class DFHACK_EXPORT DfVector
{
private:
// starting offset
@ -40,40 +41,20 @@ namespace DFHack
uint8_t* data;
public:
DfVector()
{
data = 0;
};
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;
}
DfVector();
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size);
~DfVector();
// get offset of the specified index
inline void* operator[] (uint32_t index)
{
assert(index < size);
// FIXME: vector out of bounds exception
//assert(index < size);
return data + index*item_size;
};
// get offset of the specified index
inline void* at (uint32_t index)
{
assert(index < size);
//assert(index < size);
return data + index*item_size;
};
// get vector size

@ -5,10 +5,28 @@ Author: Alex Legg
Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack
*/
#include "DFCommonInternal.h"
//#include <DFCommonInternal.h>
#include <sstream>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <assert.h>
#include <string>
#include <vector>
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 ()
{
DFHack::Process *proc;
@ -32,9 +50,7 @@ int main ()
DF.Suspend();
/*
* Find out which material is bauxite
*/
// Find out which material is bauxite
if(!DF.ReadStoneMatgloss(stoneMat))
{
cout << "Materials not supported for this version of DF, exiting." << endl;
@ -63,23 +79,15 @@ int main ()
return EXIT_FAILURE;
}
/*
* Get some basics needed for full access
*/
// Get some basics needed for full access
proc = DF.getProcess();
meminfo = proc->getDescriptor();
/*
* Get the object name/ID mapping
*/
/*
vector <string> objecttypes;
DF.getClassIDMapping (objecttypes);
*/
// Get the object name/ID mapping
//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");
item_material_offset = meminfo->getOffset("item_materials");
if( !items || ! item_material_offset)
@ -145,5 +153,6 @@ int main ()
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}