From f4f566e7c4b34314a020c659a32d70989ea9f1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 28 Feb 2010 05:35:54 +0100 Subject: [PATCH] Fixed exceptions on GCC Fixed dfbauxte tool - no longer includes internal headers Moved part of DFVector into a .cpp file --- library/CMakeLists.txt | 1 + library/DFError.h | 13 ++++++++----- library/DFVector.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ library/DFVector.h | 35 ++++++++------------------------- tools/dfbauxite.cpp | 43 +++++++++++++++++++++++++---------------- 5 files changed, 87 insertions(+), 49 deletions(-) create mode 100644 library/DFVector.cpp diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 45258c4f5..321ef5b3b 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -30,6 +30,7 @@ DFMemInfo.cpp DFMemInfoManager.cpp DFHackAPI.cpp DFTileTypes.cpp +DFVector.cpp md5/md5.cpp md5/md5wrapper.cpp tinyxml/tinystr.cpp diff --git a/library/DFError.h b/library/DFError.h index 36bf7ff5f..204601fde 100644 --- a/library/DFError.h +++ b/library/DFError.h @@ -25,6 +25,7 @@ distribution. #ifndef ERROR_H_INCLUDED #define ERROR_H_INCLUDED +#include "Export.h" #include #include #include @@ -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: diff --git a/library/DFVector.cpp b/library/DFVector.cpp new file mode 100644 index 000000000..d720c7819 --- /dev/null +++ b/library/DFVector.cpp @@ -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; +}; diff --git a/library/DFVector.h b/library/DFVector.h index 7ac24871b..e1d95b175 100644 --- a/library/DFVector.h +++ b/library/DFVector.h @@ -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 diff --git a/tools/dfbauxite.cpp b/tools/dfbauxite.cpp index d9ff5b3a6..9d57c4b91 100644 --- a/tools/dfbauxite.cpp +++ b/tools/dfbauxite.cpp @@ -5,10 +5,28 @@ Author: Alex Legg Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack */ -#include "DFCommonInternal.h" +//#include #include +#include +#include +#include +#include +#include +#include using namespace std; + +#include +#include +#include +#include +#include +#include +#include +#include +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 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; }