global.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. #pragma once
  2. #ifndef __GLOBAL_H__
  3. #define __GLOBAL_H__
  4. #include <iostream>
  5. #include <algorithm> //std::find
  6. #include <string> //std::find
  7. #include <boost/logic/tribool.hpp>
  8. #include <boost/unordered_set.hpp>
  9. using boost::logic::tribool;
  10. #include <boost/cstdint.hpp>
  11. #include <assert.h>
  12. typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
  13. typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
  14. typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
  15. typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
  16. typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
  17. typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
  18. typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
  19. typedef boost::int8_t si8; //signed int 8 bits (1 byte)
  20. typedef si64 expType;
  21. typedef ui16 spelltype;
  22. typedef std::pair<ui32, ui32> TDmgRange;
  23. typedef ui8 TBonusType;
  24. typedef si32 TBonusSubtype;
  25. #include "int3.h"
  26. #include <map>
  27. #include <vector>
  28. #define CHECKTIME 1
  29. #if CHECKTIME
  30. #include "timeHandler.h"
  31. #define THC
  32. #endif
  33. #define NAME_VER ("VCMI 0.83b")
  34. extern std::string NAME; //full name
  35. extern std::string NAME_AFFIX; //client / server
  36. #define CONSOLE_LOGGING_LEVEL 5
  37. #define FILE_LOGGING_LEVEL 6
  38. /*
  39. * DATA_DIR contains the game data (Data/, MP3/, ...).
  40. * USER_DIR is where to save games (Games/) and the config.
  41. * BIN_DIR is where the vcmiclient/vcmiserver binaries reside
  42. * LIB_DIR is where the AI libraries reside (linux only)
  43. */
  44. #ifdef _WIN32
  45. #define DATA_DIR "."
  46. #define USER_DIR "."
  47. #define BIN_DIR "."
  48. #define LIB_DIR "AI"
  49. #define SERVER_NAME "VCMI_server.exe"
  50. #else
  51. #ifndef DATA_DIR
  52. #error DATA_DIR undefined.
  53. #endif
  54. #ifndef BIN_DIR
  55. #error BIN_DIR undefined.
  56. #endif
  57. #ifndef LIB_DIR
  58. #error LIB_DIR undefined.
  59. #endif
  60. #define SERVER_NAME "vcmiserver"
  61. #endif
  62. #ifdef _WIN32
  63. #define PATH_SEPARATOR "\\"
  64. #else
  65. #define PATH_SEPARATOR "/"
  66. #endif
  67. /*
  68. * global.h, part of VCMI engine
  69. *
  70. * Authors: listed in file AUTHORS in main folder
  71. *
  72. * License: GNU General Public License v2.0 or later
  73. * Full text of license available in license.txt file, in main folder
  74. *
  75. */
  76. enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
  77. enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
  78. captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
  79. enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
  80. enum ECombatInfo{ALIVE = 180, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
  81. class CGameInfo;
  82. extern const CGameInfo* CGI; //game info for general use
  83. class CClientState;
  84. extern CClientState * CCS;
  85. //a few typedefs for CCreatureSet
  86. typedef si32 TSlot;
  87. typedef si32 TQuantity;
  88. typedef ui32 TCreature; //creature id
  89. const int ARMY_SIZE = 7;
  90. const int HEROI_TYPE = 34,
  91. TOWNI_TYPE = 98,
  92. CREI_TYPE = 54,
  93. EVENTI_TYPE = 26;
  94. const int CREATURES_COUNT = 197;
  95. const int CRE_LEVELS = 10;
  96. const int F_NUMBER = 9; //factions (town types) quantity
  97. const int PLAYER_LIMIT = 8; //player limit per map
  98. const int ALL_PLAYERS = 255; //bitfield
  99. const int HEROES_PER_TYPE=8; //amount of heroes of each type
  100. const int SKILL_QUANTITY=28;
  101. const int SKILL_PER_HERO=8;
  102. const int ARTIFACTS_QUANTITY=171;
  103. const int HEROES_QUANTITY=156;
  104. const int SPELLS_QUANTITY=70;
  105. const int RESOURCE_QUANTITY=8;
  106. const int TERRAIN_TYPES=10;
  107. const int PRIMARY_SKILLS=4;
  108. const int NEUTRAL_PLAYER=255;
  109. const int NAMES_PER_TOWN=16;
  110. const int CREATURES_PER_TOWN = 7; //without upgrades
  111. const int MAX_BUILDING_PER_TURN = 1;
  112. const int SPELL_LEVELS = 5;
  113. //const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number
  114. const int CREEP_SIZE = 2000000000;
  115. const int WEEKLY_GROWTH = 10; //percent
  116. const int AVAILABLE_HEROES_PER_PLAYER = 2;
  117. const bool DWELLINGS_ACCUMULATE_CREATURES = true;
  118. const bool STACK_EXP = true;
  119. const int BFIELD_WIDTH = 17;
  120. const int BFIELD_HEIGHT = 11;
  121. const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT;
  122. const int SPELLBOOK_GOLD_COST = 500;
  123. //for battle stacks' positions
  124. struct THex
  125. {
  126. static const si16 INVALID = -1;
  127. enum EDir{RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT, TOP_RIGHT};
  128. si16 hex;
  129. THex() : hex(INVALID) {}
  130. THex(si16 _hex) : hex(_hex)
  131. {
  132. //assert(isValid());
  133. }
  134. operator si16() const
  135. {
  136. return hex;
  137. }
  138. bool isValid() const
  139. {
  140. return hex >= 0 && hex < BFIELD_SIZE;
  141. }
  142. template<typename inttype>
  143. THex(inttype x, inttype y)
  144. {
  145. setXY(x, y);
  146. }
  147. template<typename inttype>
  148. THex(std::pair<inttype, inttype> xy)
  149. {
  150. setXY(xy);
  151. }
  152. template<typename inttype>
  153. void setX(inttype x)
  154. {
  155. setXY(x, getY());
  156. }
  157. template<typename inttype>
  158. void setY(inttype y)
  159. {
  160. setXY(getX(), y);
  161. }
  162. void setXY(si16 x, si16 y)
  163. {
  164. assert(x >= 0 && x < BFIELD_WIDTH && y >= 0 && y < BFIELD_HEIGHT);
  165. hex = x + y * BFIELD_WIDTH;
  166. }
  167. template<typename inttype>
  168. void setXY(std::pair<inttype, inttype> xy)
  169. {
  170. setXY(xy.first, xy.second);
  171. }
  172. si16 getY() const
  173. {
  174. return hex/BFIELD_WIDTH;
  175. }
  176. si16 getX() const
  177. {
  178. int pos = hex - getY() * BFIELD_WIDTH;
  179. return pos;
  180. }
  181. std::pair<si16, si16> getXY() const
  182. {
  183. return std::make_pair(getX(), getY());
  184. }
  185. //moving to direction
  186. void operator+=(EDir dir)
  187. {
  188. si16 x = getX(),
  189. y = getY();
  190. switch(dir)
  191. {
  192. case TOP_LEFT:
  193. setXY(y%2 ? x-1 : x, y-1);
  194. break;
  195. case TOP_RIGHT:
  196. setXY(y%2 ? x : x+1, y-1);
  197. break;
  198. case RIGHT:
  199. setXY(x+1, y);
  200. break;
  201. case BOTTOM_RIGHT:
  202. setXY(y%2 ? x : x+1, y+1);
  203. break;
  204. case BOTTOM_LEFT:
  205. setXY(y%2 ? x-1 : x, y+1);
  206. break;
  207. case LEFT:
  208. setXY(x-1, y);
  209. break;
  210. default:
  211. throw std::string("Disaster: wrong direction in THex::operator+=!\n");
  212. break;
  213. }
  214. }
  215. //generates new THex moved by given dir
  216. THex operator+(EDir dir) const
  217. {
  218. THex ret(*this);
  219. ret += dir;
  220. return ret;
  221. }
  222. std::vector<THex> neighbouringTiles() const
  223. {
  224. std::vector<THex> ret;
  225. const int WN = BFIELD_WIDTH;
  226. checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret);
  227. checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret);
  228. checkAndPush(hex - 1, ret);
  229. checkAndPush(hex + 1, ret);
  230. checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), ret);
  231. checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), ret);
  232. return ret;
  233. }
  234. //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
  235. static signed char mutualPosition(THex hex1, THex hex2)
  236. {
  237. if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left
  238. return 0;
  239. if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right
  240. return 1;
  241. if(hex2 == hex1 - 1 && hex1%17 != 0) //left
  242. return 5;
  243. if(hex2 == hex1 + 1 && hex1%17 != 16) //right
  244. return 2;
  245. if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left
  246. return 4;
  247. if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right
  248. return 3;
  249. return -1;
  250. }
  251. //returns distance between given hexes
  252. static si8 getDistance(THex hex1, THex hex2)
  253. {
  254. int xDst = std::abs(hex1 % BFIELD_WIDTH - hex2 % BFIELD_WIDTH),
  255. yDst = std::abs(hex1 / BFIELD_WIDTH - hex2 / BFIELD_WIDTH);
  256. return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2;
  257. }
  258. template <typename Handler> void serialize(Handler &h, const int version)
  259. {
  260. h & hex;
  261. }
  262. private:
  263. static void checkAndPush(int tile, std::vector<THex> & ret)
  264. {
  265. if( tile>=0 && tile<BFIELD_SIZE && (tile%BFIELD_WIDTH != (BFIELD_WIDTH - 1)) && (tile%BFIELD_WIDTH != 0) )
  266. ret.push_back(THex(tile));
  267. }
  268. };
  269. enum EMarketMode
  270. {
  271. RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT,
  272. ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, RESOURCE_SKILL,
  273. MARTKET_AFTER_LAST_PLACEHOLDER
  274. };
  275. namespace SpellCasting
  276. {
  277. enum ESpellCastProblem
  278. {
  279. OK, NO_HERO_TO_CAST_SPELL, ALREADY_CASTED_THIS_TURN, NO_SPELLBOOK, ANOTHER_ELEMENTAL_SUMMONED,
  280. HERO_DOESNT_KNOW_SPELL, NOT_ENOUGH_MANA, ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL,
  281. SECOND_HEROS_SPELL_IMMUNITY, SPELL_LEVEL_LIMIT_EXCEEDED, NO_SPELLS_TO_DISPEL,
  282. NO_APPROPRIATE_TARGET, STACK_IMMUNE_TO_SPELL, WRONG_SPELL_TARGET
  283. };
  284. }
  285. namespace Res
  286. {
  287. enum ERes
  288. {
  289. WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL
  290. };
  291. }
  292. namespace Arts
  293. {
  294. enum EPos
  295. {
  296. PRE_FIRST = -1,
  297. HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, RIGHT_RING, LEFT_RING, FEET, MISC1, MISC2, MISC3, MISC4,
  298. MACH1, MACH2, MACH3, MACH4, SPELLBOOK, MISC5,
  299. AFTER_LAST
  300. };
  301. const ui16 BACKPACK_START = 19;
  302. const int ID_CATAPULT = 3, ID_LOCK = 145;
  303. }
  304. enum EAlignment
  305. {
  306. GOOD, EVIL, NEUTRAL
  307. };
  308. //uncomment to make it work
  309. //#define MARK_BLOCKED_POSITIONS
  310. //#define MARK_VISITABLE_POSITIONS
  311. #define DEFBYPASS
  312. #ifdef _WIN32
  313. #define DLL_F_EXPORT __declspec(dllexport)
  314. #else
  315. #if defined(__GNUC__) && __GNUC__ >= 4
  316. #define DLL_F_EXPORT __attribute__ ((visibility("default")))
  317. #else
  318. #define DLL_F_EXPORT
  319. #endif
  320. #endif
  321. #ifdef _WIN32
  322. #define DLL_F_IMPORT __declspec(dllimport)
  323. #else
  324. #if defined(__GNUC__) && __GNUC__ >= 4
  325. #define DLL_F_IMPORT __attribute__ ((visibility("default")))
  326. #else
  327. #define DLL_F_IMPORT
  328. #endif
  329. #endif
  330. #ifdef VCMI_DLL
  331. #define DLL_EXPORT DLL_F_EXPORT
  332. #else
  333. #define DLL_EXPORT DLL_F_IMPORT
  334. #endif
  335. template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
  336. #define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr)))
  337. //a normal std::map with consted operator[] for sanity
  338. template<typename KeyT, typename ValT>
  339. class bmap : public std::map<KeyT, ValT>
  340. {
  341. public:
  342. const ValT & operator[](KeyT key) const
  343. {
  344. return find(key)->second;
  345. }
  346. ValT & operator[](KeyT key)
  347. {
  348. return static_cast<std::map<KeyT, ValT> &>(*this)[key];
  349. }
  350. template <typename Handler> void serialize(Handler &h, const int version)
  351. {
  352. h & static_cast<std::map<KeyT, ValT> &>(*this);
  353. }
  354. };
  355. namespace vstd
  356. {
  357. template <typename Container, typename Item>
  358. bool contains(const Container & c, const Item &i) //returns true if container c contains item i
  359. {
  360. return std::find(c.begin(),c.end(),i) != c.end();
  361. }
  362. template <typename V, typename Item, typename Item2>
  363. bool contains(const std::map<Item,V> & c, const Item2 &i) //returns true if map c contains item i
  364. {
  365. return c.find(i)!=c.end();
  366. }
  367. template <typename V, typename Item, typename Item2>
  368. bool contains(const bmap<Item,V> & c, const Item2 &i) //returns true if bmap c contains item i
  369. {
  370. return c.find(i)!=c.end();
  371. }
  372. template <typename Item>
  373. bool contains(const boost::unordered_set<Item> & c, const Item &i) //returns true if unordered set c contains item i
  374. {
  375. return c.find(i)!=c.end();
  376. }
  377. template <typename Container1, typename Container2>
  378. typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
  379. {
  380. typename Container2::iterator itr = c2.begin();
  381. while(itr != c2.end())
  382. if(!contains(c1,*itr))
  383. return itr;
  384. else
  385. ++itr;
  386. return c2.end();
  387. }
  388. template <typename Container1, typename Container2>
  389. typename Container2::const_iterator findFirstNot(const Container1 &c1, const Container2 &c2)//returns const first element of c2 not present in c1
  390. {
  391. typename Container2::const_iterator itr = c2.begin();
  392. while(itr != c2.end())
  393. if(!contains(c1,*itr))
  394. return itr;
  395. else
  396. ++itr;
  397. return c2.end();
  398. }
  399. template <typename Container, typename Item>
  400. typename Container::iterator find(const Container & c, const Item &i)
  401. {
  402. return std::find(c.begin(),c.end(),i);
  403. }
  404. template <typename T1, typename T2>
  405. int findPos(const std::vector<T1> & c, const T2 &s) //returns position of first element in vector c equal to s, if there is no such element, -1 is returned
  406. {
  407. for(size_t i=0; i < c.size(); ++i)
  408. if(c[i] == s)
  409. return i;
  410. return -1;
  411. }
  412. template <typename T1, typename T2, typename Func>
  413. int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
  414. {
  415. for(size_t i=0; i < c.size(); ++i)
  416. if(f(c[i],s))
  417. return i;
  418. return -1;
  419. }
  420. template <typename Container, typename Item>
  421. typename Container::iterator find(Container & c, const Item &i) //returns iterator to the given element if present in container, end() if not
  422. {
  423. return std::find(c.begin(),c.end(),i);
  424. }
  425. template <typename Container, typename Item>
  426. typename Container::const_iterator find(const Container & c, const Item &i)//returns const iterator to the given element if present in container, end() if not
  427. {
  428. return std::find(c.begin(),c.end(),i);
  429. }
  430. template <typename Container, typename Item>
  431. typename Container::size_type operator-=(Container &c, const Item &i) //removes element i from container c, returns false if c does not contain i
  432. {
  433. typename Container::iterator itr = find(c,i);
  434. if(itr == c.end())
  435. return false;
  436. c.erase(itr);
  437. return true;
  438. }
  439. template <typename t1>
  440. void delObj(t1 *a1)
  441. {
  442. delete a1;
  443. }
  444. template <typename t1, typename t2>
  445. void assign(t1 &a1, const t2 &a2)
  446. {
  447. a1 = a2;
  448. }
  449. template <typename t1, typename t2>
  450. struct assigner
  451. {
  452. public:
  453. t1 &op1;
  454. t2 op2;
  455. assigner(t1 &a1, const t2 & a2)
  456. :op1(a1), op2(a2)
  457. {}
  458. void operator()()
  459. {
  460. op1 = op2;
  461. }
  462. };
  463. template <typename t1, typename t2>
  464. assigner<t1,t2> assigno(t1 &a1, const t2 &a2)
  465. {
  466. return assigner<t1,t2>(a1,a2);
  467. }
  468. template <typename t1, typename t2, typename t3>
  469. bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2)
  470. {
  471. return a1.*point == a2;
  472. }
  473. template <typename t1, typename t2>
  474. bool equal(const t1 &a1, const t2 &a2)
  475. {
  476. return a1 == a2;
  477. }
  478. }
  479. using vstd::operator-=;
  480. template <typename t1, typename t2>
  481. t1 & amax(t1 &a, const t2 &b) //assigns greater of (a, b) to a and returns maximum of (a, b)
  482. {
  483. if(a >= b)
  484. return a;
  485. else
  486. {
  487. a = b;
  488. return a;
  489. }
  490. }
  491. template <typename t1, typename t2>
  492. t1 & amin(t1 &a, const t2 &b) //assigns smaller of (a, b) to a and returns minimum of (a, b)
  493. {
  494. if(a <= b)
  495. return a;
  496. else
  497. {
  498. a = b;
  499. return a;
  500. }
  501. }
  502. template <typename t1, typename t2, typename t3>
  503. t1 & abetw(t1 &a, const t2 &b, const t3 &c) //makes a to fit the range <b, c>
  504. {
  505. amax(a,b);
  506. amin(a,c);
  507. return a;
  508. }
  509. template <typename t1, typename t2, typename t3>
  510. bool isbetw(const t1 &a, const t2 &b, const t3 &c) //checks if a is between b and c
  511. {
  512. return a > b && a < c;
  513. }
  514. template <typename t1, typename t2, typename t3>
  515. bool iswith(const t1 &a, const t2 &b, const t3 &c) //checks if a is within b and c
  516. {
  517. return a >= b && a <= c;
  518. }
  519. template <typename T>
  520. void delNull(T* &ptr) //deleted pointer and sets it to NULL
  521. {
  522. delete ptr;
  523. ptr = NULL;
  524. }
  525. #include "CConsoleHandler.h"
  526. extern DLL_EXPORT std::ostream *logfile;
  527. extern DLL_EXPORT CConsoleHandler *console;
  528. class CLogger //logger, prints log info to console and saves in file
  529. {
  530. const int lvl;
  531. public:
  532. CLogger& operator<<(std::ostream& (*fun)(std::ostream&))
  533. {
  534. if(lvl < CONSOLE_LOGGING_LEVEL)
  535. std::cout << fun;
  536. if((lvl < FILE_LOGGING_LEVEL) && logfile)
  537. *logfile << fun;
  538. return *this;
  539. }
  540. template<typename T>
  541. CLogger & operator<<(const T & data)
  542. {
  543. if(lvl < CONSOLE_LOGGING_LEVEL)
  544. {
  545. if(console)
  546. console->print(data,lvl);
  547. else
  548. std::cout << data << std::flush;
  549. }
  550. if((lvl < FILE_LOGGING_LEVEL) && logfile)
  551. *logfile << data << std::flush;
  552. return *this;
  553. }
  554. CLogger(const int Lvl) : lvl(Lvl) {}
  555. };
  556. extern DLL_EXPORT CLogger tlog0; //green - standard progress info
  557. extern DLL_EXPORT CLogger tlog1; //red - big errors
  558. extern DLL_EXPORT CLogger tlog2; //magenta - major warnings
  559. extern DLL_EXPORT CLogger tlog3; //yellow - minor warnings
  560. extern DLL_EXPORT CLogger tlog4; //white - detailed log info
  561. extern DLL_EXPORT CLogger tlog5; //gray - minor log info
  562. extern DLL_EXPORT CLogger tlog6; //teal - AI info
  563. //XXX pls dont - 'debug macros' are usually more trouble than it's worth
  564. #define HANDLE_EXCEPTION \
  565. catch (const std::exception& e) { \
  566. tlog1 << e.what() << std::endl; \
  567. throw; \
  568. } \
  569. catch (const std::exception * e) \
  570. { \
  571. tlog1 << e->what()<< std::endl; \
  572. throw; \
  573. } \
  574. catch (const std::string& e) { \
  575. tlog1 << e << std::endl; \
  576. throw; \
  577. }
  578. #define HANDLE_EXCEPTIONC(COMMAND) \
  579. catch (const std::exception& e) { \
  580. COMMAND; \
  581. tlog1 << e.what() << std::endl; \
  582. throw; \
  583. } \
  584. catch (const std::string &e) \
  585. { \
  586. COMMAND; \
  587. tlog1 << e << std::endl; \
  588. throw; \
  589. }
  590. #if defined(linux) && defined(sparc)
  591. /* SPARC does not support unaligned memory access. Let gcc know when
  592. * to emit the right code. */
  593. struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };
  594. struct unaligned_Uint32 { ui32 val __attribute__(( packed )); };
  595. static inline ui16 read_unaligned_u16(const void *p)
  596. {
  597. const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p;
  598. return v->val;
  599. }
  600. static inline ui32 read_unaligned_u32(const void *p)
  601. {
  602. const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p;
  603. return v->val;
  604. }
  605. #else
  606. #define read_unaligned_u16(p) (* reinterpret_cast<const Uint16 *>(p))
  607. #define read_unaligned_u32(p) (* reinterpret_cast<const Uint32 *>(p))
  608. #endif
  609. //for explicit overrides
  610. #ifdef _MSC_VER
  611. #define OVERRIDE override
  612. #else
  613. #define OVERRIDE //is there any working counterpart?
  614. #endif
  615. #endif // __GLOBAL_H__