- Timestamp:
- Nov 29, 2005, 11:07:43 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r5766 r5819 81 81 CL_WEAPON = 0x00120000, 82 82 83 // subsuper-classes derivations taken : 1, 5, a, b . << THIS IS A LIST OF ALL THE DCL_MASK_SUBSUPERCLASS_ID's taken83 // subsuper-classes derivations taken : 1, 5, a, b, c. << THIS IS A LIST OF ALL THE DCL_MASK_SUBSUPERCLASS_ID's taken 84 84 85 85 // lowest level classes … … 142 142 CL_LASER = 0x00000242, 143 143 CL_BOMB = 0x00000243, 144 CL_GROUND_TURRET 144 CL_GROUND_TURRET = 0x00000244, 145 145 CL_GUIDED_MISSILE = 0x00000245, 146 146 … … 171 171 172 172 // graphical stuff (range from 0x00000800 to 0x000009ff) 173 CL_TEXTURE = 0x00c01000, 173 174 CL_TEXT = 0x00b01801, 174 CL_FONT = 0x00000802, 175 CL_TEXTURE = 0x00000803, 175 CL_FONT = 0x00c02802, 176 176 CL_MATERIAL = 0x00000804, 177 177 CL_MODEL = 0x00000805, //!< @todo make this a SUBCLASS maybe -
trunk/src/defs/globals.h
r4946 r5819 17 17 "Nico Bernold - Physics\n" \ 18 18 "David Gruetter - The ProtoType\n" \ 19 "Aaron von Schroeder - Sensors\n" \ 20 "Lukas Grauer - Phasers\n" \ 19 21 "many more...\n" 22 20 23 #define ORXONOX_WEBPAGE "http://www.orxonox.net" 21 24 … … 90 93 "any later version.\n" 91 94 95 96 92 97 #define GNU_LICENCE_LONG \ 93 98 " GNU GENERAL PUBLIC LICENSE\n" \ -
trunk/src/defs/stdincl.h
r5075 r5819 17 17 #endif 18 18 19 #include <stdlibincl.h>19 #include "stdlibincl.h" 20 20 21 21 #include "sdlincl.h" 22 22 #include "glincl.h" 23 23 24 #include "error.h"25 #include "globals.h"26 27 24 #include "compiler.h" 28 25 -
trunk/src/lib/coord/p_node.cc
r5772 r5819 334 334 } 335 335 this->relDirection = relDir; 336 336 337 this->bRelCoorChanged = true; 337 338 } … … 363 364 *this->toDirection = relDirSoft; 364 365 this->bias = bias; 366 this->bRelDirChanged = true; 365 367 } 366 368 -
trunk/src/lib/event/key_mapper.h
r5474 r5819 29 29 virtual ~KeyMapper(); 30 30 31 void loadKeyBindings(const char* fileName = DEFAULT_CONFIG_FILE);31 void loadKeyBindings(const char* fileName = NULL); 32 32 void loadKeyBindings(IniParser* iniParser); 33 33 -
trunk/src/lib/graphics/graphics_engine.cc
r5790 r5819 30 30 #include "text.h" 31 31 32 #include "globals.h" 32 33 33 34 #ifdef __WIN32__ -
trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r5430 r5819 22 22 #include "material.h" 23 23 #include "abstract_model.h" 24 #include "list.h"25 #include "vector.h"26 24 #include "debug.h" 25 26 #include "util/list.h" 27 27 28 28 using namespace std; -
trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r5430 r5819 16 16 17 17 #include "base_object.h" 18 #include "vector.h" 18 19 19 #include "abstract_model.h" 20 20 -
trunk/src/lib/sound/sound_engine.cc
r5779 r5819 21 21 #include "sound_engine.h" 22 22 23 //#include <AL/alc.h> // maybe later24 23 #include "class_list.h" 25 24 … … 208 207 void SoundEngine::flushUnusedBuffers() 209 208 { 209 /// FIXME 210 210 /* if(this->sourceList && this->bufferList) 211 211 { … … 280 280 } 281 281 282 283 alutInit(NULL, 0); 282 // INITIALIZING THE DEVICE: 283 ALCubyte deviceName[] = 284 #ifdef __WIN32__ 285 "native"; 286 #else 287 "'( ( devices '( native arts null ) ) )"; 288 #endif 289 // 290 this->device = alcOpenDevice(deviceName); 291 292 this->context = alcCreateContext(this->device, NULL); 293 294 alcMakeContextCurrent(this->context); 295 296 284 297 if ((result = alGetError()) != AL_NO_ERROR) 285 298 SoundEngine::PrintALErrorString(result); -
trunk/src/lib/sound/sound_engine.h
r5779 r5819 68 68 static SoundEngine* singletonRef; //!< Reference to this class 69 69 70 ALCdevice* device; //!< the used audio-device. 71 ALCcontext* context; //!< the context, currently in use. 72 70 73 float musicVolume; //!< the maximum volume of the music in % (0f,1f] 71 74 float effectsVolume; //!< the maximum volume of sound-effects in % (0f,1f] 72 75 PNode* listener; //!< The listener of the Scene 76 73 77 std::list<BaseObject*>* bufferList; //!< A list of buffers 74 78 std::list<BaseObject*>* sourceList; //!< A list for all the sources in the scene. 79 75 80 76 81 }; -
trunk/src/lib/tinyxml/tinystr.cc
r4491 r5819 3 3 Original file by Yves Berquin. 4 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any 7 7 damages arising from the use of this software. 8 8 9 Permission is granted to anyone to use this software for any 10 purpose, including commercial applications, and to alter it and 9 Permission is granted to anyone to use this software for any 10 purpose, including commercial applications, and to alter it and 11 11 redistribute it freely, subject to the following restrictions: 12 12 13 1. The origin of this software must not be misrepresented; you must 14 not claim that you wrote the original software. If you use this 15 software in a product, an acknowledgment in the product documentation 13 1. The origin of this software must not be misrepresented; you must 14 not claim that you wrote the original software. If you use this 15 software in a product, an acknowledgment in the product documentation 16 16 would be appreciated but is not required. 17 17 … … 19 19 must not be misrepresented as being the original software. 20 20 21 3. This notice may not be removed or altered from any source 21 3. This notice may not be removed or altered from any source 22 22 distribution. 23 23 */ 24 24 25 #include "tinyxml.h" 25 /* 26 * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005. 27 */ 28 26 29 27 30 #ifndef TIXML_USE_STL 28 31 29 30 #include <stdlib.h>31 #include <string.h>32 #include <ctype.h>33 34 32 #include "tinystr.h" 35 33 36 // TiXmlString constructor, based on a C string 37 TiXmlString::TiXmlString (const char* instring) 34 // Error value for find primitive 35 const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1); 36 37 // Null rep. 38 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' }; 39 40 41 void TiXmlString::reserve (size_type cap) 38 42 { 39 size_t newlen; 40 char * newstring; 41 42 if (!instring) 43 { 44 allocated = 0; 45 cstring = NULL; 46 current_length = 0; 47 return; 48 } 49 newlen = strlen (instring) + 1; 50 newstring = new char [newlen]; 51 memcpy (newstring, instring, newlen); 52 // strcpy (newstring, instring); 53 allocated = newlen; 54 cstring = newstring; 55 current_length = newlen - 1; 56 } 57 58 // TiXmlString copy constructor 59 TiXmlString::TiXmlString (const TiXmlString& copy) 60 { 61 size_t newlen; 62 char * newstring; 63 64 // Prevent copy to self! 65 if ( © == this ) 66 return; 67 68 if (! copy . allocated) 69 { 70 allocated = 0; 71 cstring = NULL; 72 current_length = 0; 73 return; 74 } 75 newlen = copy . length () + 1; 76 newstring = new char [newlen]; 77 // strcpy (newstring, copy . cstring); 78 memcpy (newstring, copy . cstring, newlen); 79 allocated = newlen; 80 cstring = newstring; 81 current_length = newlen - 1; 82 } 83 84 // TiXmlString = operator. Safe when assign own content 85 void TiXmlString ::operator = (const char * content) 86 { 87 size_t newlen; 88 char * newstring; 89 90 if (! content) 91 { 92 empty_it (); 93 return; 94 } 95 newlen = strlen (content) + 1; 96 newstring = new char [newlen]; 97 // strcpy (newstring, content); 98 memcpy (newstring, content, newlen); 99 empty_it (); 100 allocated = newlen; 101 cstring = newstring; 102 current_length = newlen - 1; 103 } 104 105 // = operator. Safe when assign own content 106 void TiXmlString ::operator = (const TiXmlString & copy) 107 { 108 size_t newlen; 109 char * newstring; 110 111 if (! copy . length ()) 112 { 113 empty_it (); 114 return; 115 } 116 newlen = copy . length () + 1; 117 newstring = new char [newlen]; 118 // strcpy (newstring, copy . c_str ()); 119 memcpy (newstring, copy . c_str (), newlen); 120 empty_it (); 121 allocated = newlen; 122 cstring = newstring; 123 current_length = newlen - 1; 43 if (cap > capacity()) 44 { 45 TiXmlString tmp; 46 tmp.init(length(), cap); 47 memcpy(tmp.start(), data(), length()); 48 swap(tmp); 49 } 124 50 } 125 51 126 52 127 // append a const char * to an existing TiXmlString 128 void TiXmlString::append( const char* str, size_t len ) 53 TiXmlString& TiXmlString::assign(const char* str, size_type len) 129 54 { 130 char * new_string; 131 size_t new_alloc, new_size, size_suffix; 132 133 // don't use strlen - it can overrun the len passed in! 134 const char* p = str; 135 size_suffix = 0; 136 137 while ( *p && size_suffix < (unsigned)len ) 55 size_type cap = capacity(); 56 if (len > cap || cap > 3*(len + 8)) 138 57 { 139 ++p; 140 ++size_suffix; 58 TiXmlString tmp; 59 tmp.init(len); 60 memcpy(tmp.start(), str, len); 61 swap(tmp); 141 62 } 142 if ( !size_suffix) 143 return; 144 145 new_size = length () + size_suffix + 1; 146 // check if we need to expand 147 if (new_size > allocated) 148 { 149 // compute new size 150 new_alloc = assign_new_size (new_size); 151 152 // allocate new buffer 153 new_string = new char [new_alloc]; 154 new_string [0] = 0; 155 156 // copy the previous allocated buffer into this one 157 if (allocated && cstring) 158 // strcpy (new_string, cstring); 159 memcpy (new_string, cstring, length ()); 160 161 // append the suffix. It does exist, otherwize we wouldn't be expanding 162 // strncat (new_string, str, len); 163 memcpy (new_string + length (), 164 str, 165 size_suffix); 166 167 // return previsously allocated buffer if any 168 if (allocated && cstring) 169 delete [] cstring; 170 171 // update member variables 172 cstring = new_string; 173 allocated = new_alloc; 174 } 175 else 176 { 177 // we know we can safely append the new string 178 // strncat (cstring, str, len); 179 memcpy (cstring + length (), 180 str, 181 size_suffix); 182 } 183 current_length = new_size - 1; 184 cstring [current_length] = 0; 63 else 64 { 65 memmove(start(), str, len); 66 set_size(len); 67 } 68 return *this; 185 69 } 186 70 187 71 188 // append a const char * to an existing TiXmlString 189 void TiXmlString::append( const char * suffix ) 72 TiXmlString& TiXmlString::append(const char* str, size_type len) 190 73 { 191 char * new_string; 192 size_t new_alloc, new_size; 193 194 new_size = length () + strlen (suffix) + 1; 195 // check if we need to expand 196 if (new_size > allocated) 197 { 198 // compute new size 199 new_alloc = assign_new_size (new_size); 200 201 // allocate new buffer 202 new_string = new char [new_alloc]; 203 new_string [0] = 0; 204 205 // copy the previous allocated buffer into this one 206 if (allocated && cstring) 207 memcpy (new_string, cstring, 1 + length ()); 208 // strcpy (new_string, cstring); 209 210 // append the suffix. It does exist, otherwize we wouldn't be expanding 211 // strcat (new_string, suffix); 212 memcpy (new_string + length (), 213 suffix, 214 strlen (suffix) + 1); 215 216 // return previsously allocated buffer if any 217 if (allocated && cstring) 218 delete [] cstring; 219 220 // update member variables 221 cstring = new_string; 222 allocated = new_alloc; 223 } 224 else 225 { 226 // we know we can safely append the new string 227 // strcat (cstring, suffix); 228 memcpy (cstring + length (), 229 suffix, 230 strlen (suffix) + 1); 231 } 232 current_length = new_size - 1; 233 } 234 235 // Check for TiXmlString equuivalence 236 //bool TiXmlString::operator == (const TiXmlString & compare) const 237 //{ 238 // return (! strcmp (c_str (), compare . c_str ())); 239 //} 240 241 //unsigned TiXmlString::length () const 242 //{ 243 // if (allocated) 244 // // return strlen (cstring); 245 // return current_length; 246 // return 0; 247 //} 248 249 250 unsigned TiXmlString::find (char tofind, unsigned offset) const 251 { 252 char * lookup; 253 254 if (offset >= length ()) 255 return (unsigned) notfound; 256 for (lookup = cstring + offset; * lookup; lookup++) 257 if (* lookup == tofind) 258 return (unsigned)(lookup - cstring); 259 return (unsigned) notfound; 74 size_type newsize = length() + len; 75 if (newsize > capacity()) 76 { 77 reserve (newsize + capacity()); 78 } 79 memmove(finish(), str, len); 80 set_size(newsize); 81 return *this; 260 82 } 261 83 262 84 263 bool TiXmlString::operator == (const TiXmlString & compare) const 85 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) 264 86 { 265 if ( allocated && compare.allocated ) 266 { 267 assert( cstring ); 268 assert( compare.cstring ); 269 return ( strcmp( cstring, compare.cstring ) == 0 ); 270 } 271 else if ( length() == 0 && compare.length() == 0 ) 272 { 273 return true; 274 } 275 return false; 87 TiXmlString tmp; 88 tmp.reserve(a.length() + b.length()); 89 tmp += a; 90 tmp += b; 91 return tmp; 276 92 } 277 93 278 279 bool TiXmlString::operator == (const char* compare) const 94 TiXmlString operator + (const TiXmlString & a, const char* b) 280 95 { 281 if ( allocated && compare && *compare ) 282 { 283 assert( cstring ); 284 return ( strcmp( cstring, compare ) == 0 ); 285 } 286 else if ( length() == 0 && (!compare || !*compare ) ) // this is a little dubious, but try to duplicate behavior in other operator== 287 { 288 return true; 289 } 290 return false; 96 TiXmlString tmp; 97 TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) ); 98 tmp.reserve(a.length() + b_len); 99 tmp += a; 100 tmp.append(b, b_len); 101 return tmp; 291 102 } 292 103 293 294 bool TiXmlString::operator < (const TiXmlString & compare) const 104 TiXmlString operator + (const char* a, const TiXmlString & b) 295 105 { 296 if ( allocated && compare.allocated ) 297 { 298 assert( cstring ); 299 assert( compare.cstring ); 300 return ( strcmp( cstring, compare.cstring ) > 0 ); 301 } 302 return false; 303 } 304 305 306 bool TiXmlString::operator > (const TiXmlString & compare) const 307 { 308 if ( allocated && compare.allocated ) 309 { 310 assert( cstring ); 311 assert( compare.cstring ); 312 return ( strcmp( cstring, compare.cstring ) < 0 ); 313 } 314 return false; 106 TiXmlString tmp; 107 TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) ); 108 tmp.reserve(a_len + b.length()); 109 tmp.append(a, a_len); 110 tmp += b; 111 return tmp; 315 112 } 316 113 -
trunk/src/lib/tinyxml/tinystr.h
r4491 r5819 3 3 Original file by Yves Berquin. 4 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any 7 7 damages arising from the use of this software. 8 8 9 Permission is granted to anyone to use this software for any 10 purpose, including commercial applications, and to alter it and 9 Permission is granted to anyone to use this software for any 10 purpose, including commercial applications, and to alter it and 11 11 redistribute it freely, subject to the following restrictions: 12 12 13 1. The origin of this software must not be misrepresented; you must 14 not claim that you wrote the original software. If you use this 15 software in a product, an acknowledgment in the product documentation 13 1. The origin of this software must not be misrepresented; you must 14 not claim that you wrote the original software. If you use this 15 software in a product, an acknowledgment in the product documentation 16 16 would be appreciated but is not required. 17 17 … … 19 19 must not be misrepresented as being the original software. 20 20 21 3. This notice may not be removed or altered from any source 21 3. This notice may not be removed or altered from any source 22 22 distribution. 23 23 */ 24 24 25 #include "tinyxml.h" 26 25 /* 26 * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005. 27 * 28 * - completely rewritten. compact, clean, and fast implementation. 29 * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems) 30 * - fixed reserve() to work as per specification. 31 * - fixed buggy compares operator==(), operator<(), and operator>() 32 * - fixed operator+=() to take a const ref argument, following spec. 33 * - added "copy" constructor with length, and most compare operators. 34 * - added swap(), clear(), size(), capacity(), operator+(). 35 */ 27 36 28 37 #ifndef TIXML_USE_STL … … 31 40 #define TIXML_STRING_INCLUDED 32 41 33 #ifdef _MSC_VER34 #pragma warning( disable : 4530 )35 #pragma warning( disable : 4786 )36 #endif37 38 42 #include <assert.h> 43 #include <string.h> 39 44 40 45 /* 41 TiXmlString is an emulation of the std::string template.46 TiXmlString is an emulation of a subset of the std::string template. 42 47 Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. 43 48 Only the member functions relevant to the TinyXML project have been implemented. … … 48 53 { 49 54 public : 50 // TiXmlString constructor, based on a string, mark explicit to force 51 // us to find unnecessary casting. 52 explicit TiXmlString (const char * instring); 53 54 // TiXmlString empty constructor 55 TiXmlString () 56 { 57 allocated = 0; 58 cstring = NULL; 59 current_length = 0; 60 } 61 62 // TiXmlString copy constructor 63 explicit TiXmlString (const TiXmlString& copy); 64 65 // TiXmlString destructor 66 ~ TiXmlString () 67 { 68 empty_it (); 69 } 70 71 // Convert a TiXmlString into a classical char * 72 const char * c_str () const 73 { 74 if (allocated) 75 return cstring; 76 return ""; 77 } 78 79 // Return the length of a TiXmlString 80 size_t length () const 81 { 82 return ( allocated ) ? current_length : 0; 83 } 84 85 // TiXmlString = operator 86 void operator = (const char * content); 87 88 // = operator 89 void operator = (const TiXmlString & copy); 90 91 // += operator. Maps to append 92 TiXmlString& operator += (const char * suffix) 93 { 94 append (suffix); 95 return *this; 96 } 97 98 // += operator. Maps to append 99 TiXmlString& operator += (char single) 100 { 101 append (single); 102 return *this; 103 } 104 105 // += operator. Maps to append 106 TiXmlString& operator += (TiXmlString & suffix) 107 { 108 append (suffix); 109 return *this; 110 } 111 bool operator == (const TiXmlString & compare) const; 112 bool operator == (const char* compare) const; 113 bool operator < (const TiXmlString & compare) const; 114 bool operator > (const TiXmlString & compare) const; 115 116 // Checks if a TiXmlString is empty 117 bool empty () const 118 { 119 return length () ? false : true; 120 } 121 122 // single char extraction 123 const char& at (unsigned index) const 124 { 125 assert( index < length ()); 126 return cstring [index]; 127 } 128 129 // find a char in a string. Return TiXmlString::notfound if not found 130 unsigned find (char lookup) const 131 { 132 return find (lookup, 0); 133 } 134 135 // find a char in a string from an offset. Return TiXmlString::notfound if not found 136 unsigned find (char tofind, unsigned offset) const; 137 138 /* Function to reserve a big amount of data when we know we'll need it. Be aware that this 139 function clears the content of the TiXmlString if any exists. 140 */ 141 void reserve (unsigned size) 142 { 143 empty_it (); 144 if (size) 145 { 146 allocated = size; 147 cstring = new char [size]; 148 cstring [0] = 0; 149 current_length = 0; 150 } 151 } 152 153 // [] operator 154 char& operator [] (unsigned index) const 155 { 156 assert( index < length ()); 157 return cstring [index]; 158 } 159 160 // Error value for find primitive 161 enum { notfound = 0xffffffff, 162 npos = notfound }; 163 164 void append (const char *str, size_t len ); 165 166 protected : 167 168 // The base string 169 char * cstring; 170 // Number of chars allocated 171 size_t allocated; 172 // Current string size 173 size_t current_length; 174 175 // New size computation. It is simplistic right now : it returns twice the amount 176 // we need 177 size_t assign_new_size (size_t minimum_to_allocate) 178 { 179 return minimum_to_allocate * 2; 180 } 181 182 // Internal function that clears the content of a TiXmlString 183 void empty_it () 184 { 185 if (cstring) 186 delete [] cstring; 187 cstring = NULL; 188 allocated = 0; 189 current_length = 0; 190 } 191 192 void append (const char *suffix ); 193 194 // append function for another TiXmlString 195 void append (const TiXmlString & suffix) 196 { 197 append (suffix . c_str ()); 198 } 199 200 // append for a single char. 201 void append (char single) 202 { 203 if ( cstring && current_length < (allocated-1) ) 55 // The size type used 56 typedef unsigned int size_type; 57 58 // Error value for find primitive 59 static const size_type npos; // = -1; 60 61 62 // TiXmlString empty constructor 63 TiXmlString () : rep_(&nullrep_) 64 { 65 } 66 67 // TiXmlString copy constructor 68 TiXmlString (const TiXmlString & copy) 69 { 70 init(copy.length()); 71 memcpy(start(), copy.data(), length()); 72 } 73 74 // TiXmlString constructor, based on a string 75 TiXmlString (const char * copy) 76 { 77 init( static_cast<size_type>( strlen(copy) )); 78 memcpy(start(), copy, length()); 79 } 80 81 // TiXmlString constructor, based on a string 82 TiXmlString (const char * str, size_type len) 83 { 84 init(len); 85 memcpy(start(), str, len); 86 } 87 88 // TiXmlString destructor 89 ~TiXmlString () 90 { 91 quit(); 92 } 93 94 // = operator 95 TiXmlString& operator = (const char * copy) 96 { 97 return assign( copy, (size_type)strlen(copy)); 98 } 99 100 // = operator 101 TiXmlString& operator = (const TiXmlString & copy) 102 { 103 return assign(copy.start(), copy.length()); 104 } 105 106 107 // += operator. Maps to append 108 TiXmlString& operator += (const char * suffix) 109 { 110 return append(suffix, static_cast<size_type>( strlen(suffix) )); 111 } 112 113 // += operator. Maps to append 114 TiXmlString& operator += (char single) 115 { 116 return append(&single, 1); 117 } 118 119 // += operator. Maps to append 120 TiXmlString& operator += (const TiXmlString & suffix) 121 { 122 return append(suffix.data(), suffix.length()); 123 } 124 125 126 // Convert a TiXmlString into a null-terminated char * 127 const char * c_str () const { return rep_->str; } 128 129 // Convert a TiXmlString into a char * (need not be null terminated). 130 const char * data () const { return rep_->str; } 131 132 // Return the length of a TiXmlString 133 size_type length () const { return rep_->size; } 134 135 // Alias for length() 136 size_type size () const { return rep_->size; } 137 138 // Checks if a TiXmlString is empty 139 bool empty () const { return rep_->size == 0; } 140 141 // Return capacity of string 142 size_type capacity () const { return rep_->capacity; } 143 144 145 // single char extraction 146 const char& at (size_type index) const 147 { 148 assert( index < length() ); 149 return rep_->str[ index ]; 150 } 151 152 // [] operator 153 char& operator [] (size_type index) const 154 { 155 assert( index < length() ); 156 return rep_->str[ index ]; 157 } 158 159 // find a char in a string. Return TiXmlString::npos if not found 160 size_type find (char lookup) const 161 { 162 return find(lookup, 0); 163 } 164 165 // find a char in a string from an offset. Return TiXmlString::npos if not found 166 size_type find (char tofind, size_type offset) const 167 { 168 if (offset >= length()) return npos; 169 170 for (const char* p = c_str() + offset; *p != '\0'; ++p) 204 171 { 205 cstring[ current_length ] = single; 206 ++current_length; 207 cstring[ current_length ] = 0; 172 if (*p == tofind) return static_cast< size_type >( p - c_str() ); 173 } 174 return npos; 175 } 176 177 void clear () 178 { 179 //Lee: 180 //The original was just too strange, though correct: 181 // TiXmlString().swap(*this); 182 //Instead use the quit & re-init: 183 quit(); 184 init(0,0); 185 } 186 187 /* Function to reserve a big amount of data when we know we'll need it. Be aware that this 188 function DOES NOT clear the content of the TiXmlString if any exists. 189 */ 190 void reserve (size_type cap); 191 192 TiXmlString& assign (const char* str, size_type len); 193 194 TiXmlString& append (const char* str, size_type len); 195 196 void swap (TiXmlString& other) 197 { 198 Rep* r = rep_; 199 rep_ = other.rep_; 200 other.rep_ = r; 201 } 202 203 private: 204 205 void init(size_type sz) { init(sz, sz); } 206 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } 207 char* start() const { return rep_->str; } 208 char* finish() const { return rep_->str + rep_->size; } 209 210 struct Rep 211 { 212 size_type size, capacity; 213 char str[1]; 214 }; 215 216 void init(size_type sz, size_type cap) 217 { 218 if (cap) 219 { 220 // Lee: the original form: 221 // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap)); 222 // doesn't work in some cases of new being overloaded. Switching 223 // to the normal allocation, although use an 'int' for systems 224 // that are overly picky about structure alignment. 225 const size_type bytesNeeded = sizeof(Rep) + cap; 226 const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); 227 rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] ); 228 229 rep_->str[ rep_->size = sz ] = '\0'; 230 rep_->capacity = cap; 208 231 } 209 232 else 210 233 { 211 char smallstr [2]; 212 smallstr [0] = single; 213 smallstr [1] = 0; 214 append (smallstr); 234 rep_ = &nullrep_; 215 235 } 216 } 236 } 237 238 void quit() 239 { 240 if (rep_ != &nullrep_) 241 { 242 // The rep_ is really an array of ints. (see the allocator, above). 243 // Cast it back before delete, so the compiler won't incorrectly call destructors. 244 delete [] ( reinterpret_cast<int*>( rep_ ) ); 245 } 246 } 247 248 Rep * rep_; 249 static Rep nullrep_; 217 250 218 251 } ; 219 252 220 /* 253 254 inline bool operator == (const TiXmlString & a, const TiXmlString & b) 255 { 256 return ( a.length() == b.length() ) // optimization on some platforms 257 && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare 258 } 259 inline bool operator < (const TiXmlString & a, const TiXmlString & b) 260 { 261 return strcmp(a.c_str(), b.c_str()) < 0; 262 } 263 264 inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } 265 inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } 266 inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } 267 inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } 268 269 inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } 270 inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } 271 inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } 272 inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } 273 274 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); 275 TiXmlString operator + (const TiXmlString & a, const char* b); 276 TiXmlString operator + (const char* a, const TiXmlString & b); 277 278 279 /* 221 280 TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. 222 281 Only the operators that we need for TinyXML have been developped. … … 225 284 { 226 285 public : 227 TiXmlOutStream () : TiXmlString () {} 228 229 // TiXmlOutStream << operator. Maps to TiXmlString::append 230 TiXmlOutStream & operator << (const char * in) 231 { 232 append (in);233 return (* this); 234 } 235 236 // TiXmlOutStream << operator. Maps to TiXmlString::append 237 TiXmlOutStream & operator << (const TiXmlString & in) 238 { 239 append (in . c_str ());240 return (* this); 241 } 286 287 // TiXmlOutStream << operator. 288 TiXmlOutStream & operator << (const TiXmlString & in) 289 { 290 *this += in; 291 return *this; 292 } 293 294 // TiXmlOutStream << operator. 295 TiXmlOutStream & operator << (const char * in) 296 { 297 *this += in; 298 return *this; 299 } 300 242 301 } ; 243 244 #ifdef _MSC_VER245 #pragma warning( default : 4530 )246 #pragma warning( default : 4786 )247 #endif248 302 249 303 #endif // TIXML_STRING_INCLUDED -
trunk/src/lib/tinyxml/tinyxml.cc
r4491 r5819 101 101 // Below 32 is symbolic. 102 102 char buf[ 32 ]; 103 sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); 103 104 #if defined(TIXML_SNPRINTF) 105 TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); 106 #else 107 sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); 108 #endif 109 104 110 //*ME: warning C4267: convert 'size_t' to 'int' 105 111 //*ME: Int-Cast to make compiler happy ... … … 319 325 for ( node = firstChild; node; node = node->next ) 320 326 { 321 if ( node->SValue() == _value)327 if ( strcmp( node->Value(), _value ) == 0 ) 322 328 return node; 323 329 } … … 331 337 for ( node = firstChild; node; node = node->next ) 332 338 { 333 if ( node->SValue() == _value)339 if ( strcmp( node->Value(), _value ) == 0 ) 334 340 return node; 335 341 } … … 343 349 for ( node = lastChild; node; node = node->prev ) 344 350 { 345 if ( node->SValue() == _value)351 if ( strcmp( node->Value(), _value ) == 0 ) 346 352 return node; 347 353 } … … 354 360 for ( node = lastChild; node; node = node->prev ) 355 361 { 356 if ( node->SValue() == _value)362 if ( strcmp( node->Value(), _value ) == 0 ) 357 363 return node; 358 364 } … … 417 423 for ( node = next; node; node = node->next ) 418 424 { 419 if ( node->SValue() == _value)425 if ( strcmp( node->Value(), _value ) == 0 ) 420 426 return node; 421 427 } … … 428 434 for ( node = next; node; node = node->next ) 429 435 { 430 if ( node->SValue() == _value)436 if ( strcmp( node->Value(), _value ) == 0 ) 431 437 return node; 432 438 } … … 439 445 for ( node = prev; node; node = node->prev ) 440 446 { 441 if ( node->SValue() == _value)447 if ( strcmp( node->Value(), _value ) == 0 ) 442 448 return node; 443 449 } … … 450 456 for ( node = prev; node; node = node->prev ) 451 457 { 452 if ( node->SValue() == _value)458 if ( strcmp( node->Value(), _value ) == 0 ) 453 459 return node; 454 460 } … … 716 722 { 717 723 char buf[64]; 718 sprintf( buf, "%d", val ); 724 #if defined(TIXML_SNPRINTF) 725 TIXML_SNPRINTF( buf, sizeof(buf), "%d", val ); 726 #else 727 sprintf( buf, "%d", val ); 728 #endif 719 729 SetAttribute( name, buf ); 720 730 } … … 724 734 { 725 735 char buf[256]; 726 sprintf( buf, "%f", val ); 736 #if defined(TIXML_SNPRINTF) 737 TIXML_SNPRINTF( buf, sizeof(buf), "%f", val ); 738 #else 739 sprintf( buf, "%f", val ); 740 #endif 727 741 SetAttribute( name, buf ); 728 742 } … … 866 880 867 881 882 const char* TiXmlElement::GetText() const 883 { 884 const TiXmlNode* child = this->FirstChild(); 885 if ( child ) { 886 const TiXmlText* childText = child->ToText(); 887 if ( childText ) { 888 return childText->Value(); 889 } 890 } 891 return 0; 892 } 893 894 868 895 TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) 869 896 { 870 897 tabsize = 4; 898 useMicrosoftBOM = false; 871 899 ClearError(); 872 900 } … … 875 903 { 876 904 tabsize = 4; 905 useMicrosoftBOM = false; 877 906 value = documentName; 878 907 ClearError(); … … 884 913 { 885 914 tabsize = 4; 915 useMicrosoftBOM = false; 886 916 value = documentName; 887 917 ClearError(); … … 942 972 value = filename; 943 973 944 FILE* file = fopen( value.c_str (), "r" ); 974 // reading in binary mode so that tinyxml can normalize the EOL 975 FILE* file = fopen( value.c_str (), "rb" ); 945 976 946 977 if ( file ) … … 964 995 data.reserve( length ); 965 996 966 const int BUF_SIZE = 2048; 967 char buf[BUF_SIZE]; 968 969 while( fgets( buf, BUF_SIZE, file ) ) 997 // Subtle bug here. TinyXml did use fgets. But from the XML spec: 998 // 2.11 End-of-Line Handling 999 // <snip> 1000 // <quote> 1001 // ...the XML processor MUST behave as if it normalized all line breaks in external 1002 // parsed entities (including the document entity) on input, before parsing, by translating 1003 // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 1004 // a single #xA character. 1005 // </quote> 1006 // 1007 // It is not clear fgets does that, and certainly isn't clear it works cross platform. 1008 // Generally, you expect fgets to translate from the convention of the OS to the c/unix 1009 // convention, and not work generally. 1010 1011 /* 1012 while( fgets( buf, sizeof(buf), file ) ) 970 1013 { 971 1014 data += buf; 972 1015 } 1016 */ 1017 1018 char* buf = new char[ length+1 ]; 1019 buf[0] = 0; 1020 1021 if ( fread( buf, length, 1, file ) != 1 ) { 1022 //if ( fread( buf, 1, length, file ) != (size_t)length ) { 1023 SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); 1024 fclose( file ); 1025 return false; 1026 } 973 1027 fclose( file ); 1028 1029 const char* lastPos = buf; 1030 const char* p = buf; 1031 1032 buf[length] = 0; 1033 while( *p ) { 1034 assert( p < (buf+length) ); 1035 if ( *p == 0xa ) { 1036 // Newline character. No special rules for this. Append all the characters 1037 // since the last string, and include the newline. 1038 data.append( lastPos, p-lastPos+1 ); // append, include the newline 1039 ++p; // move past the newline 1040 lastPos = p; // and point to the new buffer (may be 0) 1041 assert( p <= (buf+length) ); 1042 } 1043 else if ( *p == 0xd ) { 1044 // Carriage return. Append what we have so far, then 1045 // handle moving forward in the buffer. 1046 if ( (p-lastPos) > 0 ) { 1047 data.append( lastPos, p-lastPos ); // do not add the CR 1048 } 1049 data += (char)0xa; // a proper newline 1050 1051 if ( *(p+1) == 0xa ) { 1052 // Carriage return - new line sequence 1053 p += 2; 1054 lastPos = p; 1055 assert( p <= (buf+length) ); 1056 } 1057 else { 1058 // it was followed by something else...that is presumably characters again. 1059 ++p; 1060 lastPos = p; 1061 assert( p <= (buf+length) ); 1062 } 1063 } 1064 else { 1065 ++p; 1066 } 1067 } 1068 // Handle any left over characters. 1069 if ( p-lastPos ) { 1070 data.append( lastPos, p-lastPos ); 1071 } 1072 delete [] buf; 1073 buf = 0; 974 1074 975 1075 Parse( data.c_str(), 0, encoding ); … … 990 1090 if ( fp ) 991 1091 { 1092 if ( useMicrosoftBOM ) 1093 { 1094 const unsigned char TIXML_UTF_LEAD_0 = 0xefU; 1095 const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; 1096 const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; 1097 1098 fputc( TIXML_UTF_LEAD_0, fp ); 1099 fputc( TIXML_UTF_LEAD_1, fp ); 1100 fputc( TIXML_UTF_LEAD_2, fp ); 1101 } 992 1102 Print( fp, 0 ); 993 1103 fclose( fp ); … … 1135 1245 { 1136 1246 char buf [64]; 1137 sprintf (buf, "%d", _value); 1247 #if defined(TIXML_SNPRINTF) 1248 TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); 1249 #else 1250 sprintf (buf, "%d", _value); 1251 #endif 1138 1252 SetValue (buf); 1139 1253 } … … 1142 1256 { 1143 1257 char buf [256]; 1144 sprintf (buf, "%lf", _value); 1258 #if defined(TIXML_SNPRINTF) 1259 TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value); 1260 #else 1261 sprintf (buf, "%lf", _value); 1262 #endif 1145 1263 SetValue (buf); 1146 1264 } 1147 1265 1148 constint TiXmlAttribute::IntValue() const1266 int TiXmlAttribute::IntValue() const 1149 1267 { 1150 1268 return atoi (value.c_str ()); 1151 1269 } 1152 1270 1153 constdouble TiXmlAttribute::DoubleValue() const1271 double TiXmlAttribute::DoubleValue() const 1154 1272 { 1155 1273 return atof (value.c_str ()); … … 1206 1324 1207 1325 1208 void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const 1209 { 1210 TIXML_STRING buffer; 1211 PutString( value, &buffer ); 1212 fprintf( cfile, "%s", buffer.c_str() ); 1326 void TiXmlText::Print( FILE* cfile, int depth ) const 1327 { 1328 if ( cdata ) 1329 { 1330 int i; 1331 fprintf( cfile, "\n" ); 1332 for ( i=0; i<depth; i++ ) { 1333 fprintf( cfile, " " ); 1334 } 1335 fprintf( cfile, "<![CDATA[" ); 1336 fprintf( cfile, "%s", value.c_str() ); // unformatted output 1337 fprintf( cfile, "]]>\n" ); 1338 } 1339 else 1340 { 1341 TIXML_STRING buffer; 1342 PutString( value, &buffer ); 1343 fprintf( cfile, "%s", buffer.c_str() ); 1344 } 1213 1345 } 1214 1346 … … 1216 1348 void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const 1217 1349 { 1218 PutString( value, stream ); 1350 if ( cdata ) 1351 { 1352 (*stream) << "<![CDATA[" << value << "]]>"; 1353 } 1354 else 1355 { 1356 PutString( value, stream ); 1357 } 1219 1358 } 1220 1359 … … 1223 1362 { 1224 1363 TiXmlNode::CopyTo( target ); 1364 target->cdata = cdata; 1225 1365 } 1226 1366 -
trunk/src/lib/tinyxml/tinyxml.h
r4491 r5819 28 28 29 29 #ifdef _MSC_VER 30 #pragma warning( push ) 30 31 #pragma warning( disable : 4530 ) 31 32 #pragma warning( disable : 4786 ) … … 62 63 #endif 63 64 65 // Deprecated library function hell. Compilers want to use the 66 // new safe versions. This probably doesn't fully address the problem, 67 // but it gets closer. There are too many compilers for me to fully 68 // test. If you get compilation troubles, undefine TIXML_SAFE 69 70 #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress. 71 #ifdef TIXML_SAFE 72 #if defined(_MSC_VER) && (_MSC_VER >= 1200 ) 73 // Microsoft visual studio, version 6 and higher. 74 //#pragma message( "Using _sn* functions." ) 75 #define TIXML_SNPRINTF _snprintf 76 #define TIXML_SNSCANF _snscanf 77 #elif defined(__GNUC__) && (__GNUC__ >= 3 ) 78 // GCC version 3 and higher.s 79 //#warning( "Using sn* functions." ) 80 #define TIXML_SNPRINTF snprintf 81 #define TIXML_SNSCANF snscanf 82 #endif 83 #endif 84 64 85 class TiXmlDocument; 65 86 class TiXmlElement; … … 72 93 73 94 const int TIXML_MAJOR_VERSION = 2; 74 const int TIXML_MINOR_VERSION = 3;75 const int TIXML_PATCH_VERSION = 4;95 const int TIXML_MINOR_VERSION = 4; 96 const int TIXML_PATCH_VERSION = 2; 76 97 77 98 /* Internal structure for tracking location of items … … 206 227 TIXML_ERROR_DOCUMENT_EMPTY, 207 228 TIXML_ERROR_EMBEDDED_NULL, 229 TIXML_ERROR_PARSING_CDATA, 208 230 209 231 TIXML_ERROR_STRING_COUNT … … 278 300 else if ( *length ) 279 301 { 280 strncpy( _value, p, *length ); 302 //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), 303 // and the null terminator isn't needed 304 for( int i=0; p[i] && i<*length; ++i ) { 305 _value[i] = p[i]; 306 } 281 307 return p + (*length); 282 308 } … … 296 322 // Return true if the next characters in the stream are any of the endTag sequences. 297 323 // Ignore case only works for english, and should only be relied on when comparing 298 // to Eng ilish words: StringEqual( p, "version", true ) is fine.324 // to English words: StringEqual( p, "version", true ) is fine. 299 325 static bool StringEqual( const char* p, 300 326 const char* endTag, … … 421 447 The subclasses will wrap this function. 422 448 */ 423 const char * Value() const { return value.c_str (); } 449 const char *Value() const { return value.c_str (); } 450 451 #ifdef TIXML_USE_STL 452 /** Return Value() as a std::string. If you only use STL, 453 this is more efficient than calling Value(). 454 Only available in STL mode. 455 */ 456 const std::string& ValueStr() const { return value; } 457 #endif 424 458 425 459 /** Changes the value of the node. Defined as: … … 589 623 UNKNOWN, TEXT, and DECLARATION. 590 624 */ 591 virtualint Type() const { return type; }625 int Type() const { return type; } 592 626 593 627 /** Return a pointer to the Document this node lives in. … … 633 667 // Figure out what is at *p, and parse it. Returns null if it is not an xml node. 634 668 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); 635 636 // Internal Value function returning a TIXML_STRING637 const TIXML_STRING& SValue() const { return value ; }638 669 639 670 TiXmlNode* parent; … … 695 726 const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. 696 727 const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. 697 const intIntValue() const; ///< Return the value of this attribute, converted to an integer.698 const doubleDoubleValue() const; ///< Return the value of this attribute, converted to a double.728 int IntValue() const; ///< Return the value of this attribute, converted to an integer. 729 double DoubleValue() const; ///< Return the value of this attribute, converted to a double. 699 730 700 731 /** QueryIntValue examines the value string. It is an alternative to the … … 707 738 which is the opposite of almost all other TinyXml calls. 708 739 */ 709 int QueryIntValue( int* value ) const;740 int QueryIntValue( int* _value ) const; 710 741 /// QueryDoubleValue examines the value string. See QueryIntValue(). 711 int QueryDoubleValue( double* value ) const;742 int QueryDoubleValue( double* _value ) const; 712 743 713 744 void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. 714 745 void SetValue( const char* _value ) { value = _value; } ///< Set the value. 715 746 716 void SetIntValue( int value ); ///< Set the value from an integer.717 void SetDoubleValue( double value ); ///< Set the value from a double.747 void SetIntValue( int _value ); ///< Set the value from an integer. 748 void SetDoubleValue( double _value ); ///< Set the value from a double. 718 749 719 750 #ifdef TIXML_USE_STL … … 856 887 does not exist, then TIXML_NO_ATTRIBUTE is returned. 857 888 */ 858 int QueryIntAttribute( const char* name, int* value ) const;889 int QueryIntAttribute( const char* name, int* _value ) const; 859 890 /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). 860 int QueryDoubleAttribute( const char* name, double* value ) const;891 int QueryDoubleAttribute( const char* name, double* _value ) const; 861 892 /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). 862 int Query DoubleAttribute( const char* name, float*value ) const {893 int QueryFloatAttribute( const char* name, float* _value ) const { 863 894 double d; 864 895 int result = QueryDoubleAttribute( name, &d ); 865 *value = (float)d; 896 if ( result == TIXML_SUCCESS ) { 897 *_value = (float)d; 898 } 866 899 return result; 867 900 } … … 870 903 will be created if it does not exist, or changed if it does. 871 904 */ 872 void SetAttribute( const char* name, const char * value );905 void SetAttribute( const char* name, const char * _value ); 873 906 874 907 #ifdef TIXML_USE_STL … … 876 909 const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } 877 910 const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); } 878 int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(),value ); }879 int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(),value ); }911 int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); } 912 int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); } 880 913 881 914 /// STL std::string form. … … 918 951 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } 919 952 953 /** Convenience function for easy access to the text inside an element. Although easy 954 and concise, GetText() is limited compared to getting the TiXmlText child 955 and accessing it directly. 956 957 If the first child of 'this' is a TiXmlText, the GetText() 958 returns the character string of the Text node, else null is returned. 959 960 This is a convenient method for getting the text of simple contained text: 961 @verbatim 962 <foo>This is text</foo> 963 const char* str = fooElement->GetText(); 964 @endverbatim 965 966 'str' will be a pointer to "This is text". 967 968 Note that this function can be misleading. If the element foo was created from 969 this XML: 970 @verbatim 971 <foo><b>This is text</b></foo> 972 @endverbatim 973 974 then the value of str would be null. The first child node isn't a text node, it is 975 another element. From this XML: 976 @verbatim 977 <foo>This is <b>text</b></foo> 978 @endverbatim 979 GetText() will return "This is ". 980 981 WARNING: GetText() accesses a child node - don't become confused with the 982 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 safe type casts on the referenced node. 984 */ 985 const char* GetText() const; 986 920 987 /// Creates a new Element and returns it - the returned element is a copy. 921 988 virtual TiXmlNode* Clone() const; … … 987 1054 988 1055 989 /** XML text. Contained in an element. 1056 /** XML text. A text node can have 2 ways to output the next. "normal" output 1057 and CDATA. It will default to the mode it was parsed from the XML file and 1058 you generally want to leave it alone, but you can change the output mode with 1059 SetCDATA() and query it with CDATA(). 990 1060 */ 991 1061 class TiXmlText : public TiXmlNode … … 993 1063 friend class TiXmlElement; 994 1064 public: 995 /// Constructor. 996 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT) 1065 /** Constructor for text element. By default, it is treated as 1066 normal, encoded text. If you want it be output as a CDATA text 1067 element, set the parameter _cdata to 'true' 1068 */ 1069 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT) 997 1070 { 998 1071 SetValue( initValue ); 1072 cdata = false; 999 1073 } 1000 1074 virtual ~TiXmlText() {} … … 1005 1079 { 1006 1080 SetValue( initValue ); 1081 cdata = false; 1007 1082 } 1008 1083 #endif … … 1013 1088 /// Write this text object to a FILE stream. 1014 1089 virtual void Print( FILE* cfile, int depth ) const; 1090 1091 /// Queries whether this represents text using a CDATA section. 1092 bool CDATA() { return cdata; } 1093 /// Turns on or off a CDATA representation of text. 1094 void SetCDATA( bool _cdata ) { cdata = _cdata; } 1015 1095 1016 1096 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); … … 1029 1109 1030 1110 private: 1111 bool cdata; // true if this should be input and output as a CDATA style text element 1031 1112 }; 1032 1113 … … 1207 1288 prefer the ErrorId, this function will fetch it. 1208 1289 */ 1209 constint ErrorId() const { return errorId; }1290 int ErrorId() const { return errorId; } 1210 1291 1211 1292 /** Returns the location (if known) of the error. The first column is column 1, … … 1219 1300 int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() 1220 1301 1221 /** By calling this method, with a tab size 1302 /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) 1303 to report the correct values for row and column. It does not change the output 1304 or input in any way. 1305 1306 By calling this method, with a tab size 1222 1307 greater than 0, the row and column of each node and attribute is stored 1223 1308 when the file is loaded. Very useful for tracking the DOM back in to … … 1277 1362 int tabsize; 1278 1363 TiXmlCursor errorLocation; 1364 bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. 1279 1365 }; 1280 1366 … … 1364 1450 public: 1365 1451 /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. 1366 TiXmlHandle( TiXmlNode* node ) { this->node =node; }1452 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } 1367 1453 /// Copy constructor 1368 1454 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } … … 1419 1505 1420 1506 #ifdef _MSC_VER 1421 #pragma warning( default : 4530 ) 1422 #pragma warning( default : 4786 ) 1507 #pragma warning( pop ) 1423 1508 #endif 1424 1509 -
trunk/src/lib/tinyxml/tinyxmlerror.cc
r4261 r5819 27 27 // The goal of the seperate error file is to make the first 28 28 // step towards localization. tinyxml (currently) only supports 29 // latin-1, but at least the error messagescould now be translated.29 // english error messages, but the could now be translated. 30 30 // 31 31 // It also cleans up the code a bit. … … 49 49 "Error document empty.", 50 50 "Error null (0) or unexpected EOF found in input stream.", 51 "Error parsing CDATA.", 51 52 }; -
trunk/src/lib/tinyxml/tinyxmlparser.cc
r4491 r5819 718 718 { 719 719 encoding = TIXML_ENCODING_UTF8; 720 useMicrosoftBOM = true; 720 721 } 721 722 } … … 786 787 if ( pError && data ) 787 788 { 788 //TiXmlParsingData data( pError, prevData );789 789 data->Stamp( pError, encoding ); 790 790 errorLocation = data->Cursor(); … … 821 821 const char* commentHeader = { "<!--" }; 822 822 const char* dtdHeader = { "<!" }; 823 const char* cdataHeader = { "<![CDATA[" }; 823 824 824 825 if ( StringEqual( p, xmlHeader, true, encoding ) ) … … 835 836 #endif 836 837 returnNode = new TiXmlComment(); 838 } 839 else if ( StringEqual( p, cdataHeader, false, encoding ) ) 840 { 841 #ifdef DEBUG_PARSER 842 TIXML_LOG( "XML parsing CDATA\n" ); 843 #endif 844 TiXmlText* text = new TiXmlText( "" ); 845 text->SetCDATA( true ); 846 returnNode = text; 837 847 } 838 848 else if ( StringEqual( p, dtdHeader, false, encoding ) ) … … 931 941 if ( !in->good() ) return; 932 942 assert( in->peek() == '<' ); 933 int tagIndex = tag->length();943 int tagIndex = (int) tag->length(); 934 944 935 945 bool closingTag = false; … … 1013 1023 } 1014 1024 1015 // TiXmlParsingData data( p, prevData );1016 1025 if ( data ) 1017 1026 { … … 1127 1136 TiXmlDocument* document = GetDocument(); 1128 1137 1138 // Read in text and elements in any order. 1129 1139 const char* pWithWhiteSpace = p; 1130 // Read in text and elements in any order.1131 1140 p = SkipWhiteSpace( p, encoding ); 1141 1132 1142 while ( p && *p ) 1133 1143 { … … 1162 1172 { 1163 1173 // We hit a '<' 1164 // Have we hit a new element or an end tag? 1174 // Have we hit a new element or an end tag? This could also be 1175 // a TiXmlText in the "CDATA" style. 1165 1176 if ( StringEqual( p, "</", false, encoding ) ) 1166 1177 { … … 1181 1192 } 1182 1193 } 1194 pWithWhiteSpace = p; 1183 1195 p = SkipWhiteSpace( p, encoding ); 1184 1196 } … … 1222 1234 p = SkipWhiteSpace( p, encoding ); 1223 1235 1224 // TiXmlParsingData data( p, prevData );1225 1236 if ( data ) 1226 1237 { … … 1286 1297 p = SkipWhiteSpace( p, encoding ); 1287 1298 1288 // TiXmlParsingData data( p, prevData );1289 1299 if ( data ) 1290 1300 { … … 1315 1325 tabsize = document->TabSize(); 1316 1326 1317 // TiXmlParsingData data( p, prevData );1318 1327 if ( data ) 1319 1328 { … … 1378 1387 void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) 1379 1388 { 1380 while ( in->good() ) 1381 { 1382 int c = in->peek(); 1383 if ( c == '<' ) 1384 return; 1389 if ( cdata ) 1390 { 1391 int c = in->get(); 1385 1392 if ( c <= 0 ) 1386 1393 { … … 1392 1399 1393 1400 (*tag) += (char) c; 1394 in->get(); 1401 1402 if ( c == '>' 1403 && tag->at( tag->length() - 2 ) == ']' 1404 && tag->at( tag->length() - 3 ) == ']' ) 1405 { 1406 // All is well. 1407 return; 1408 } 1409 } 1410 else 1411 { 1412 while ( in->good() ) 1413 { 1414 int c = in->peek(); 1415 if ( c == '<' ) 1416 return; 1417 if ( c <= 0 ) 1418 { 1419 TiXmlDocument* document = GetDocument(); 1420 if ( document ) 1421 document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); 1422 return; 1423 } 1424 1425 (*tag) += (char) c; 1426 in->get(); 1427 } 1395 1428 } 1396 1429 } … … 1400 1433 { 1401 1434 value = ""; 1402 // TiXmlParsingData data( p, prevData ); 1435 TiXmlDocument* document = GetDocument(); 1436 1403 1437 if ( data ) 1404 1438 { … … 1406 1440 location = data->Cursor(); 1407 1441 } 1408 bool ignoreWhite = true; 1409 1410 const char* end = "<"; 1411 p = ReadText( p, &value, ignoreWhite, end, false, encoding ); 1412 if ( p ) 1413 return p-1; // don't truncate the '<' 1414 return 0; 1442 1443 const char* const startTag = "<![CDATA["; 1444 const char* const endTag = "]]>"; 1445 1446 if ( cdata || StringEqual( p, startTag, false, encoding ) ) 1447 { 1448 cdata = true; 1449 1450 if ( !StringEqual( p, startTag, false, encoding ) ) 1451 { 1452 document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); 1453 return 0; 1454 } 1455 p += strlen( startTag ); 1456 1457 // Keep all the white space, ignore the encoding, etc. 1458 while ( p && *p 1459 && !StringEqual( p, endTag, false, encoding ) 1460 ) 1461 { 1462 value += *p; 1463 ++p; 1464 } 1465 1466 TIXML_STRING dummy; 1467 p = ReadText( p, &dummy, false, endTag, false, encoding ); 1468 return p; 1469 } 1470 else 1471 { 1472 bool ignoreWhite = true; 1473 1474 const char* end = "<"; 1475 p = ReadText( p, &value, ignoreWhite, end, false, encoding ); 1476 if ( p ) 1477 return p-1; // don't truncate the '<' 1478 return 0; 1479 } 1415 1480 } 1416 1481 … … 1450 1515 return 0; 1451 1516 } 1452 // TiXmlParsingData data( p, prevData );1453 1517 if ( data ) 1454 1518 { -
trunk/src/orxonox.cc
r5788 r5819 27 27 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ORXONOX 28 28 #include "orxonox.h" 29 30 #include "globals.h" 29 31 30 32 #include "gui.h" -
trunk/src/story_entities/world.cc
r5769 r5819 1042 1042 } 1043 1043 1044 1045 1046 /**1047 \brief commands that the world must catch1048 @returns false if not used by the world1049 */1050 bool World::command(Command* cmd)1051 {1052 if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW0)) this->localCamera->setViewMode(VIEW_NORMAL);1053 else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW1)) this->localCamera->setViewMode(VIEW_BEHIND);1054 else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW2)) this->localCamera->setViewMode(VIEW_FRONT);1055 else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW3)) this->localCamera->setViewMode(VIEW_LEFT);1056 else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT);1057 else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP);1058 return false;1059 }1060 1061 1044 void World::setPath( const char* name) 1062 1045 { -
trunk/src/subprojects/collision_detection/collision_detection.cc
r5486 r5819 81 81 // a = new TestEntity(); a->setName("Clown1"); 82 82 b = new CollisionTestEntity(); b->setName("Jaeger"); 83 if (argc > 1) 84 { 85 printf("Loading model %s\n", argv[1]); 86 b->loadModel(argv[1]); 87 } 83 88 // a = new Terrain(); 84 89 -
trunk/src/subprojects/framework.cc
r5485 r5819 80 80 float dt = framework->tick(); 81 81 82 NullParent::getInstance()->update (dt);82 NullParent::getInstance()->updateNode(dt); 83 83 84 84 // Draw the scene -
trunk/src/util/loading/game_loader.cc
r5553 r5819 357 357 } 358 358 359 PRINTF(2)("Fabricate failed, Ti XmlElement did not contain a value\n");359 PRINTF(2)("Fabricate failed, TiElement did not contain a value\n"); 360 360 361 361 return NULL; -
trunk/src/util/loading/game_loader.h
r5139 r5819 12 12 #include "event_listener.h" 13 13 14 #include "error.h" 14 15 15 16 //----------------------------------------------------------------------------- -
trunk/src/world_entities/weapons/aiming_turret.cc
r5769 r5819 49 49 50 50 this->setActionSound(WA_SHOOT, "sound/shot1.wav"); 51 this->setActionSound(WA_ACTIVATE, "sound/vo cals/missiles.wav");51 this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav"); 52 52 this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); 53 53 } -
trunk/src/world_entities/weapons/cannon.cc
r5750 r5819 87 87 //this->minCharge = 2; 88 88 89 this->setActionSound(WA_SHOOT, "sound/shot1.wav"); 89 this->setActionSound(WA_SHOOT, "sound/explo.wav"); 90 this->setActionSound(WA_ACTIVATE, "sound/voices/cannon.wav"); 90 91 91 92 this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); -
trunk/src/world_entities/weapons/ground_turret.cc
r5795 r5819 81 81 * @todo: make the class Loadable 82 82 */ 83 // LoadParamXML(root, "Weapons", this, GroundTurret, loadWeapon); 83 const TiXmlElement* element; 84 85 element = root->FirstChildElement("weapon-left"); 86 if (element != NULL) element = element->FirstChildElement(); 87 this->left = dynamic_cast<Weapon*>( Factory::getFirst()->fabricate( element) ); 88 if (this->left) 89 { 90 this->left->setParent(this); 91 this->left->setRelCoor(0,10,-5); 92 } 93 94 element = root->FirstChildElement("weapon-right"); 95 if (element != NULL) if (element != NULL) element = element->FirstChildElement(); 96 this->right = dynamic_cast<Weapon*>( Factory::getFirst()->fabricate( element) ); 97 if (this->right) 98 { 99 this->right->setParent(this); 100 this->right->setRelCoor(0,10,5); 101 } 84 102 } 85 86 103 87 104 /** … … 113 130 if (this->model) 114 131 this->model->draw(); 115 if (left != NULL) 132 133 glPopMatrix(); 134 if (this->left != NULL) 116 135 this->left->draw(); 117 136 if (this->right != NULL) 118 137 this->right->draw(); 119 120 glPopMatrix();121 138 } 122 139 -
trunk/src/world_entities/weapons/ground_turret.h
r5795 r5819 22 22 void loadParams(const TiXmlElement* root); 23 23 24 void loadWeapons(const TiXmlElement* root);25 26 24 virtual void postSpawn (); 27 25 virtual void leftWorld (); -
trunk/src/world_entities/weapons/rocket.cc
r5779 r5819 46 46 this->energyMin = 1; 47 47 this->energyMax = 10; 48 this->lifeSpan = 2;48 this->lifeSpan = 5; 49 49 50 50 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); -
trunk/src/world_entities/weapons/test_gun.cc
r5750 r5819 131 131 //this->minCharge = 2; 132 132 133 this->setActionSound(WA_SHOOT, "sound/shot1.wav"); 133 this->setActionSound(WA_SHOOT, "sound/laser.wav"); 134 this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); 135 134 136 135 137 this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); -
trunk/src/world_entities/weapons/turret.cc
r5766 r5819 44 44 this->init(); 45 45 46 this->loadModel("models/guns/turret1.obj");47 48 49 46 this->setActionSound(WA_SHOOT, "sound/shot1.wav"); 50 47 this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav"); 51 48 this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); 49 50 this->loadModel("models/guns/turret1.obj"); 52 51 } 53 52 … … 72 71 { 73 72 this->setClassID(CL_TURRET, "Turret"); 73 74 74 75 75 Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); … … 136 136 return; 137 137 138 pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)138 pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */ 139 139 /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); 140 140 141 141 142 142 pj->setParent(NullParent::getInstance()); … … 154 154 void Turret::draw () const 155 155 { 156 /* draw gun body */ 157 glMatrixMode(GL_MODELVIEW); 158 glPushMatrix(); 159 glTranslatef (this->getAbsCoor ().x, 160 this->getAbsCoor ().y, 161 this->getAbsCoor ().z); 162 Vector tmpRot = this->getAbsDir().getSpacialAxis(); 163 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 156 if (this->model != NULL) 157 { 158 /* draw gun body */ 159 glMatrixMode(GL_MODELVIEW); 160 glPushMatrix(); 161 glTranslatef (this->getAbsCoor ().x, 162 this->getAbsCoor ().y, 163 this->getAbsCoor ().z); 164 Vector tmpRot = this->getAbsDir().getSpacialAxis(); 165 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 164 166 165 this->model->draw(); 166 glPopMatrix(); 167 this->model->draw(); 168 glPopMatrix(); 169 } 167 170 } 168
Note: See TracChangeset
for help on using the changeset viewer.