- Timestamp:
- Mar 9, 2006, 5:28:10 PM (19 years ago)
- Location:
- branches/std/src
- Files:
-
- 60 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/Makefile.am
r7193 r7203 55 55 56 56 SUBDIRS = \ 57 . \ 57 58 math \ 58 59 graphics \ … … 65 66 parser \ 66 67 shell \ 67 gui \ 68 . 68 gui -
branches/std/src/lib/event/key_mapper.cc
r6998 r7203 129 129 * @param filename: The path and name of the file to load the bindings from 130 130 */ 131 void KeyMapper::loadKeyBindings (const char*fileName)131 void KeyMapper::loadKeyBindings (const std::string& fileName) 132 132 { 133 133 IniParser parser(fileName); … … 145 145 146 146 iniParser->firstVar(); 147 while(iniParser->getCurrentName() )147 while(iniParser->getCurrentName() != "") 148 148 { 149 149 PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); … … 164 164 165 165 iniParser->firstVar(); 166 while(iniParser->getCurrentName() )166 while(iniParser->getCurrentName() != "") 167 167 { 168 168 PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); … … 177 177 * @param the name of the button 178 178 */ 179 int* KeyMapper::nameToIndex (const char*name)179 int* KeyMapper::nameToIndex (const std::string& name) 180 180 { 181 181 coord[0] = -1; … … 199 199 * @param id of the key 200 200 */ 201 void KeyMapper::mapKeys(const char*name, int* index)201 void KeyMapper::mapKeys(const std::string& name, int* index) 202 202 { 203 203 for( int i = 0; map[i].pValue != NULL; ++i ) 204 204 { 205 if( !strcmp (name, map[i].pName))205 if( name == map[i].pName) 206 206 { 207 207 if( index[0] == 0) -
branches/std/src/lib/event/key_mapper.h
r6998 r7203 29 29 virtual ~KeyMapper(); 30 30 31 void loadKeyBindings(const char*fileName = NULL);31 void loadKeyBindings(const std::string& fileName = NULL); 32 32 void loadKeyBindings(IniParser* iniParser); 33 33 … … 35 35 36 36 private: 37 int* nameToIndex (const char*name);38 void mapKeys(const char*name, int* index);37 int* nameToIndex (const std::string& name); 38 void mapKeys(const std::string& name, int* index); 39 39 40 40 public: -
branches/std/src/lib/event/key_names.cc
r5476 r7203 23 23 using namespace std; 24 24 25 int buttonnameToSDLB(const char*name)25 int buttonnameToSDLB(const std::string& name) 26 26 { 27 if( !strcmp (name,"BUTTON_LEFT")) return EV_MOUSE_BUTTON_LEFT;28 if( !strcmp (name,"BUTTON_MIDDLE")) return EV_MOUSE_BUTTON_MIDDLE;29 if( !strcmp (name,"BUTTON_RIGHT")) return EV_MOUSE_BUTTON_RIGHT;30 if( !strcmp (name,"BUTTON_WHEELUP")) return EV_MOUSE_BUTTON_WHEELUP;31 if( !strcmp (name,"BUTTON_WHEELDOWN")) return EV_MOUSE_BUTTON_WHEELDOWN;27 if((name == "BUTTON_LEFT")) return EV_MOUSE_BUTTON_LEFT; 28 if((name == "BUTTON_MIDDLE")) return EV_MOUSE_BUTTON_MIDDLE; 29 if((name == "BUTTON_RIGHT")) return EV_MOUSE_BUTTON_RIGHT; 30 if((name == "BUTTON_WHEELUP")) return EV_MOUSE_BUTTON_WHEELUP; 31 if((name == "BUTTON_WHEELDOWN")) return EV_MOUSE_BUTTON_WHEELDOWN; 32 32 return -1; 33 33 } … … 43 43 } 44 44 45 int keynameToSDLK(const char*name)45 int keynameToSDLK(const std::string& name) 46 46 { 47 if( !strcmp (name,"BACKSPACE")) return SDLK_BACKSPACE;48 if( !strcmp (name,"TAB")) return SDLK_TAB;49 if( !strcmp (name,"CLEAR")) return SDLK_CLEAR;50 if( !strcmp (name,"RETURN")) return SDLK_RETURN;51 if( !strcmp (name,"ESCAPE")) return SDLK_ESCAPE;52 if( !strcmp (name,"SPACE")) return SDLK_SPACE;53 if( !strcmp (name,"EXCLAIM")) return SDLK_EXCLAIM;54 if( !strcmp (name,"QUOTEDBL")) return SDLK_QUOTEDBL;55 if( !strcmp (name,"HASH")) return SDLK_HASH;56 if( !strcmp (name,"PAUSE")) return SDLK_PAUSE;57 if( !strcmp (name,"DOLLAR")) return SDLK_DOLLAR;58 if( !strcmp (name,"AMPERSAND")) return SDLK_AMPERSAND;59 if( !strcmp (name,"QUOTE")) return SDLK_QUOTE;60 if( !strcmp (name,"LEFTPAREN")) return SDLK_LEFTPAREN;61 if( !strcmp (name,"RIGHTPAREN")) return SDLK_RIGHTPAREN;62 if( !strcmp (name,"ASTERISK")) return SDLK_ASTERISK;63 if( !strcmp (name,"PLUS")) return SDLK_PLUS;64 if( !strcmp (name,"COMMA")) return SDLK_COMMA;65 if( !strcmp (name,"MINUS")) return SDLK_MINUS;66 if( !strcmp (name,"PERIOD")) return SDLK_PERIOD;67 if( !strcmp (name,"SLASH")) return SDLK_SLASH;68 if( !strcmp (name,"0")) return SDLK_0;69 if( !strcmp (name,"1")) return SDLK_1;70 if( !strcmp (name,"2")) return SDLK_2;71 if( !strcmp (name,"3")) return SDLK_3;72 if( !strcmp (name,"4")) return SDLK_4;73 if( !strcmp (name,"5")) return SDLK_5;74 if( !strcmp (name,"6")) return SDLK_6;75 if( !strcmp (name,"7")) return SDLK_7;76 if( !strcmp (name,"8")) return SDLK_8;77 if( !strcmp (name,"9")) return SDLK_9;78 if( !strcmp (name,"COLON")) return SDLK_COLON;79 if( !strcmp (name,"SEMICOLON")) return SDLK_SEMICOLON;80 if( !strcmp (name,"LESS")) return SDLK_LESS;81 if( !strcmp (name,"EQUALS")) return SDLK_EQUALS;82 if( !strcmp (name,"GREATER")) return SDLK_GREATER;83 if( !strcmp (name,"QUESTION")) return SDLK_QUESTION;84 if( !strcmp (name,"AT")) return SDLK_AT;85 if( !strcmp (name,"LEFTBRACKET")) return SDLK_LEFTBRACKET;86 if( !strcmp (name,"BACKSLASH")) return SDLK_BACKSLASH;87 if( !strcmp (name,"RIGHTBRACKET")) return SDLK_RIGHTBRACKET;88 if( !strcmp (name,"CARET")) return SDLK_CARET;89 if( !strcmp (name,"UNDERSCORE")) return SDLK_UNDERSCORE;90 if( !strcmp (name,"BACKQUOTE")) return SDLK_BACKQUOTE;91 if( !strcmp (name,"a")) return SDLK_a;92 if( !strcmp (name,"b")) return SDLK_b;93 if( !strcmp (name,"c")) return SDLK_c;94 if( !strcmp (name,"d")) return SDLK_d;95 if( !strcmp (name,"e")) return SDLK_e;96 if( !strcmp (name,"f")) return SDLK_f;97 if( !strcmp (name,"g")) return SDLK_g;98 if( !strcmp (name,"h")) return SDLK_h;99 if( !strcmp (name,"i")) return SDLK_i;100 if( !strcmp (name,"j")) return SDLK_j;101 if( !strcmp (name,"k")) return SDLK_k;102 if( !strcmp (name,"l")) return SDLK_l;103 if( !strcmp (name,"m")) return SDLK_m;104 if( !strcmp (name,"n")) return SDLK_n;105 if( !strcmp (name,"o")) return SDLK_o;106 if( !strcmp (name,"p")) return SDLK_p;107 if( !strcmp (name,"q")) return SDLK_q;108 if( !strcmp (name,"r")) return SDLK_r;109 if( !strcmp (name,"s")) return SDLK_s;110 if( !strcmp (name,"t")) return SDLK_t;111 if( !strcmp (name,"u")) return SDLK_u;112 if( !strcmp (name,"v")) return SDLK_v;113 if( !strcmp (name,"w")) return SDLK_w;114 if( !strcmp (name,"x")) return SDLK_x;115 if( !strcmp (name,"y")) return SDLK_y;116 if( !strcmp (name,"z")) return SDLK_z;117 if( !strcmp (name,"DELETE")) return SDLK_DELETE;118 if( !strcmp (name,"KP0")) return SDLK_KP0;119 if( !strcmp (name,"KP1")) return SDLK_KP1;120 if( !strcmp (name,"KP2")) return SDLK_KP2;121 if( !strcmp (name,"KP3")) return SDLK_KP3;122 if( !strcmp (name,"KP4")) return SDLK_KP4;123 if( !strcmp (name,"KP5")) return SDLK_KP5;124 if( !strcmp (name,"KP6")) return SDLK_KP6;125 if( !strcmp (name,"KP7")) return SDLK_KP7;126 if( !strcmp (name,"KP8")) return SDLK_KP8;127 if( !strcmp (name,"KP9")) return SDLK_KP9;128 if( !strcmp (name,"KP_PERIOD")) return SDLK_KP_PERIOD;129 if( !strcmp (name,"KP_DIVIDE")) return SDLK_KP_DIVIDE;130 if( !strcmp (name,"KP_MULTIPLY")) return SDLK_KP_MULTIPLY;131 if( !strcmp (name,"KP_MINUS")) return SDLK_KP_MINUS;132 if( !strcmp (name,"KP_PLUS")) return SDLK_KP_PLUS;133 if( !strcmp (name,"KP_ENTER")) return SDLK_KP_ENTER;134 if( !strcmp (name,"KP_EQUALS")) return SDLK_KP_EQUALS;135 if( !strcmp (name,"UP")) return SDLK_UP;136 if( !strcmp (name,"DOWN")) return SDLK_DOWN;137 if( !strcmp (name,"RIGHT")) return SDLK_RIGHT;138 if( !strcmp (name,"LEFT")) return SDLK_LEFT;139 if( !strcmp (name,"INSERT")) return SDLK_INSERT;140 if( !strcmp (name,"HOME")) return SDLK_HOME;141 if( !strcmp (name,"END")) return SDLK_END;142 if( !strcmp (name,"PAGEUP")) return SDLK_PAGEUP;143 if( !strcmp (name,"PAGEDOWN")) return SDLK_PAGEDOWN;144 if( !strcmp (name,"F1")) return SDLK_F1;145 if( !strcmp (name,"F2")) return SDLK_F2;146 if( !strcmp (name,"F3")) return SDLK_F3;147 if( !strcmp (name,"F4")) return SDLK_F4;148 if( !strcmp (name,"F5")) return SDLK_F5;149 if( !strcmp (name,"F6")) return SDLK_F6;150 if( !strcmp (name,"F7")) return SDLK_F7;151 if( !strcmp (name,"F8")) return SDLK_F8;152 if( !strcmp (name,"F9")) return SDLK_F9;153 if( !strcmp (name,"F10")) return SDLK_F10;154 if( !strcmp (name,"F11")) return SDLK_F11;155 if( !strcmp (name,"F12")) return SDLK_F12;156 if( !strcmp (name,"F13")) return SDLK_F13;157 if( !strcmp (name,"F14")) return SDLK_F14;158 if( !strcmp (name,"F15")) return SDLK_F15;159 if( !strcmp (name,"NUMLOCK")) return SDLK_NUMLOCK;160 if( !strcmp (name,"CAPSLOCK")) return SDLK_CAPSLOCK;161 if( !strcmp (name,"SCROLLOCK")) return SDLK_SCROLLOCK;162 if( !strcmp (name,"RSHIFT")) return SDLK_RSHIFT;163 if( !strcmp (name,"LSHIFT")) return SDLK_LSHIFT;164 if( !strcmp (name,"RCTRL")) return SDLK_RCTRL;165 if( !strcmp (name,"LCTRL")) return SDLK_LCTRL;166 if( !strcmp (name,"RALT")) return SDLK_RALT;167 if( !strcmp (name,"LALT")) return SDLK_LALT;168 if( !strcmp (name,"RMETA")) return SDLK_RMETA;169 if( !strcmp (name,"LMETA")) return SDLK_LMETA;170 if( !strcmp (name,"LSUPER")) return SDLK_LSUPER;171 if( !strcmp (name,"RSUPER")) return SDLK_RSUPER;172 if( !strcmp (name,"MODE")) return SDLK_MODE;173 if( !strcmp (name,"HELP")) return SDLK_HELP;174 if( !strcmp (name,"PRINT")) return SDLK_PRINT;175 if( !strcmp (name,"SYSREQ")) return SDLK_SYSREQ;176 if( !strcmp (name,"BREAK")) return SDLK_BREAK;177 if( !strcmp (name,"MENU")) return SDLK_MENU;178 if( !strcmp (name,"POWER")) return SDLK_POWER;179 if( !strcmp (name,"EURO")) return SDLK_EURO;47 if((name == "BACKSPACE")) return SDLK_BACKSPACE; 48 if((name == "TAB")) return SDLK_TAB; 49 if((name == "CLEAR")) return SDLK_CLEAR; 50 if((name == "RETURN")) return SDLK_RETURN; 51 if((name == "ESCAPE")) return SDLK_ESCAPE; 52 if((name == "SPACE")) return SDLK_SPACE; 53 if((name == "EXCLAIM")) return SDLK_EXCLAIM; 54 if((name == "QUOTEDBL")) return SDLK_QUOTEDBL; 55 if((name == "HASH")) return SDLK_HASH; 56 if((name == "PAUSE")) return SDLK_PAUSE; 57 if((name == "DOLLAR")) return SDLK_DOLLAR; 58 if((name == "AMPERSAND")) return SDLK_AMPERSAND; 59 if((name == "QUOTE")) return SDLK_QUOTE; 60 if((name == "LEFTPAREN")) return SDLK_LEFTPAREN; 61 if((name == "RIGHTPAREN")) return SDLK_RIGHTPAREN; 62 if((name == "ASTERISK")) return SDLK_ASTERISK; 63 if((name == "PLUS")) return SDLK_PLUS; 64 if((name == "COMMA")) return SDLK_COMMA; 65 if((name == "MINUS")) return SDLK_MINUS; 66 if((name == "PERIOD")) return SDLK_PERIOD; 67 if((name == "SLASH")) return SDLK_SLASH; 68 if((name == "0")) return SDLK_0; 69 if((name == "1")) return SDLK_1; 70 if((name == "2")) return SDLK_2; 71 if((name == "3")) return SDLK_3; 72 if((name == "4")) return SDLK_4; 73 if((name == "5")) return SDLK_5; 74 if((name == "6")) return SDLK_6; 75 if((name == "7")) return SDLK_7; 76 if((name == "8")) return SDLK_8; 77 if((name == "9")) return SDLK_9; 78 if((name == "COLON")) return SDLK_COLON; 79 if((name == "SEMICOLON")) return SDLK_SEMICOLON; 80 if((name == "LESS")) return SDLK_LESS; 81 if((name == "EQUALS")) return SDLK_EQUALS; 82 if((name == "GREATER")) return SDLK_GREATER; 83 if((name == "QUESTION")) return SDLK_QUESTION; 84 if((name == "AT")) return SDLK_AT; 85 if((name == "LEFTBRACKET")) return SDLK_LEFTBRACKET; 86 if((name == "BACKSLASH")) return SDLK_BACKSLASH; 87 if((name == "RIGHTBRACKET")) return SDLK_RIGHTBRACKET; 88 if((name == "CARET")) return SDLK_CARET; 89 if((name == "UNDERSCORE")) return SDLK_UNDERSCORE; 90 if((name == "BACKQUOTE")) return SDLK_BACKQUOTE; 91 if((name == "a")) return SDLK_a; 92 if((name == "b")) return SDLK_b; 93 if((name == "c")) return SDLK_c; 94 if((name == "d")) return SDLK_d; 95 if((name == "e")) return SDLK_e; 96 if((name == "f")) return SDLK_f; 97 if((name == "g")) return SDLK_g; 98 if((name == "h")) return SDLK_h; 99 if((name == "i")) return SDLK_i; 100 if((name == "j")) return SDLK_j; 101 if((name == "k")) return SDLK_k; 102 if((name == "l")) return SDLK_l; 103 if((name == "m")) return SDLK_m; 104 if((name == "n")) return SDLK_n; 105 if((name == "o")) return SDLK_o; 106 if((name == "p")) return SDLK_p; 107 if((name == "q")) return SDLK_q; 108 if((name == "r")) return SDLK_r; 109 if((name == "s")) return SDLK_s; 110 if((name == "t")) return SDLK_t; 111 if((name == "u")) return SDLK_u; 112 if((name == "v")) return SDLK_v; 113 if((name == "w")) return SDLK_w; 114 if((name == "x")) return SDLK_x; 115 if((name == "y")) return SDLK_y; 116 if((name == "z")) return SDLK_z; 117 if((name == "DELETE")) return SDLK_DELETE; 118 if((name == "KP0")) return SDLK_KP0; 119 if((name == "KP1")) return SDLK_KP1; 120 if((name == "KP2")) return SDLK_KP2; 121 if((name == "KP3")) return SDLK_KP3; 122 if((name == "KP4")) return SDLK_KP4; 123 if((name == "KP5")) return SDLK_KP5; 124 if((name == "KP6")) return SDLK_KP6; 125 if((name == "KP7")) return SDLK_KP7; 126 if((name == "KP8")) return SDLK_KP8; 127 if((name == "KP9")) return SDLK_KP9; 128 if((name == "KP_PERIOD")) return SDLK_KP_PERIOD; 129 if((name == "KP_DIVIDE")) return SDLK_KP_DIVIDE; 130 if((name == "KP_MULTIPLY")) return SDLK_KP_MULTIPLY; 131 if((name == "KP_MINUS")) return SDLK_KP_MINUS; 132 if((name == "KP_PLUS")) return SDLK_KP_PLUS; 133 if((name == "KP_ENTER")) return SDLK_KP_ENTER; 134 if((name == "KP_EQUALS")) return SDLK_KP_EQUALS; 135 if((name == "UP")) return SDLK_UP; 136 if((name == "DOWN")) return SDLK_DOWN; 137 if((name == "RIGHT")) return SDLK_RIGHT; 138 if((name == "LEFT")) return SDLK_LEFT; 139 if((name == "INSERT")) return SDLK_INSERT; 140 if((name == "HOME")) return SDLK_HOME; 141 if((name == "END")) return SDLK_END; 142 if((name == "PAGEUP")) return SDLK_PAGEUP; 143 if((name == "PAGEDOWN")) return SDLK_PAGEDOWN; 144 if((name == "F1")) return SDLK_F1; 145 if((name == "F2")) return SDLK_F2; 146 if((name == "F3")) return SDLK_F3; 147 if((name == "F4")) return SDLK_F4; 148 if((name == "F5")) return SDLK_F5; 149 if((name == "F6")) return SDLK_F6; 150 if((name == "F7")) return SDLK_F7; 151 if((name == "F8")) return SDLK_F8; 152 if((name == "F9")) return SDLK_F9; 153 if((name == "F10")) return SDLK_F10; 154 if((name == "F11")) return SDLK_F11; 155 if((name == "F12")) return SDLK_F12; 156 if((name == "F13")) return SDLK_F13; 157 if((name == "F14")) return SDLK_F14; 158 if((name == "F15")) return SDLK_F15; 159 if((name == "NUMLOCK")) return SDLK_NUMLOCK; 160 if((name == "CAPSLOCK")) return SDLK_CAPSLOCK; 161 if((name == "SCROLLOCK")) return SDLK_SCROLLOCK; 162 if((name == "RSHIFT")) return SDLK_RSHIFT; 163 if((name == "LSHIFT")) return SDLK_LSHIFT; 164 if((name == "RCTRL")) return SDLK_RCTRL; 165 if((name == "LCTRL")) return SDLK_LCTRL; 166 if((name == "RALT")) return SDLK_RALT; 167 if((name == "LALT")) return SDLK_LALT; 168 if((name == "RMETA")) return SDLK_RMETA; 169 if((name == "LMETA")) return SDLK_LMETA; 170 if((name == "LSUPER")) return SDLK_LSUPER; 171 if((name == "RSUPER")) return SDLK_RSUPER; 172 if((name == "MODE")) return SDLK_MODE; 173 if((name == "HELP")) return SDLK_HELP; 174 if((name == "PRINT")) return SDLK_PRINT; 175 if((name == "SYSREQ")) return SDLK_SYSREQ; 176 if((name == "BREAK")) return SDLK_BREAK; 177 if((name == "MENU")) return SDLK_MENU; 178 if((name == "POWER")) return SDLK_POWER; 179 if((name == "EURO")) return SDLK_EURO; 180 180 return -1; 181 181 } 182 182 183 const char* SDLKToKeyname( 183 const char* SDLKToKeyname(int key) 184 184 { 185 185 if( key == SDLK_BACKSPACE) return "BACKSPACE"; -
branches/std/src/lib/event/key_names.h
r5474 r7203 1 1 /*! 2 2 * @file keynames.h 3 4 5 6 */3 * Key/button naming functions 4 * 5 * Converts strings to SDLK/SDL_BUTTON values and vice versa 6 */ 7 7 #ifndef _KEY_NAMES_H 8 8 #define _KEY_NAMES_H 9 9 10 /** 11 * converts a button name string to a integer representing the corresponding SDL mouse button identifier 12 * @param name: the name of the mouse button 13 * @return an int containing the SDL identifier of the mouse button or -1 if the button name is not valid 14 */ 15 int buttonnameToSDLB(const char* name); 10 #include <string> 16 11 17 12 /** 18 * converst a SDL mouse button identifier to a name string 19 * @param button: an SDL mouse button identifier 20 * @return a pointer to a string containing the name of the mouse button 21 */ 13 * converts a button name string to a integer representing the corresponding SDL mouse button identifier 14 * @param name: the name of the mouse button 15 * @return an int containing the SDL identifier of the mouse button or -1 if the button name is not valid 16 */ 17 int buttonnameToSDLB(const std::string& name); 18 19 /** 20 * converst a SDL mouse button identifier to a name string 21 * @param button: an SDL mouse button identifier 22 * @return a pointer to a string containing the name of the mouse button 23 */ 22 24 const char* SDLBToButtonname( int button); 23 25 24 26 /** 25 26 27 28 */29 int keynameToSDLK(const char*name);27 * converts a key name string to a integer representing the corresponding SDLK sym 28 * @param name: the name of the key 29 * @return the SDLK sym of the named key or -1 if the key name is not valid 30 */ 31 int keynameToSDLK(const std::string& name); 30 32 31 33 /** 32 33 34 35 */34 * converts an SDLK sym to a name string 35 * @param key: the SDLK sym 36 * @return a pointer to a string containig the name of the key 37 */ 36 38 const char* SDLKToKeyname( int key); 37 39 -
branches/std/src/lib/graphics/graphics_engine.cc
r7193 r7203 169 169 { 170 170 // looking if we are in fullscreen-mode 171 const char*fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");172 if ( strchr(fullscreen, '1') || !strcasecmp(fullscreen, "true"))171 const std::string fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0"); 172 if (fullscreen[0] == '1' || fullscreen == "true") 173 173 this->fullscreenFlag = SDL_FULLSCREEN; 174 174 175 175 // looking if we are in fullscreen-mode 176 const char*textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");177 if ( strchr(textures, '1') || !strcasecmp(textures, "true"))176 const std::string textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0"); 177 if (textures[0] == '1' || textures == "true") 178 178 Texture::setTextureEnableState( true); 179 179 else … … 181 181 182 182 // searching for a usefull resolution 183 SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480") , 'x');183 SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480").c_str(), 'x'); ///FIXME 184 184 //resolution.debug(); 185 185 … … 262 262 * @param icon The name of the Icon on the Disc 263 263 */ 264 void GraphicsEngine::setWindowName(const char* windowName, const char*icon)265 { 266 SDL_Surface* iconSurf = SDL_LoadBMP(icon );264 void GraphicsEngine::setWindowName(const std::string& windowName, const std::string& icon) 265 { 266 SDL_Surface* iconSurf = SDL_LoadBMP(icon.c_str()); 267 267 if (iconSurf != NULL) 268 268 { 269 269 Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0); 270 270 SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey); 271 SDL_WM_SetIcon(iconSurf, NULL);271 SDL_WM_SetIcon(iconSurf, NULL); 272 272 SDL_FreeSurface(iconSurf); 273 273 } 274 274 275 SDL_WM_SetCaption (windowName , icon);275 SDL_WM_SetCaption (windowName.c_str(), icon.c_str()); 276 276 } 277 277 -
branches/std/src/lib/graphics/graphics_engine.h
r6990 r7203 41 41 int initFromIniFile(IniParser* iniParser); 42 42 43 void setWindowName(const char* windowName, const char*icon);43 void setWindowName(const std::string& windowName, const std::string& icon); 44 44 45 45 int setResolution(int width, int height, int bpp); -
branches/std/src/lib/graphics/importer/height_map.cc
r7193 r7203 333 333 } 334 334 335 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel() 335 HeightMap::HeightMap(const std::string& height_map_name = "") 336 : VertexArrayModel() 336 337 { 337 338 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 338 heightMap = IMG_Load(height_map_name );339 heightMap = IMG_Load(height_map_name.c_str()); 339 340 if(heightMap!=NULL) { 340 341 341 PRINTF(0)("loading Image %s\n", height_map_name);342 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 342 343 PRINTF(0)("width : %i\n", heightMap->w); 343 344 PRINTF(0)("height : %i\n", heightMap->h); … … 350 351 } 351 352 352 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);353 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 353 354 354 355 … … 361 362 } 362 363 363 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel() 364 HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL) 365 : VertexArrayModel() 364 366 { 365 367 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 366 368 367 heightMap = IMG_Load(height_map_name );369 heightMap = IMG_Load(height_map_name.c_str()); 368 370 if(heightMap!=NULL) { 369 371 370 PRINTF(0)("loading Image %s\n", height_map_name);372 PRINTF(0)("loading Image %s\n", height_map_name.c_str()); 371 373 PRINTF(0)("width : %i\n", heightMap->w); 372 374 PRINTF(0)("height : %i\n", heightMap->h); … … 379 381 } 380 382 381 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);383 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str()); 382 384 383 385 … … 385 387 386 388 colourMap=NULL; 387 if(colour_map_name != NULL)389 if(colour_map_name != "") 388 390 { 389 colourMap = IMG_Load(colour_map_name);391 colourMap = IMG_Load(colour_map_name.c_str()); 390 392 } 391 393 392 394 if(colourMap != NULL) 393 395 { 394 PRINTF(0)("loading Image %s\n", colour_map_name);396 PRINTF(0)("loading Image %s\n", colour_map_name.c_str()); 395 397 PRINTF(0)("width : %i\n", colourMap->w); 396 398 PRINTF(0)("height : %i\n", colourMap->h); -
branches/std/src/lib/graphics/importer/height_map.h
r6981 r7203 59 59 void load(); 60 60 void load(int Mode); 61 void load(const char*, int Mode);61 void load(const std::string&, int Mode); 62 62 void scale( Vector V); 63 63 void setAbsCoor(Vector V); … … 65 65 float getNormal(float x, float y); 66 66 HeightMap(); 67 HeightMap(const char*);68 HeightMap(const char*, const char*);67 HeightMap(const std::string&); 68 HeightMap(const std::string&, const std::string&); 69 69 virtual ~HeightMap(); 70 70 -
branches/std/src/lib/graphics/importer/material.cc
r7193 r7203 34 34 * @param mtlName Name of the Material to be added to the Material List 35 35 */ 36 Material::Material (const char*mtlName)36 Material::Material (const std::string& mtlName) 37 37 { 38 38 this->setClassID(CL_MATERIAL, "Material"); … … 278 278 * @param pathName The Path to add. 279 279 */ 280 void Material::addTexturePath(const char*pathName)280 void Material::addTexturePath(const std::string& pathName) 281 281 { 282 282 ResourceManager::getInstance()->addImageDir(pathName); … … 289 289 * @param dMap the Name of the Image to Use 290 290 */ 291 void Material::setDiffuseMap(const char*dMap, GLenum target)291 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 292 292 { 293 293 PRINTF(5)("setting Diffuse Map %s\n", dMap); … … 297 297 //! @todo check if RESOURCE MANAGER is availiable 298 298 //! @todo Textures from .mtl-file need special care. 299 if ( dMap != NULL)299 if (!dMap.empty()) 300 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 301 301 else … … 308 308 @todo implement this 309 309 */ 310 void Material::setAmbientMap(const char*aMap, GLenum target)310 void Material::setAmbientMap(const std::string& aMap, GLenum target) 311 311 { 312 312 SDL_Surface* ambientMap; … … 319 319 @todo implement this 320 320 */ 321 void Material::setSpecularMap(const char*sMap, GLenum target)321 void Material::setSpecularMap(const std::string& sMap, GLenum target) 322 322 { 323 323 SDL_Surface* specularMap; … … 330 330 @todo implemet this 331 331 */ 332 void Material::setBump(const char*bump)333 { 334 335 } 332 void Material::setBump(const std::string& bump) 333 { 334 335 } -
branches/std/src/lib/graphics/importer/material.h
r7057 r7203 26 26 { 27 27 public: 28 Material (const char* mtlName = NULL);28 Material (const std::string& mtlName = ""); 29 29 virtual ~Material (); 30 30 … … 49 49 50 50 // MAPPING // 51 void setDiffuseMap(const char*dMap, GLenum target = GL_TEXTURE_2D);52 void setAmbientMap(const char*aMap, GLenum target = GL_TEXTURE_2D);53 void setSpecularMap(const char*sMap, GLenum target = GL_TEXTURE_2D);54 void setBump(const char*bump);51 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D); 52 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 53 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 54 void setBump(const std::string& bump); 55 55 GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; }; 56 56 57 static void addTexturePath(const char*pathName);57 static void addTexturePath(const std::string& pathName); 58 58 59 59 private: -
branches/std/src/lib/graphics/importer/md2Model.cc
r7193 r7203 75 75 \brief simple constructor initializing all variables 76 76 */ 77 MD2Model::MD2Model(const char* modelFileName, const char*skinFileName, float scale)77 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 78 78 { 79 79 this->setClassID(CL_MD2_MODEL, "MD2Model"); … … 352 352 { 353 353 PRINT(0)("\n==========================| MD2Model::debug() |===\n"); 354 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName );355 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName );354 PRINT(0)("= Model FileName:\t%s\n", this->data->fileName.c_str()); 355 PRINT(0)("= Skin FileName:\t%s\n", this->data->skinFileName.c_str()); 356 356 PRINT(0)("= Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size 357 357 PRINT(0)("= Number of Vertices:\t%i\n", this->data->header->numVertices); … … 370 370 \brief simple constructor 371 371 */ 372 MD2Data::MD2Data(const char* modelFileName, const char*skinFileName, float scale)372 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 373 373 { 374 374 scale *= 0.1f; … … 387 387 this->scaleFactor = scale; 388 388 389 this->fileName = NULL;390 this->skinFileName = NULL;389 this->fileName = ""; 390 this->skinFileName = ""; 391 391 this->loadModel(modelFileName); 392 392 this->loadSkin(skinFileName); … … 401 401 MD2Data::~MD2Data() 402 402 { 403 delete [] this->fileName;404 delete [] this->skinFileName;405 403 delete this->header; 406 404 … … 419 417 \return true if success 420 418 */ 421 bool MD2Data::loadModel(const char*fileName)419 bool MD2Data::loadModel(const std::string& fileName) 422 420 { 423 421 FILE *pFile; //file stream … … 428 426 429 427 //! @todo this chek should include deleting a loaded model (eventually) 430 if (fileName == NULL)428 if (fileName.empty()) 431 429 return false; 432 430 433 pFile = fopen(fileName , "rb");431 pFile = fopen(fileName.c_str(), "rb"); 434 432 if( unlikely(!pFile)) 435 433 { … … 442 440 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 443 441 { 444 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName );442 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 445 443 return false; 446 444 } 447 445 448 this->fileName = new char[strlen(fileName)+1]; 449 strcpy(this->fileName, fileName); 446 this->fileName =fileName; 450 447 /* got the data: map it to locals */ 451 448 this->numFrames = this->header->numFrames; … … 507 504 \return true if success 508 505 */ 509 bool MD2Data::loadSkin(const char*fileName)510 { 511 if( fileName == NULL)512 { 513 this->skinFileName = NULL;506 bool MD2Data::loadSkin(const std::string& fileName) 507 { 508 if( fileName.empty()) 509 { 510 this->skinFileName = ""; 514 511 return false; 515 512 } 516 513 517 this->skinFileName = new char[strlen(fileName)+1]; 518 strcpy(this->skinFileName, fileName); 514 this->skinFileName =fileName; 519 515 520 516 this->material.setName("md2ModelMaterial"); -
branches/std/src/lib/graphics/importer/md2Model.h
r7123 r7203 189 189 { 190 190 public: 191 MD2Data(const char* modelFileName, const char*skinFileName, float scale = 1.0f);191 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 192 192 virtual ~MD2Data(); 193 193 194 194 private: 195 bool loadModel(const char*fileName);196 bool loadSkin(const char*fileName = NULL);195 bool loadModel(const std::string& fileName); 196 bool loadSkin(const std::string& fileName = NULL); 197 197 198 198 public: … … 202 202 int numTexCoor; //!< number of texture coordinates 203 203 int numGLCommands; //!< number of gl commands in the glList (tells how to draw) 204 char*fileName; //!< file name of the model File205 char*skinFileName; //!< file name of the skin file204 std::string fileName; //!< file name of the model File 205 std::string skinFileName; //!< file name of the skin file 206 206 MD2Header* header; //!< the header file 207 207 … … 223 223 224 224 public: 225 MD2Model(const char* modelFileName, const char*skinFileName = NULL, float scale = 1.0f);225 MD2Model(const std::string& modelFileName, const std::string& skinFileName = NULL, float scale = 1.0f); 226 226 virtual ~MD2Model(); 227 227 -
branches/std/src/lib/graphics/importer/media_container.cc
r7193 r7203 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );103 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );112 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 113 113 return false; 114 114 } … … 116 116 // Find the first video stream and take it 117 117 video_stream = av_find_default_stream_index(format_context); 118 118 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );121 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 122 122 return false; 123 123 } … … 202 202 // Free the packet that was allocated by av_read_frame 203 203 av_free_packet(&packet); 204 204 205 205 // Did we get a video frame? 206 206 if(frame_finished) … … 216 216 memcpy(&data[i*codec_context->width*3], 217 217 ((AVPicture*)RGB_frame)->data[0]+i * 218 ((AVPicture*)RGB_frame)->linesize[0], 218 ((AVPicture*)RGB_frame)->linesize[0], 219 219 codec_context->width*sizeof(uint8_t)*3); 220 220 … … 258 258 } 259 259 else 260 return NULL;261 } 260 return 0; 261 } -
branches/std/src/lib/graphics/importer/movie_player.cc
r7193 r7203 31 31 32 32 33 MoviePlayer::MoviePlayer(const char*filename)33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object … … 83 83 84 84 85 bool MoviePlayer::loadMovie(const char*filename)85 bool MoviePlayer::loadMovie(const std::string& filename) 86 86 { 87 87 this->unloadMedia(); 88 88 89 if(filename == NULL)89 if(filename.empty()) 90 90 return false; 91 91 // check whether file exists 92 92 if(!ResourceManager::isInDataDir(filename)) 93 93 { 94 PRINTF(1)("Could not find %s\n", filename );94 PRINTF(1)("Could not find %s\n", filename.c_str()); 95 95 return false; 96 96 } … … 100 100 101 101 // Open video file 102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename) , NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename) );102 if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 ) 103 { 104 PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str()); 105 105 return false; 106 106 } … … 109 109 if (av_find_stream_info(format_context) < 0) 110 110 { 111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename) );111 PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str()); 112 112 return false; 113 113 } … … 118 118 if(video_stream == -1) 119 119 { 120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename) );120 PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str()); 121 121 return false; 122 122 } -
branches/std/src/lib/graphics/importer/movie_player.h
r6981 r7203 58 58 public: 59 59 60 MoviePlayer(const char*filename = NULL);60 MoviePlayer(const std::string& filename = NULL); 61 61 virtual ~MoviePlayer(); 62 62 63 bool loadMovie(const char*filename);63 bool loadMovie(const std::string& filename); 64 64 65 65 void start(float start_time); -
branches/std/src/lib/graphics/importer/objModel.cc
r6162 r7203 32 32 * @param scaling The factor that the model will be scaled with. 33 33 */ 34 OBJModel::OBJModel(const char* fileName, float scaling) : StaticModel(fileName) 34 OBJModel::OBJModel(const std::string& fileName, float scaling) 35 : StaticModel(fileName) 35 36 { 36 37 this->setClassID(CL_OBJ_MODEL, "OBJModel"); … … 51 52 */ 52 53 OBJModel::~OBJModel() 53 { 54 PRINTF(4)("Deleting the obj-names\n"); 55 if (this->objPath) 56 delete []this->objPath; 57 } 54 { } 58 55 59 56 /** … … 63 60 Splits the FileName from the DirectoryName 64 61 */ 65 bool OBJModel::importFile (const char* fileName) 66 { 62 bool OBJModel::importFile (const std::string& fileNameInput) 63 { 64 const char* fileName = fileNameInput.c_str(); 67 65 PRINTF(4)("preparing to read in file: %s\n", fileName); 68 66 // splitting the … … 74 72 { 75 73 int len = split - fileName+1; 76 this->objPath = new char[len +2];77 strncpy(this->objPath, fileName, len);74 this->objPath = fileName; 75 this->objPath.erase(len, this->objPath.size()); 78 76 this->objPath[len] = '\0'; 79 77 PRINTF(4)("Resolved file %s to Path %s.\n", fileName, this->objPath); … … 91 89 This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks 92 90 */ 93 bool OBJModel::readFromObjFile(const char*fileName)91 bool OBJModel::readFromObjFile(const std::string& fileName) 94 92 { 95 93 FILE* stream; 96 if( (stream = fopen (fileName , "r")) == NULL)97 { 98 PRINTF(2)("Object File Could not be Opened %s\n", fileName );94 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 95 { 96 PRINTF(2)("Object File Could not be Opened %s\n", fileName.c_str()); 99 97 return false; 100 98 } … … 162 160 * that a material does not have to be able to read itself in from a File. 163 161 */ 164 bool OBJModel::readMtlLib (const char* mtlFile) 165 { 166 char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1]; 167 sprintf(fileName, "%s%s", this->objPath, mtlFile); 162 bool OBJModel::readMtlLib (const std::string& mtlFile) 163 { 164 std::string fileName = this->objPath + mtlFile; 168 165 169 166 FILE* stream; 170 if( (stream = fopen (fileName, "r")) == NULL) 171 { 172 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName); 173 delete[] fileName; 167 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 168 { 169 PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName.c_str()); 174 170 return false; 175 171 } … … 258 254 } 259 255 fclose(stream); 260 delete []fileName;261 256 return true; 262 257 } -
branches/std/src/lib/graphics/importer/objModel.h
r6022 r7203 13 13 { 14 14 public: 15 OBJModel(const char*fileName, float scaling = 1.0);15 OBJModel(const std::string& fileName, float scaling = 1.0); 16 16 virtual ~OBJModel(); 17 17 18 18 private: 19 19 ///// readin ///// 20 bool importFile (const char*fileName);21 bool readFromObjFile (const char*fileName);22 bool readMtlLib (const char*matFile);20 bool importFile (const std::string& fileName); 21 bool readFromObjFile (const std::string& fileName); 22 bool readMtlLib (const std::string& matFile); 23 23 24 24 private: 25 char*objPath; //!< The Path where the obj and mtl-file are located.25 std::string objPath; //!< The Path where the obj and mtl-file are located. 26 26 }; 27 27 -
branches/std/src/lib/graphics/importer/static_model.cc
r6423 r7203 23 23 #include <stdarg.h> 24 24 25 #include "vector.h"26 27 25 using namespace std; 28 26 … … 86 84 { 87 85 PRINTF(4)("Adding new Group\n"); 88 this->name = NULL;86 this->name = ""; 89 87 this->faceMode = -1; 90 88 this->faceCount = 0; … … 109 107 if (this->listNumber != 0) 110 108 glDeleteLists(this->listNumber, 1); 111 112 if (this->name != NULL)113 delete[] this->name;114 109 115 110 if (this->next !=NULL) … … 142 137 * assigns it a Name and a Type 143 138 */ 144 StaticModel::StaticModel(const char*modelName)139 StaticModel::StaticModel(const std::string& modelName) 145 140 { 146 141 this->setClassID(CL_STATIC_MODEL, "StaticModel"); … … 276 271 * It does this by just calling the List that must have been created earlier. 277 272 */ 278 void StaticModel::draw (char* groupName) const 279 { 280 if (groupName == NULL) 281 return; 273 void StaticModel::draw (const std::string& groupName) const 274 { 282 275 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 283 276 ModelGroup* tmpGroup = this->firstGroup; 284 277 while (tmpGroup != NULL) 285 278 { 286 if (tmpGroup->name != NULL && !strcmp(tmpGroup->name, groupName))279 if (tmpGroup->name == groupName) 287 280 { 288 PRINTF(4)("Drawing model %s\n", tmpGroup->name );281 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 289 282 glCallList (tmpGroup->listNumber); 290 283 return; … … 292 285 tmpGroup = tmpGroup->next; 293 286 } 294 PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->getName());287 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getName()); 295 288 return; 296 289 } … … 341 334 * @returns the added material 342 335 */ 343 Material* StaticModel::addMaterial(const char*materialName)336 Material* StaticModel::addMaterial(const std::string& materialName) 344 337 { 345 338 ModelMaterial* modMat = new ModelMaterial; … … 357 350 * @returns the Material if found, NULL otherwise 358 351 */ 359 Material* StaticModel::findMaterialByName(const char*materialName)352 Material* StaticModel::findMaterialByName(const std::string& materialName) 360 353 { 361 354 list<ModelMaterial*>::iterator modMat; 362 355 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 363 if ( !strcmp((*modMat)->material->getName(), materialName))356 if (materialName == (*modMat)->material->getName()) 364 357 return (*modMat)->material; 365 358 return NULL; … … 373 366 * With it you should be able to create Models with more than one SubModel inside 374 367 */ 375 bool StaticModel::addGroup(const char*groupString)368 bool StaticModel::addGroup(const std::string& groupString) 376 369 { 377 370 PRINTF(5)("Read Group: %s.\n", groupString); … … 382 375 } 383 376 // setting the group name if not default. 384 if (strcmp(groupString, "default")) 385 { 386 this->currentGroup->name = new char [strlen(groupString)+1]; 387 strcpy(this->currentGroup->name, groupString); 377 if (groupString == "default") 378 { 379 this->currentGroup->name = groupString; 388 380 } 389 381 ++this->groupCount; … … 396 388 * If a vertex line is found this function will inject it into the vertex-Array 397 389 */ 398 bool StaticModel::addVertex (const char*vertexString)390 bool StaticModel::addVertex (const std::string& vertexString) 399 391 { 400 392 float subbuffer1; 401 393 float subbuffer2; 402 394 float subbuffer3; 403 sscanf (vertexString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);395 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 404 396 this->vertices.push_back(subbuffer1*scaleFactor); 405 397 this->vertices.push_back(subbuffer2*scaleFactor); … … 431 423 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 432 424 */ 433 bool StaticModel::addVertexNormal (const char*normalString)425 bool StaticModel::addVertexNormal (const std::string& normalString) 434 426 { 435 427 float subbuffer1; 436 428 float subbuffer2; 437 429 float subbuffer3; 438 sscanf (normalString , "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);430 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 439 431 this->normals.push_back(subbuffer1); 440 432 this->normals.push_back(subbuffer2); … … 471 463 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 472 464 */ 473 bool StaticModel::addVertexTexture (const char*vTextureString)465 bool StaticModel::addVertexTexture (const std::string& vTextureString) 474 466 { 475 467 float subbuffer1; 476 468 float subbuffer2; 477 sscanf (vTextureString , "%f %f", &subbuffer1, &subbuffer2);469 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 478 470 this->vTexture.push_back(subbuffer1); 479 471 this->vTexture.push_back(1 - subbuffer2); … … 508 500 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 509 501 */ 510 bool StaticModel::addFace (const char* faceString) 511 { 502 bool StaticModel::addFace (const std::string& faceStringInput) 503 { 504 const char* faceString = faceStringInput.c_str(); 512 505 if (this->currentGroup->faceCount >0) 513 506 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; … … 596 589 * @param matString the Material that will be set. 597 590 */ 598 bool StaticModel::setMaterial(const char*matString)591 bool StaticModel::setMaterial(const std::string& matString) 599 592 { 600 593 if (this->currentGroup->faceCount > 0) -
branches/std/src/lib/graphics/importer/static_model.h
r6423 r7203 13 13 #include <vector> 14 14 #include <list> 15 16 // FORWARD DECLARATION //17 template<class T> class tArray;18 15 19 16 // definition of different modes for setting up Faces … … 70 67 void cleanup(); 71 68 72 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char*name) function.69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 73 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 74 71 GLuint listNumber; //!< The number of the GL-List this Group gets. … … 98 95 { 99 96 public: 100 StaticModel(const char*modelName = NULL);97 StaticModel(const std::string& modelName = NULL); 101 98 virtual ~StaticModel(); 102 99 103 100 virtual void draw() const; 104 101 void draw(int groupNumber) const; 105 void draw(c har*groupName) const;102 void draw(const std::string& groupName) const; 106 103 107 104 void rebuild(); 108 105 109 106 Material* addMaterial(Material* material); 110 Material* addMaterial(const char*materialName);107 Material* addMaterial(const std::string& materialName); 111 108 112 bool addGroup(const char*groupString);109 bool addGroup(const std::string& groupString); 113 110 114 bool addVertex(const char*vertexString);111 bool addVertex(const std::string& vertexString); 115 112 bool addVertex(float x, float y, float z); 116 113 117 bool addFace(const char*faceString);114 bool addFace(const std::string& faceString); 118 115 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 119 116 120 bool addVertexNormal(const char*normalString);117 bool addVertexNormal(const std::string& normalString); 121 118 bool addVertexNormal(float x, float y, float z); 122 119 123 bool addVertexTexture(const char*vTextureString);120 bool addVertexTexture(const std::string& vTextureString); 124 121 bool addVertexTexture(float u, float v); 125 122 126 bool setMaterial(const char*mtlString);123 bool setMaterial(const std::string& mtlString); 127 124 bool setMaterial(Material* mtl); 128 125 … … 133 130 void cubeModel(); 134 131 135 Material* findMaterialByName(const char*materialName);132 Material* findMaterialByName(const std::string& materialName); 136 133 137 134 protected: -
branches/std/src/lib/graphics/importer/texture.cc
r6871 r7203 32 32 * Constructor for a Texture 33 33 */ 34 Texture::Texture(const char*imageName, GLenum target)34 Texture::Texture(const std::string& imageName, GLenum target) 35 35 { 36 36 this->setClassID(CL_TEXTURE, "Texture"); … … 41 41 this->priority = 0.5; 42 42 43 if ( imageName != NULL)43 if (!imageName.empty()) 44 44 { 45 45 this->setName(imageName); … … 67 67 * @param imageName The image to load 68 68 */ 69 bool Texture::loadImage(const char*imageName, GLenum target)69 bool Texture::loadImage(const std::string& imageName, GLenum target) 70 70 { 71 71 if (Texture::texturesEnabled) … … 81 81 this->texture = 0; 82 82 } 83 if ( imageName != NULL)83 if (!imageName.empty()) 84 84 { 85 85 SDL_Surface* tmpSurf; … … 87 87 glDeleteTextures(1, &this->texture); 88 88 // load the new Image to memory 89 tmpSurf = IMG_Load(imageName );89 tmpSurf = IMG_Load(imageName.c_str()); 90 90 if(tmpSurf != NULL) 91 91 { -
branches/std/src/lib/graphics/importer/texture.h
r6981 r7203 18 18 { 19 19 public: 20 Texture(const char*imageName = NULL, GLenum target = GL_TEXTURE_2D);20 Texture(const std::string& imageName = NULL, GLenum target = GL_TEXTURE_2D); 21 21 // Texture(TEXTURE_TYPE type, int resolution); 22 22 virtual ~Texture(); 23 23 24 bool loadImage(const char*imageName, GLenum target = GL_TEXTURE_2D);24 bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D); 25 25 virtual bool rebuild(); 26 26 -
branches/std/src/lib/graphics/shader.cc
r7193 r7203 36 36 * standard constructor 37 37 */ 38 Shader::Shader (const char* vertexShaderFile, const char*fragmentShaderFile)38 Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 39 39 { 40 40 this->setClassID(CL_SHADER, "Shader"); 41 41 42 this->fragmentShaderFile = NULL;43 this->vertexShaderFile = NULL;42 this->fragmentShaderFile = ""; 43 this->vertexShaderFile = ""; 44 44 this->shaderProgram = 0; 45 45 this->vertexShader = 0; … … 52 52 this->shaderProgram = glCreateProgramObjectARB(); 53 53 54 if ( vertexShaderFile != NULL)54 if (!vertexShaderFile.empty()) 55 55 this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile); 56 if ( fragmentShaderFile != NULL)56 if (!fragmentShaderFile.empty()) 57 57 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 58 58 glLinkProgramARB(this->shaderProgram); … … 103 103 } 104 104 105 Shader* Shader::getShader(const char* vertexShaderFile, const char*fragmentShaderFile)105 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 106 106 { 107 107 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, fragmentShaderFile); … … 116 116 117 117 118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const char*fileName)118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName) 119 119 { 120 120 GLhandleARB shader = 0; … … 129 129 if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader) 130 130 { 131 this->vertexShaderFile = new char[strlen(fileName)+1]; 132 strcpy(this->vertexShaderFile, fileName); 131 this->vertexShaderFile = fileName; 133 132 134 133 shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); … … 137 136 if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader) 138 137 { 139 this->fragmentShaderFile = new char[strlen(fileName)+1]; 140 strcpy(this->fragmentShaderFile, fileName); 138 this->fragmentShaderFile = fileName; 141 139 142 140 shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); … … 146 144 { 147 145 GLint status = 0; 148 glShaderSourceARB(shader, program->size(), (const char**)&(*program)[0], NULL); 146 /// FIXME do it back 147 // glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL); 149 148 glCompileShaderARB(shader); 150 149 // checking on error. … … 160 159 } 161 160 162 char* Shader::fileRead(const char*fileName)161 char* Shader::fileRead(const std::string& fileName) 163 162 { 164 163 FILE* fileHandle; … … 167 166 int count = 0; 168 167 169 if (fileName == NULL)168 if (fileName.empty()) 170 169 return NULL; 171 170 172 fileHandle = fopen(fileName , "rt");171 fileHandle = fopen(fileName.c_str(), "rt"); 173 172 174 173 if (fileHandle == NULL) … … 187 186 188 187 189 std::vector<char*>* Shader::fileReadArray(const char*fileName)188 std::vector<char*>* Shader::fileReadArray(const std::string& fileName) 190 189 { 191 190 FILE* stream; //< The stream we use to read the file. 192 191 193 if( (stream = fopen (fileName , "rt")) == NULL)194 { 195 PRINTF(1)("Shader could not open %s\n", fileName );192 if( (stream = fopen (fileName.c_str(), "rt")) == NULL) 193 { 194 PRINTF(1)("Shader could not open %s\n", fileName.c_str()); 196 195 return NULL; 197 196 } … … 234 233 if (type == SHADER_VERTEX && this->vertexShader != 0) 235 234 { 236 delete[] this->vertexShaderFile; 237 this->vertexShaderFile = NULL; 235 this->vertexShaderFile = ""; 238 236 glDetachObjectARB(this->shaderProgram, this->vertexShader); 239 237 glDeleteObjectARB(this->vertexShader); … … 245 243 else if (type == SHADER_FRAGMENT && this->fragmentShader != 0) 246 244 { 247 delete[] this->fragmentShaderFile; 248 this->fragmentShaderFile = NULL; 245 this->fragmentShaderFile = ""; 249 246 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 250 247 glDeleteObjectARB(this->fragmentShader); -
branches/std/src/lib/graphics/shader.h
r7195 r7203 27 27 28 28 public: 29 Shader(const char* vertexShaderFile = NULL, const char*fragmentShaderFile = NULL);29 Shader(const std::string& vertexShaderFile = NULL, const std::string& fragmentShaderFile = NULL); 30 30 virtual ~Shader(); 31 static Shader* getShader(const char* vertexShaderFile, const char*fragmentShaderFile);31 static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); 32 32 static bool unload(Shader* shader); 33 33 34 bool loadShaderProgramm(SHADER_TYPE type, const char*fileName);34 bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName); 35 35 void activateShader(); 36 36 static void deactivateShader(); 37 37 void deleteProgram(SHADER_TYPE type); 38 38 39 char* fileRead(const char*fileName);40 std::vector<char*>* fileReadArray(const char*fileName);39 char* fileRead(const std::string& fileName); 40 std::vector<char*>* fileReadArray(const std::string& fileName); 41 41 42 42 static bool checkShaderAbility(); … … 54 54 55 55 private: 56 char*fragmentShaderFile;57 char*vertexShaderFile;56 std::string fragmentShaderFile; 57 std::string vertexShaderFile; 58 58 GLhandleARB shaderProgram; 59 59 GLhandleARB vertexShader; -
branches/std/src/lib/graphics/text_engine/font.cc
r6609 r7203 37 37 * @param fontSize the Size of the Font in Pixels 38 38 */ 39 Font::Font(const char*fontFile, unsigned int renderSize)39 Font::Font(const std::string& fontFile, unsigned int renderSize) 40 40 { 41 41 this->init(); … … 44 44 this->setStyle("c"); 45 45 46 if ( fontFile != NULL)46 if (!fontFile.empty()) 47 47 this->loadFontFromTTF(fontFile); 48 48 } … … 52 52 * @param imageFile the ImageFile to load the Font From. 53 53 */ 54 Font::Font(const char*imageFile)54 Font::Font(const std::string& imageFile) 55 55 { 56 56 this->init(); … … 58 58 // this->setSize(fontSize); 59 59 SDL_Surface* image = NULL; 60 if ( imageFile != NULL)61 image = IMG_Load(imageFile );60 if (!imageFile.empty()) 61 image = IMG_Load(imageFile.c_str()); 62 62 else 63 63 return; … … 68 68 } 69 69 else 70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile , IMG_GetError());70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile.c_str(), IMG_GetError()); 71 71 } 72 72 … … 114 114 115 115 //! @todo check if we really do not need to delete the fastTextureID here. 116 // if (this->fastTextureID != 0)117 // if(glIsTexture(this->fastTextureID))118 // glDeleteTextures(1, &this->fastTextureID);116 // if (this->fastTextureID != 0) 117 // if(glIsTexture(this->fastTextureID)) 118 // glDeleteTextures(1, &this->fastTextureID); 119 119 120 120 // erease this font out of the memory. … … 140 140 * @returns true if loaded, false if something went wrong, or if a font was loaded before. 141 141 */ 142 bool Font::loadFontFromTTF(const char*fontFile)142 bool Font::loadFontFromTTF(const std::string& fontFile) 143 143 { 144 144 // checking for existent Font. … … 222 222 * i: italic, b: bold, u, underline 223 223 */ 224 void Font::setStyle(const char*renderStyle)224 void Font::setStyle(const std::string& renderStyle) 225 225 { 226 226 this->renderStyle = TTF_STYLE_NORMAL; 227 227 228 for (int i = 0; i < strlen(renderStyle); i++) 229 if (strncmp(renderStyle+i, "b", 1) == 0) 228 for (int i = 0; i < renderStyle.size(); i++) 229 { 230 if (renderStyle[i] == 'b') 230 231 this->renderStyle |= TTF_STYLE_BOLD; 231 else if (strncmp(renderStyle+i, "i", 1) == 0)232 this->renderStyle |= TTF_STYLE_ITALIC;233 else if (strncmp(renderStyle+i, "u", 1) == 0)234 this->renderStyle |= TTF_STYLE_UNDERLINE;235 232 else if (renderStyle[i] == 'i') 233 this->renderStyle |= TTF_STYLE_ITALIC; 234 else if (renderStyle[i] == 'u') 235 this->renderStyle |= TTF_STYLE_UNDERLINE; 236 } 236 237 if (likely(this->fontTTF != NULL)) 237 238 TTF_SetFontStyle(this->fontTTF, this->renderStyle); 238 // else239 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");239 // else 240 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); 240 241 } 241 242 … … 247 248 * @param fileName the File to write the image into. 248 249 */ 249 void Font::createAsciiImage(const char*fileName, unsigned int size) const250 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const 250 251 { 251 252 if (this->fontTTF == NULL) … … 258 259 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 259 260 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 260 261 261 height*size, height*size, 262 32, 262 263 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 263 264 265 266 264 0x000000FF, 265 0x0000FF00, 266 0x00FF0000, 267 0xFF000000 267 268 #else 268 269 270 271 269 0xFF000000, 270 0x00FF0000, 271 0x0000FF00, 272 0x000000FF 272 273 #endif 273 274 ); … … 299 300 } 300 301 } 301 SDL_SaveBMP(tmpSurf, fileName );302 SDL_SaveBMP(tmpSurf, fileName.c_str()); 302 303 SDL_FreeSurface(tmpSurf); 303 304 } … … 409 410 410 411 this->initGlyphs(32, numberOfGlyphs); 411 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space412 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space 412 413 413 414 int rectSize = this->findOptimalFastTextureSize(); … … 418 419 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 419 420 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 420 421 421 rectSize, rectSize, 422 32, 422 423 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 423 424 425 426 424 0x000000FF, 425 0x0000FF00, 426 0x00FF0000, 427 0xFF000000 427 428 #else 428 429 430 431 429 0xFF000000, 430 0x00FF0000, 431 0x0000FF00, 432 0x000000FF 432 433 #endif 433 434 ); … … 457 458 break; 458 459 } 459 460 // reading in the new Glyph 460 461 if (likely(this->fontTTF != NULL)) 461 462 { … … 521 522 for (int i = from; i <= lastGlyph; i++) 522 523 { 523 524 // setting up all the Glyphs we like. 524 525 glyphArray[i] = getGlyphMetrics(i); 525 526 } … … 555 556 if((tmpGlyph = this->glyphArray[i]) != NULL) 556 557 { 557 558 // getting the height of the highest Glyph in the Line. 558 559 if (tmpGlyph->height*this->renderSize > maxLineHeight) 559 560 maxLineHeight = (int)(tmpGlyph->height*this->renderSize); … … 563 564 x = 0; 564 565 y = y + maxLineHeight; 565 566 //maxLineHeight = 0; 566 567 } 567 568 if (y + maxLineHeight + 1 > size) … … 592 593 if(style==TTF_STYLE_NORMAL) 593 594 PRINTF(0)(" normal"); 594 else { 595 else 596 { 595 597 if(style&TTF_STYLE_BOLD) 596 598 PRINTF(0)(" bold"); -
branches/std/src/lib/graphics/text_engine/font.h
r6609 r7203 55 55 { 56 56 public: 57 Font(const char*fontFile,57 Font(const std::string& fontFile, 58 58 unsigned int renderSize); 59 Font(const char*imageFile);59 Font(const std::string& imageFile); 60 60 Font(char** xpmArray); 61 61 virtual ~Font(); … … 64 64 65 65 // font 66 bool loadFontFromTTF(const char*fontFile);66 bool loadFontFromTTF(const std::string& fontFile); 67 67 bool loadFontFromSDL_Surface(SDL_Surface* surface); 68 68 69 void setStyle(const char*renderStyle);69 void setStyle(const std::string& renderStyle); 70 70 71 71 /** @returns a Pointer to the Array of Glyphs */ … … 78 78 inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; 79 79 80 void createAsciiImage(const char*fileName, unsigned int size) const;80 void createAsciiImage(const std::string& fileName, unsigned int size) const; 81 81 static void initDefaultFont(); 82 82 static void removeDefaultFont(); -
branches/std/src/lib/gui/gtk_gui/gui_exec.cc
r7193 r7203 47 47 Frame* execFrame; //!< The Frame that holds the ExecutionOptions. 48 48 49 this->confFile = NULL;50 this->confDir = NULL;49 this->confFile = ""; 50 this->confDir = ""; 51 51 52 52 execFrame = new Frame("Execute-Tags:"); … … 137 137 GuiExec::~GuiExec() 138 138 { 139 if(this->confFile)140 delete []this->confFile;141 if(this->confDir)142 delete []this->confDir;143 139 } 144 140 … … 156 152 //! @todo F** Windows-support 157 153 #ifndef __WIN32__ 158 mkdir(this->confDir , 0755);154 mkdir(this->confDir.c_str(), 0755); 159 155 #else /* __WiN32__ */ 160 mkdir(this->confDir );156 mkdir(this->confDir.c_str()); 161 157 #endif /* __WIN32__ */ 162 158 } … … 170 166 void GuiExec::setConfFile(const char* fileName) 171 167 { 172 if (!this->confDir )168 if (!this->confDir.empty()) 173 169 this->setConfDir("~/"); 174 this->confFile = new char[strlen(this->confDir)+strlen(fileName)+2]; 175 sprintf(this->confFile, "%s/%s", this->confDir, fileName); 170 this->confFile = this->confDir + "/" + fileName; 176 171 PRINTF(5)("ConfigurationFile is %s.\n", this->confFile); 177 172 } … … 182 177 const char* GuiExec::getConfigFile() const 183 178 { 184 return this->confFile ;179 return this->confFile.c_str(); 185 180 } 186 181 … … 204 199 IniParser iniParser; 205 200 this->writeFileText(widget, &iniParser, 0); 206 char*fileName = ResourceManager::homeDirCheck(confFile);201 std::string fileName = ResourceManager::homeDirCheck(confFile); 207 202 iniParser.writeFile(fileName); 208 delete[] fileName;209 203 } 210 204 … … 259 253 void GuiExec::readFromFile(Widget* widget) 260 254 { 261 char*fileName = ResourceManager::homeDirCheck(confFile);255 std::string fileName = ResourceManager::homeDirCheck(confFile); 262 256 IniParser iniParser(fileName); 263 delete[] fileName;264 257 if (!iniParser.isOpen()) 265 258 return; … … 267 260 iniParser.firstSection(); 268 261 Widget* groupWidget = widget; 269 const char*groupName;270 const char*widgetName;262 std::string groupName; 263 std::string widgetName; 271 264 VarInfo varInfo; 272 while ( groupName = iniParser.getCurrentSection())265 while ((groupName = iniParser.getCurrentSection()) != "") 273 266 { 274 printf("GROUP:::%s\n", groupName);275 if((groupWidget = locateGroup(widget, groupName , 1))==NULL)267 PRINTF(4)("GROUP:::%s\n", groupName.c_str()); 268 if((groupWidget = locateGroup(widget, groupName.c_str(), 1))==NULL) 276 269 { 277 PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName);270 PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName.c_str()); 278 271 groupWidget = widget; 279 272 continue; … … 282 275 PRINT(4)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName); 283 276 284 const char*entryName;277 std::string entryName; 285 278 iniParser.firstVar(); 286 while( entryName = iniParser.getCurrentName())287 { 288 PRINTF(4)("ENTRY:::%s = %s\n", entryName , iniParser.getCurrentValue());289 varInfo.variableName = entryName ;290 varInfo.variableValue = iniParser.getCurrentValue() ;279 while((entryName = iniParser.getCurrentName()) != "") 280 { 281 PRINTF(4)("ENTRY:::%s = %s\n", entryName.c_str(), iniParser.getCurrentValue().c_str()); 282 varInfo.variableName = entryName.c_str(); 283 varInfo.variableValue = iniParser.getCurrentValue().c_str(); 291 284 groupWidget->walkThrough(this->readFileText, &varInfo, 0); 292 285 iniParser.nextVar(); -
branches/std/src/lib/gui/gtk_gui/gui_exec.h
r6981 r7203 11 11 #include "gui_gtk.h" 12 12 13 #include <string> 14 13 15 class Widget; 14 16 class CheckButton; … … 22 24 CheckButton* saveSettings; //!< A CheckBox for if the Options should be saved. 23 25 24 char* confDir;//!< The directory of the orxonox-configuration-files.25 char* confFile;//!< The name of the .orxonox.conf(ig)-file.26 std::string confDir; //!< The directory of the orxonox-configuration-files. 27 std::string confFile; //!< The name of the .orxonox.conf(ig)-file. 26 28 27 29 //! A struct that holds informations about variables. … … 58 60 struct HashTable 59 61 { 60 char*name; //!< name of the entry61 char*value; //!< value of the entry62 std::string name; //!< name of the entry 63 std::string value; //!< value of the entry 62 64 HashTable* next; //!< pointer to the next entry 63 65 }; -
branches/std/src/lib/lang/base_object.cc
r7193 r7203 95 95 * @brief set the name of the Object 96 96 */ 97 void BaseObject::setName (const char*objectName)97 void BaseObject::setName (const std::string& objectName) 98 98 { 99 99 if (this->objectName) 100 100 delete[] this->objectName; 101 if ( objectName != NULL)102 { 103 this->objectName = new char[ strlen(objectName)+1];104 strcpy(this->objectName, objectName );101 if (!objectName.empty()) 102 { 103 this->objectName = new char[objectName.size()+1]; 104 strcpy(this->objectName, objectName.c_str()); 105 105 } 106 106 else -
branches/std/src/lib/lang/base_object.h
r6587 r7203 16 16 #endif 17 17 18 #include <string> 18 19 #include "stdincl.h" 19 20 … … 30 31 31 32 virtual void loadParams(const TiXmlElement* root); 32 void setName (const char*newName);33 void setName (const std::string& newName); 33 34 /** returns the Name of this Object */ 34 35 inline const char* getName ()const { return this->objectName; }; -
branches/std/src/lib/parser/ini_parser/ini_parser.cc
r5953 r7203 40 40 * @param fileName: the path and name of the file to parse 41 41 */ 42 IniParser::IniParser (const char*fileName)43 { 44 this->fileName = NULL;45 this->comment = NULL;46 47 if ( fileName != NULL)42 IniParser::IniParser (const std::string& fileName) 43 { 44 this->fileName = ""; 45 this->comment = ""; 46 47 if (!fileName.empty()) 48 48 this->readFile(fileName); 49 49 } … … 59 59 } 60 60 61 const std::string IniParser::emptyString = ""; 62 61 63 62 64 /** … … 68 70 while(!this->sections.empty()) 69 71 { 70 72 IniSection section = this->sections.front(); 71 73 72 74 // in all entries of the sections … … 75 77 // delete all strings of entries. 76 78 IniEntry entry = section.entries.front(); 77 delete[] entry.name;78 delete[] entry.value;79 delete[] entry.comment;80 79 section.entries.pop_front(); 81 80 } 82 81 // delete all Sections 83 delete[] section.name;84 delete[] section.comment;85 82 this->sections.pop_front(); 86 83 } … … 95 92 * If fileName is NULL the new Name will be set to NULL too. 96 93 */ 97 void IniParser::setFileName(const char* fileName) 98 { 99 if (this->fileName != NULL) 100 delete[] this->fileName; 101 if (this->comment != NULL) 102 delete[] this->comment; 103 this->comment = NULL; 104 105 if (fileName != NULL) 106 { 107 this->fileName = new char[strlen(fileName)+1]; 108 strcpy(this->fileName, fileName); 109 } 110 else 111 this->fileName = NULL; 94 void IniParser::setFileName(const std::string& fileName) 95 { 96 this->comment = ""; 97 98 if (!fileName.empty()) 99 this->fileName = fileName; 100 else 101 this->fileName = ""; 112 102 } 113 103 … … 121 111 * and the new one will be opened. 122 112 */ 123 bool IniParser::readFile(const char*fileName)113 bool IniParser::readFile(const std::string& fileName) 124 114 { 125 115 FILE* stream; //< The stream we use to read the file. 126 116 int lineCount = 0; //< The Count of lines. 127 117 128 if ( this->fileName != NULL)118 if (!this->fileName.empty()) 129 119 this->deleteSections(); 130 if( fileName == NULL)131 return false; 132 133 if( (stream = fopen (fileName , "r")) == NULL)134 { 135 PRINTF(1)("IniParser could not open %s\n", fileName );120 if( fileName.empty()) 121 return false; 122 123 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 124 { 125 PRINTF(1)("IniParser could not open %s\n", fileName.c_str()); 136 126 return false; 137 127 } … … 191 181 continue; 192 182 } 193 if( ptr == lineBegin) { 183 if( ptr == lineBegin) 184 { 194 185 lineCount++; 195 186 continue; … … 228 219 * @return true on success false otherwise 229 220 */ 230 bool IniParser::writeFile(const char*fileName) const221 bool IniParser::writeFile(const std::string& fileName) const 231 222 { 232 223 FILE* stream; //!< The stream we use to read the file. 233 if( fileName == NULL && (fileName = this->fileName) == NULL)234 return false; 235 236 if( (stream = fopen (fileName , "w")) == NULL)237 { 238 PRINTF(1)("IniParser could not open %s\n", fileName );239 return false; 240 } 241 else 242 { 243 if ( this->comment != NULL)244 fprintf(stream, "%s\n\n", this->comment );224 if( fileName.empty()) 225 return false; 226 227 if( (stream = fopen (fileName.c_str(), "w")) == NULL) 228 { 229 PRINTF(1)("IniParser could not open %s\n", fileName.c_str()); 230 return false; 231 } 232 else 233 { 234 if (!this->comment.empty()) 235 fprintf(stream, "%s\n\n", this->comment.c_str()); 245 236 246 237 std::list<IniSection>::const_iterator section; 247 238 for (section = this->sections.begin(); section != this->sections.end(); section++) 239 { 240 if (!(*section).comment.empty()) 241 fprintf(stream, "%s", (*section).comment.c_str()); 242 fprintf(stream, "\n [%s]\n", (*section).name.c_str()); 243 244 std::list<IniEntry>::const_iterator entry; 245 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 248 246 { 249 if ((*section).comment != NULL) 250 fprintf(stream, "%s", (*section).comment); 251 fprintf(stream, "\n [%s]\n", (*section).name); 252 253 std::list<IniEntry>::const_iterator entry; 254 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 255 { 256 if ((*entry).comment != NULL) 257 fprintf(stream, "%s", (*entry).comment); 258 fprintf(stream, " %s = %s\n", (*entry).name, (*entry).value); 259 } 247 if (!(*entry).comment.empty()) 248 fprintf(stream, "%s", (*entry).comment.c_str()); 249 fprintf(stream, " %s = %s\n", (*entry).name.c_str(), (*entry).value.c_str()); 260 250 } 251 } 261 252 } 262 253 fclose(stream); 263 254 } 264 255 265 void IniParser::setFileComment(const char* fileComment) 266 { 267 if (this->comment != NULL) 268 delete this->comment; 269 270 if (fileComment != NULL) 271 { 272 this->comment = new char[strlen(fileComment)+1]; 273 strcpy(this->comment, fileComment); 274 } 275 else 276 this->comment = NULL; 277 } 278 256 void IniParser::setFileComment(const std::string& fileComment) 257 { 258 this->comment = fileComment; 259 } 279 260 280 261 /** … … 284 265 * @return true on success... there is only success or segfault :) 285 266 */ 286 bool IniParser::addSection(const char*sectionName)287 { 288 if (sectionName == NULL)267 bool IniParser::addSection(const std::string& sectionName) 268 { 269 if (sectionName.empty()) 289 270 return false; 290 271 this->sections.push_back(IniSection()); 291 this->sections.back().comment = NULL; 292 this->sections.back().name = new char[strlen(sectionName)+1]; 293 strcpy(this->sections.back().name, sectionName); 272 this->sections.back().comment = ""; 273 this->sections.back().name = sectionName; 294 274 295 275 this->currentSection = --this->sections.end(); 296 276 if (!this->sections.empty()) 297 277 this->currentEntry = (*this->currentSection).entries.begin(); 298 278 PRINTF(5)("Added Section %s\n", sectionName); 299 279 return true; … … 306 286 * @return true on success or false if the section could not be found 307 287 */ 308 bool IniParser::getSection(const char*sectionName)288 bool IniParser::getSection(const std::string& sectionName) 309 289 { 310 290 this->currentSection = this->getSectionIT(sectionName); … … 321 301 * 322 302 */ 323 void IniParser::setSectionComment(const char* comment, const char*sectionName)303 void IniParser::setSectionComment(const std::string& comment, const std::string& sectionName) 324 304 { 325 305 std::list<IniSection>::iterator section = this->getSectionIT(sectionName); … … 327 307 return; 328 308 329 if ((*section).comment != NULL) 330 delete[] (*section).comment; 331 if (comment != NULL) 332 { 333 (*section).comment = new char[strlen (comment)+1]; 334 strcpy((*section).comment, comment); 335 } 336 else 337 (*section).comment = NULL; 309 (*section).comment = comment; 338 310 } 339 311 … … 342 314 * @returns the Comment, or NULL on error. 343 315 */ 344 const char* IniParser::getSectionComment(const char*sectionName) const316 const std::string& IniParser::getSectionComment(const std::string& sectionName) const 345 317 { 346 318 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); … … 348 320 return (*section).comment; 349 321 else 350 return NULL;322 return IniParser::emptyString; 351 323 } 352 324 … … 367 339 * @returns the name of the section if found, NULL otherwise 368 340 */ 369 const char*IniParser::nextSection()341 const std::string& IniParser::nextSection() 370 342 { 371 343 if (this->currentSection == this->sections.end()) 372 return NULL;344 return IniParser::emptyString; 373 345 374 346 this->currentSection++; 375 347 376 348 if (this->currentSection != this->sections.end()) 377 378 379 380 381 else 382 return NULL;349 { 350 this->currentEntry = (*this->currentSection).entries.begin(); 351 return this->currentSection->name; 352 } 353 else 354 return IniParser::emptyString; 383 355 } 384 356 … … 393 365 * @return true if everything is ok false on error 394 366 */ 395 bool IniParser::addVar(const char* entryName, const char* value, const char*sectionName)367 bool IniParser::addVar(const std::string& entryName, const std::string& value, const std::string& sectionName) 396 368 { 397 369 std::list<IniSection>::iterator section; 398 370 399 if ( sectionName != NULL)371 if (!sectionName.empty()) 400 372 { 401 373 for (section = this->sections.begin(); section != this->sections.end(); section++) 402 if ( !strcmp((*section).name, sectionName))374 if ((*section).name == sectionName) 403 375 break; 404 376 } … … 411 383 if (section == this->sections.end()) 412 384 { 413 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName , entryName);385 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str()); 414 386 return false; 415 387 } … … 417 389 { 418 390 (*section).entries.push_back(IniEntry()); 419 (*section).entries.back().comment = NULL; 420 (*section).entries.back().name = new char[strlen(entryName)+1]; 421 strcpy((*section).entries.back().name, entryName); 422 (*section).entries.back().value = new char[strlen(value)+1]; 423 strcpy((*section).entries.back().value, value); 391 (*section).entries.back().comment = ""; 392 (*section).entries.back().name = entryName; 393 (*section).entries.back().value = value; 424 394 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 425 (*section).entries.back().name ,426 (*section).entries.back().value ,427 (*section).name );395 (*section).entries.back().name.c_str(), 396 (*section).entries.back().value.c_str(), 397 (*section).name.c_str()); 428 398 this->currentEntry = --(*section).entries.end(); 429 399 return true; … … 442 412 * lead to unwanted behaviour. 443 413 */ 444 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char*defaultValue) const445 { 446 if ( this->fileName != NULL)414 const std::string& IniParser::getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue) const 415 { 416 if (!this->fileName.empty()) 447 417 { 448 418 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); 449 if (entry != NULL && !strcmp((*entry).name, entryName))419 if (entry != NULL && (*entry).name == entryName) 450 420 return (*entry).value; 451 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName , sectionName);421 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str()); 452 422 453 423 } … … 456 426 457 427 return defaultValue; 458 459 428 } 460 429 … … 465 434 * @param sectionName the Name of the Section 466 435 */ 467 void IniParser::setEntryComment(const char* comment, const char* entryName, const char*sectionName)436 void IniParser::setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName) 468 437 { 469 438 std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName); 470 471 if ((*entry).comment != NULL) 472 delete[] (*entry).comment; 473 if (comment != NULL) 474 { 475 (*entry).comment = new char[strlen (comment)+1]; 476 strcpy((*entry).comment, comment); 477 } 478 else 479 (*entry).comment = NULL; 480 481 439 (*entry).comment = comment; 482 440 } 483 441 … … 487 445 * @returns the queried Comment. 488 446 */ 489 const char* IniParser::getEntryComment(const char* entryName, const char*sectionName) const447 const std::string& IniParser::getEntryComment(const std::string& entryName, const std::string& sectionName) const 490 448 { 491 449 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); … … 501 459 { 502 460 if (!this->sections.empty() && 503 461 this->currentSection != this->sections.end()) 504 462 this->currentEntry = (*this->currentSection).entries.begin(); 505 463 } … … 530 488 * @returns the name of the Current selected Section 531 489 */ 532 const char*IniParser::getCurrentSection() const490 const std::string& IniParser::getCurrentSection() const 533 491 { 534 492 if (!this->sections.empty() && … … 536 494 return this->currentSection->name; 537 495 else 538 return NULL;539 496 return IniParser::emptyString ; 497 } 540 498 541 499 … … 543 501 * @returns the current entries Name, or NULL if we havn't selected a Entry 544 502 */ 545 const char*IniParser::getCurrentName() const546 { 547 if (!this->sections.empty() &&548 this->currentSection != this->sections.end() &&549 this->currentEntry != (*this->currentSection).entries.end())550 return (*this->currentEntry).name;551 else552 return NULL;503 const std::string& IniParser::getCurrentName() const 504 { 505 if (!this->sections.empty() && 506 this->currentSection != this->sections.end() && 507 this->currentEntry != (*this->currentSection).entries.end()) 508 return (*this->currentEntry).name; 509 else 510 return emptyString; 553 511 } 554 512 … … 556 514 * @returns the current entries Value, or NULL if we havn't selected a Entry 557 515 */ 558 const char*IniParser::getCurrentValue() const516 const std::string& IniParser::getCurrentValue() const 559 517 { 560 518 if (!this->sections.empty() && … … 563 521 return (*this->currentEntry).value; 564 522 else 565 return NULL;523 return IniParser::emptyString; 566 524 } 567 525 … … 571 529 * @param sectionName the Name of the Section to get the Iterator from 572 530 */ 573 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char*sectionName) const531 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const std::string& sectionName) const 574 532 { 575 533 std::list<IniSection>::const_iterator section = this->currentSection; 576 if (sectionName == NULL)534 if (sectionName.empty()) 577 535 return this->currentSection; 578 536 else 579 537 for (section = this->sections.begin(); section != this->sections.end(); section++) 580 if ( !strcmp((*section).name, sectionName))538 if ((*section).name == sectionName) 581 539 break; 582 540 return section; … … 588 546 * @param sectionName the Name of the Section to get the Iterator from 589 547 */ 590 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const char*sectionName)548 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const std::string& sectionName) 591 549 { 592 550 std::list<IniSection>::iterator section = this->currentSection; 593 if (sectionName == NULL)551 if (sectionName.empty()) 594 552 return this->currentSection; 595 553 else 596 554 for (section = this->sections.begin(); section != this->sections.end(); section++) 597 if ( !strcmp((*section).name, sectionName))555 if ((*section).name == sectionName) 598 556 break; 599 557 return section; … … 606 564 * @param sectionName the Name of the Section to get the Iterator from 607 565 */ 608 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char*sectionName) const609 { 610 if (entryName == NULL)566 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) const 567 { 568 if (entryName.empty()) 611 569 return this->currentEntry; 612 570 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); … … 615 573 if (section != this->sections.end()) 616 574 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 617 if ( !strcmp((*entry).name, entryName))575 if ((*entry).name == entryName) 618 576 break; 619 577 if (entry == (*section).entries.end()) … … 629 587 * @param sectionName the Name of the Section to get the Iterator from 630 588 */ 631 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const char* entryName, const char*sectionName)632 { 633 if (entryName == NULL)589 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) 590 { 591 if (entryName.empty()) 634 592 return this->currentEntry; 635 593 std::list<IniSection>::iterator section = this->getSectionIT(sectionName); … … 638 596 if (section != this->sections.end()) 639 597 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 640 if ( !strcmp((*entry).name, entryName))598 if ((*entry).name == entryName) 641 599 break; 642 600 if (entry == (*section).entries.end()) … … 652 610 void IniParser::setFileComment() 653 611 { 654 if (this->comment != NULL) 655 delete[] this->comment; 656 657 if (this->commentList.empty()) { 658 this->comment = NULL; 612 if (this->commentList.empty()) 613 { 614 this->comment = ""; 659 615 return; 660 616 } 661 617 662 unsigned int stringLength = 1;663 618 std::list<char*>::iterator comment; 664 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 665 stringLength += strlen((*comment)) +1; 666 667 this->comment = new char[stringLength]; 668 this->comment[0] = '\0'; 619 669 620 while (!this->commentList.empty()) 670 621 { 671 if (*this->comment != '\0') 672 strcat(this->comment, "\n"); 673 strcat(this->comment, this->commentList.front()); 674 delete[] this->commentList.front(); 622 if (this->comment[0] != '\0') 623 this->comment += "\n"; 624 this->comment += this->commentList.front(); 675 625 this->commentList.pop_front(); 676 626 } … … 682 632 void IniParser::setSectionComment() 683 633 { 684 if ((*this->currentSection).comment != NULL) 685 delete[] (*this->currentSection).comment; 686 687 if (this->commentList.empty()) { 688 (*this->currentSection).comment = NULL; 634 (*this->currentSection).comment = ""; 635 636 if (this->commentList.empty()) 689 637 return; 690 } 691 692 unsigned int stringLength = 1; 693 std::list<char*>::iterator comment; 694 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 695 stringLength += strlen((*comment)) +1; 696 697 (*this->currentSection).comment = new char[stringLength]; 698 (*this->currentSection).comment[0] = '\0'; 638 699 639 while (!this->commentList.empty()) 700 640 { 701 if (*(*this->currentSection).comment != '\0') 702 strcat((*this->currentSection).comment, "\n"); 703 strcat((*this->currentSection).comment, this->commentList.front()); 704 delete[] this->commentList.front(); 641 if ((*this->currentSection).comment[0] != '\0') 642 (*this->currentSection).comment += "\n"; 643 (*this->currentSection).comment += this->commentList.front(); 705 644 this->commentList.pop_front(); 706 645 } … … 712 651 void IniParser::setEntryComment() 713 652 { 714 if ((*this->currentEntry).comment != NULL) 715 delete[] (*this->currentEntry).comment; 716 717 if (this->commentList.empty()) { 718 (*this->currentEntry).comment = NULL; 653 (*this->currentEntry).comment = ""; 654 if (this->commentList.empty()) 719 655 return; 720 } 721 722 unsigned int stringLength = 1; 723 std::list<char*>::iterator comment; 724 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 725 stringLength += strlen((*comment)) +1; 726 727 (*this->currentEntry).comment = new char[stringLength]; 728 (*this->currentEntry).comment[0] = '\0'; 656 729 657 while (!this->commentList.empty()) 730 658 { 731 if (*(*this->currentEntry).comment != '\0') 732 strcat((*this->currentEntry).comment, "\n"); 733 strcat((*this->currentEntry).comment, this->commentList.front()); 734 delete[] this->commentList.front(); 659 if ((*this->currentEntry).comment[0] != '\0') 660 (*this->currentEntry).comment += "\n"; 661 (*this->currentEntry).comment += this->commentList.front(); 735 662 this->commentList.pop_front(); 736 663 } 737 738 664 } 739 665 … … 744 670 void IniParser::debug() const 745 671 { 746 PRINTF(0)("Iniparser %s - debug\n", this->fileName );747 if ( this->comment != NULL)748 PRINTF(0)("FileComment:\n %s\n\n", this->comment );749 750 if ( this->fileName != NULL)672 PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str()); 673 if (!this->comment.empty()) 674 PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str()); 675 676 if (!this->fileName.empty()) 751 677 { 752 678 std::list<IniSection>::const_iterator section; 753 679 for (section = this->sections.begin(); section != this->sections.end(); section++) 754 680 { 755 if ( (*section).comment != NULL)756 PRINTF(0)(" %s\n", (*section).comment );757 PRINTF(0)(" [%s]\n", (*section).name );681 if (!(*section).comment.empty()) 682 PRINTF(0)(" %s\n", (*section).comment.c_str()); 683 PRINTF(0)(" [%s]\n", (*section).name.c_str()); 758 684 759 685 std::list<IniEntry>::const_iterator entry; 760 686 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 761 687 { 762 if ( (*entry).comment != NULL)763 PRINTF(0)(" %s\n", (*entry).comment );764 PRINTF(0)(" '%s' -> '%s'\n", (*entry).name , (*entry).value);688 if (!(*entry).comment.empty()) 689 PRINTF(0)(" %s\n", (*entry).comment.c_str()); 690 PRINTF(0)(" '%s' -> '%s'\n", (*entry).name.c_str(), (*entry).value.c_str()); 765 691 } 766 692 } -
branches/std/src/lib/parser/ini_parser/ini_parser.h
r6981 r7203 15 15 16 16 #include <list> 17 #include <string> 17 18 18 19 //! ini-file parser … … 27 28 struct IniEntry 28 29 { 29 char*comment; //!< A Comment that is appendet to the Top of this Entry.30 char*name; //!< name of a given Entry31 char*value; //!< value of a given Entry30 std::string comment; //!< A Comment that is appendet to the Top of this Entry. 31 std::string name; //!< name of a given Entry 32 std::string value; //!< value of a given Entry 32 33 }; 33 34 … … 35 36 struct IniSection 36 37 { 37 char*comment; //!< A Comment that is appendet to the Top of this Section.38 char*name; //!< name of a given section38 std::string comment; //!< A Comment that is appendet to the Top of this Section. 39 std::string name; //!< name of a given section 39 40 std::list<IniEntry> entries; //!< a list of entries for this section 40 41 }; … … 42 43 43 44 public: 44 IniParser (const char* filename = NULL);45 IniParser (const std::string& filename = ""); 45 46 virtual ~IniParser (); 46 47 47 48 /** @returns true if the file is opened, false otherwise*/ 48 bool isOpen() const { return ( this->fileName != NULL)? true : false; };49 bool isOpen() const { return (!this->fileName.empty())? true : false; }; 49 50 /** @returns the fileName we have opened. */ 50 const char*getFileName() const { return this->fileName; };51 const std::string& getFileName() const { return this->fileName; }; 51 52 52 bool readFile(const char*fileName);53 bool writeFile(const char*fileName) const;53 bool readFile(const std::string& fileName); 54 bool writeFile(const std::string& fileName) const; 54 55 55 void setFileComment(const char*fileComment);56 const char*getFileComment() const { return this->comment; };56 void setFileComment(const std::string& fileComment); 57 const std::string& getFileComment() const { return this->comment; }; 57 58 58 bool addSection(const char*sectionName);59 bool getSection(const char*sectionName);60 void setSectionComment(const char* comment, const char*sectionName);61 const char* getSectionComment(const char*sectionNane) const;59 bool addSection(const std::string& sectionName); 60 bool getSection(const std::string& sectionName); 61 void setSectionComment(const std::string& comment, const std::string& sectionName); 62 const std::string& getSectionComment(const std::string& sectionNane) const; 62 63 63 64 // iterate through sections with these Functions 64 65 void firstSection(); 65 const char*nextSection();66 const std::string& nextSection(); 66 67 67 68 68 bool addVar(const char* entryName, const char* value, const char*sectionName = NULL);69 const char* getVar(const char* entryName, const char* sectionName, const char*defaultValue = "") const;70 void setEntryComment(const char* comment, const char* entryName, const char*sectionName);71 const char* getEntryComment(const char* entryName, const char*sectionName) const;69 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = NULL); 70 const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const; 71 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 72 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const; 72 73 73 74 // iterate Through Variables with these Functions. … … 77 78 78 79 // retrieving functions when iterating. 79 const char*getCurrentSection() const;80 const char*getCurrentName() const;81 const char*getCurrentValue() const;80 const std::string& getCurrentSection() const; 81 const std::string& getCurrentName() const; 82 const std::string& getCurrentValue() const; 82 83 83 84 … … 88 89 private: 89 90 void deleteSections(); 90 void setFileName(const char*fileName);91 void setFileName(const std::string& fileName); 91 92 92 93 void setFileComment(); … … 94 95 void setEntryComment(); 95 96 96 std::list<IniSection>::const_iterator getSectionIT(const char*sectionName) const;97 std::list<IniSection>::iterator getSectionIT(const char*sectionName);97 std::list<IniSection>::const_iterator getSectionIT(const std::string& sectionName) const; 98 std::list<IniSection>::iterator getSectionIT(const std::string& sectionName); 98 99 99 std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char*sectionName = NULL) const;100 std::list<IniEntry>::iterator getEntryIT(const char* entryName, const char*sectionName = NULL);100 std::list<IniEntry>::const_iterator getEntryIT(const std::string& entryName, const std::string& sectionName = NULL) const; 101 std::list<IniEntry>::iterator getEntryIT(const std::string& entryName, const std::string& sectionName = NULL); 101 102 102 103 private: 103 char*fileName; //!< The name of the File that was parsed.104 char*comment; //!< A Comment for the header of this File.104 std::string fileName; //!< The name of the File that was parsed. 105 std::string comment; //!< A Comment for the header of this File. 105 106 std::list<IniSection> sections; //!< a list of all stored Sections of the Parser 106 107 std::list<IniSection>::iterator currentSection; //!< the current selected Section 107 108 std::list<IniEntry>::iterator currentEntry; //!< the current selected entry (in currentSection) 108 109 109 std::list<char*> commentList; //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.) 110 std::list<std::string> commentList; //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.) 111 112 113 static const std::string emptyString; 110 114 }; 111 115 -
branches/std/src/lib/parser/tinyxml/tinyxml.h
r5819 r7203 26 26 #ifndef TINYXML_INCLUDED 27 27 #define TINYXML_INCLUDED 28 29 #define TIXML_USE_STL 28 30 29 31 #ifdef _MSC_VER … … 81 83 #define TIXML_SNSCANF snscanf 82 84 #endif 83 #endif 85 #endif 84 86 85 87 class TiXmlDocument; … … 96 98 const int TIXML_PATCH_VERSION = 2; 97 99 98 /* Internal structure for tracking location of items 100 /* Internal structure for tracking location of items 99 101 in the XML file. 100 102 */ … … 110 112 111 113 // Only used by Attribute::Query functions 112 enum 113 { 114 enum 115 { 114 116 TIXML_SUCCESS, 115 117 TIXML_NO_ATTRIBUTE, … … 162 164 /** All TinyXml classes can print themselves to a filestream. 163 165 This is a formatted print, and will insert tabs and newlines. 164 166 165 167 (For an unformatted stream, use the << operator.) 166 168 */ … … 206 208 static const int utf8ByteTable[256]; 207 209 208 virtual const char* Parse( const char* p, 209 TiXmlParsingData* data, 210 virtual const char* Parse( const char* p, 211 TiXmlParsingData* data, 210 212 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; 211 213 … … 245 247 246 248 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); 247 inline static bool IsWhiteSpace( char c ) 248 { 249 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 249 inline static bool IsWhiteSpace( char c ) 250 { 251 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 250 252 } 251 253 … … 334 336 /// Field containing a generic user pointer 335 337 void* userData; 336 338 337 339 // None of these methods are reliable for any language except English. 338 340 // Good for approximation, not great for accuracy. … … 386 388 387 389 public: 388 #ifdef TIXML_USE_STL 390 #ifdef TIXML_USE_STL 389 391 390 392 /** An input stream operator, for every class. Tolerant of newlines and … … 400 402 a node to a stream is very well defined. You'll get a nice stream 401 403 of output, without any extra whitespace or newlines. 402 404 403 405 But reading is not as well defined. (As it always is.) If you create 404 406 a TiXmlElement (for example) and read that from an input stream, … … 408 410 A TiXmlDocument will read nodes until it reads a root element, and 409 411 all the children of that root element. 410 */ 412 */ 411 413 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); 412 414 … … 470 472 #ifdef TIXML_USE_STL 471 473 /// STL std::string form. 472 void SetValue( const std::string& _value ) 473 { 474 void SetValue( const std::string& _value ) 475 { 474 476 StringToBuffer buf( _value ); 475 SetValue( buf.buffer ? buf.buffer : "" ); 476 } 477 SetValue( buf.buffer ? buf.buffer : "" ); 478 } 477 479 #endif 478 480 … … 492 494 TiXmlNode* LastChild() { return lastChild; } 493 495 const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. 494 TiXmlNode* LastChild( const char * value ); 496 TiXmlNode* LastChild( const char * value ); 495 497 496 498 #ifdef TIXML_USE_STL … … 649 651 650 652 /** Create an exact duplicate of this node and return it. The memory must be deleted 651 by the caller. 653 by the caller. 652 654 */ 653 655 virtual TiXmlNode* Clone() const = 0; … … 731 733 /** QueryIntValue examines the value string. It is an alternative to the 732 734 IntValue() method with richer error checking. 733 If the value is an integer, it is stored in 'value' and 735 If the value is an integer, it is stored in 'value' and 734 736 the call returns TIXML_SUCCESS. If it is not 735 737 an integer, it returns TIXML_WRONG_TYPE. … … 750 752 #ifdef TIXML_USE_STL 751 753 /// STL std::string form. 752 void SetName( const std::string& _name ) 753 { 754 void SetName( const std::string& _name ) 755 { 754 756 StringToBuffer buf( _name ); 755 SetName ( buf.buffer ? buf.buffer : "error" ); 756 } 757 /// STL std::string form. 758 void SetValue( const std::string& _value ) 759 { 757 SetName ( buf.buffer ? buf.buffer : "error" ); 758 } 759 /// STL std::string form. 760 void SetValue( const std::string& _value ) 761 { 760 762 StringToBuffer buf( _value ); 761 SetValue( buf.buffer ? buf.buffer : "error" ); 763 SetValue( buf.buffer ? buf.buffer : "error" ); 762 764 } 763 765 #endif … … 801 803 /* A class used to manage a group of attributes. 802 804 It is only used internally, both by the ELEMENT and the DECLARATION. 803 805 804 806 The set can be changed transparent to the Element and Declaration 805 807 classes that use it, but NOT transparent to the Attribute … … 882 884 /** QueryIntAttribute examines the attribute - it is an alternative to the 883 885 Attribute() method with richer error checking. 884 If the attribute is an integer, it is stored in 'value' and 886 If the attribute is an integer, it is stored in 'value' and 885 887 the call returns TIXML_SUCCESS. If it is not 886 888 an integer, it returns TIXML_WRONG_TYPE. If the attribute 887 889 does not exist, then TIXML_NO_ATTRIBUTE is returned. 888 */ 890 */ 889 891 int QueryIntAttribute( const char* name, int* _value ) const; 890 892 /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). … … 913 915 914 916 /// STL std::string form. 915 void SetAttribute( const std::string& name, const std::string& _value ) 916 { 917 void SetAttribute( const std::string& name, const std::string& _value ) 918 { 917 919 StringToBuffer n( name ); 918 920 StringToBuffer v( _value ); 919 921 if ( n.buffer && v.buffer ) 920 SetAttribute (n.buffer, v.buffer ); 921 } 922 SetAttribute (n.buffer, v.buffer ); 923 } 922 924 ///< STL std::string form. 923 void SetAttribute( const std::string& name, int _value ) 924 { 925 void SetAttribute( const std::string& name, int _value ) 926 { 925 927 StringToBuffer n( name ); 926 928 if ( n.buffer ) 927 SetAttribute (n.buffer, _value); 928 } 929 SetAttribute (n.buffer, _value); 930 } 929 931 #endif 930 932 … … 954 956 and concise, GetText() is limited compared to getting the TiXmlText child 955 957 and accessing it directly. 956 958 957 959 If the first child of 'this' is a TiXmlText, the GetText() 958 960 returns the character string of the Text node, else null is returned. … … 964 966 @endverbatim 965 967 966 'str' will be a pointer to "This is text". 967 968 'str' will be a pointer to "This is text". 969 968 970 Note that this function can be misleading. If the element foo was created from 969 971 this XML: 970 972 @verbatim 971 <foo><b>This is text</b></foo> 973 <foo><b>This is text</b></foo> 972 974 @endverbatim 973 975 … … 975 977 another element. From this XML: 976 978 @verbatim 977 <foo>This is <b>text</b></foo> 979 <foo>This is <b>text</b></foo> 978 980 @endverbatim 979 981 GetText() will return "This is ". 980 982 981 WARNING: GetText() accesses a child node - don't become confused with the 982 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 WARNING: GetText() accesses a child node - don't become confused with the 984 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 985 safe type casts on the referenced node. 984 986 */ … … 1054 1056 1055 1057 1056 /** XML text. A text node can have 2 ways to output the next. "normal" output 1058 /** XML text. A text node can have 2 ways to output the next. "normal" output 1057 1059 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 1060 you generally want to leave it alone, but you can change the output mode with 1059 1061 SetCDATA() and query it with CDATA(). 1060 1062 */ … … 1063 1065 friend class TiXmlElement; 1064 1066 public: 1065 /** Constructor for text element. By default, it is treated as 1067 /** Constructor for text element. By default, it is treated as 1066 1068 normal, encoded text. If you want it be output as a CDATA text 1067 1069 element, set the parameter _cdata to 'true' … … 1279 1281 - The ErrorDesc() method will return the name of the error. (very useful) 1280 1282 - The ErrorRow() and ErrorCol() will return the location of the error (if known) 1281 */ 1283 */ 1282 1284 bool Error() const { return error; } 1283 1285 … … 1290 1292 int ErrorId() const { return errorId; } 1291 1293 1292 /** Returns the location (if known) of the error. The first column is column 1, 1294 /** Returns the location (if known) of the error. The first column is column 1, 1293 1295 and the first row is row 1. A value of 0 means the row and column wasn't applicable 1294 1296 (memory errors, for example, have no row/column) or the parser lost the error. (An … … 1303 1305 to report the correct values for row and column. It does not change the output 1304 1306 or input in any way. 1305 1307 1306 1308 By calling this method, with a tab size 1307 1309 greater than 0, the row and column of each node and attribute is stored … … 1331 1333 state is automatically cleared if you Parse a new XML block. 1332 1334 */ 1333 void ClearError() { error = false; 1334 errorId = 0; 1335 errorDesc = ""; 1336 errorLocation.row = errorLocation.col = 0; 1337 //errorLocation.last = 0; 1335 void ClearError() { error = false; 1336 errorId = 0; 1337 errorDesc = ""; 1338 errorLocation.row = errorLocation.col = 0; 1339 //errorLocation.last = 0; 1338 1340 } 1339 1341 … … 1381 1383 @endverbatim 1382 1384 1383 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1385 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1384 1386 easy to write a *lot* of code that looks like: 1385 1387 … … 1401 1403 1402 1404 And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity 1403 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1405 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1404 1406 and correct to use: 1405 1407 … … 1422 1424 1423 1425 @verbatim 1424 int i=0; 1426 int i=0; 1425 1427 while ( true ) 1426 1428 { … … 1433 1435 @endverbatim 1434 1436 1435 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1436 a linear walk to find the element, so this code would iterate much more than it needs 1437 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1438 a linear walk to find the element, so this code would iterate much more than it needs 1437 1439 to. Instead, prefer: 1438 1440 … … 1464 1466 TiXmlHandle FirstChildElement( const char * value ) const; 1465 1467 1466 /** Return a handle to the "index" child with the given name. 1468 /** Return a handle to the "index" child with the given name. 1467 1469 The first child is 0, the second 1, etc. 1468 1470 */ 1469 1471 TiXmlHandle Child( const char* value, int index ) const; 1470 /** Return a handle to the "index" child. 1472 /** Return a handle to the "index" child. 1471 1473 The first child is 0, the second 1, etc. 1472 1474 */ 1473 1475 TiXmlHandle Child( int index ) const; 1474 /** Return a handle to the "index" child element with the given name. 1476 /** Return a handle to the "index" child element with the given name. 1475 1477 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1476 1478 are indexed: other types are not counted. 1477 1479 */ 1478 1480 TiXmlHandle ChildElement( const char* value, int index ) const; 1479 /** Return a handle to the "index" child element. 1481 /** Return a handle to the "index" child element. 1480 1482 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1481 1483 are indexed: other types are not counted. … … 1492 1494 1493 1495 /// Return the handle as a TiXmlNode. This may return null. 1494 TiXmlNode* Node() const { return node; } 1496 TiXmlNode* Node() const { return node; } 1495 1497 /// Return the handle as a TiXmlElement. This may return null. 1496 1498 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } -
branches/std/src/lib/particles/spark_particles.cc
r7193 r7203 68 68 { 69 69 this->setClassID(CL_SPARK_PARTICLES, "SparkParticles"); 70 71 this->material = NULL;72 70 } 73 71 -
branches/std/src/lib/sound/ogg_player.cc
r6987 r7203 31 31 * @param fileName the file to load 32 32 */ 33 OggPlayer::OggPlayer(const char*fileName)33 OggPlayer::OggPlayer(const std::string& fileName) 34 34 { 35 35 this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer"); … … 40 40 this->buffers[1] = 0; 41 41 42 if ( fileName != NULL)42 if (!fileName.empty()) 43 43 { 44 44 if (this->open(fileName)) … … 56 56 * @param fileName the file to open 57 57 */ 58 bool OggPlayer::open(const char*fileName)58 bool OggPlayer::open(const std::string& fileName) 59 59 { 60 60 if (this->buffers[0] == 0) … … 72 72 int result; 73 73 74 if(!(oggFile = fopen(fileName , "rb")))74 if(!(oggFile = fopen(fileName.c_str(), "rb"))) 75 75 { 76 76 PRINTF(2)("Could not open Ogg file."); -
branches/std/src/lib/sound/ogg_player.h
r7054 r7203 27 27 { 28 28 public: 29 OggPlayer(const char*fileName = NULL);29 OggPlayer(const std::string& fileName = NULL); 30 30 virtual ~OggPlayer(); 31 31 32 bool open(const char*fileName);32 bool open(const std::string& fileName); 33 33 void release(); 34 34 void debug(); -
branches/std/src/lib/sound/sound_buffer.cc
r6836 r7203 32 32 * @param fileName The name of the File 33 33 */ 34 SoundBuffer::SoundBuffer(const char*fileName)34 SoundBuffer::SoundBuffer(const std::string& fileName) 35 35 { 36 36 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); … … 54 54 * @returns true on success. 55 55 */ 56 bool SoundBuffer::loadWAV(const char*fileName)56 bool SoundBuffer::loadWAV(const std::string& fileName) 57 57 { 58 58 SDL_AudioSpec wavSpec; … … 61 61 62 62 /* Load the WAV */ 63 if( SDL_LoadWAV(fileName , &wavSpec, &wavBuffer, &wavLength) == NULL)63 if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL) 64 64 { 65 PRINTF(2)("Could not open %s: %s\n", fileName , SDL_GetError());65 PRINTF(2)("Could not open %s: %s\n", fileName.c_str(), SDL_GetError()); 66 66 return false; 67 67 } -
branches/std/src/lib/sound/sound_buffer.h
r6981 r7203 17 17 { 18 18 public: 19 SoundBuffer(const char*fileName);19 SoundBuffer(const std::string& fileName); 20 20 virtual ~SoundBuffer(); 21 21 22 bool loadWAV(const char*fileName);22 bool loadWAV(const std::string& fileName); 23 23 24 24 /** @returns the ID of the buffer used in this SoundBuffer */ -
branches/std/src/lib/sound/sound_engine.cc
r7193 r7203 99 99 void SoundEngine::loadSettings(IniParser* iniParser) 100 100 { 101 const char*channels = iniParser->getVar(CONFIG_NAME_AUDIO_CHANNELS, CONFIG_SECTION_AUDIO, "32");102 this->maxSourceCount = atoi(channels);103 104 const char*effectsVolume = iniParser->getVar(CONFIG_NAME_EFFECTS_VOLUME, CONFIG_SECTION_AUDIO, "80");105 this->effectsVolume = atof(effectsVolume)/100.0;106 107 const char*musicVolume = iniParser->getVar(CONFIG_NAME_MUSIC_VOLUME, CONFIG_SECTION_AUDIO, "75");108 this->musicVolume = atof(musicVolume)/100.0;101 MultiType channels = iniParser->getVar(CONFIG_NAME_AUDIO_CHANNELS, CONFIG_SECTION_AUDIO, "32"); 102 this->maxSourceCount = channels.getInt(); 103 104 MultiType effectsVolume = iniParser->getVar(CONFIG_NAME_EFFECTS_VOLUME, CONFIG_SECTION_AUDIO, "80"); 105 this->effectsVolume = effectsVolume.getFloat()/100.0; 106 107 MultiType musicVolume = iniParser->getVar(CONFIG_NAME_MUSIC_VOLUME, CONFIG_SECTION_AUDIO, "75"); 108 this->musicVolume = musicVolume.getFloat()/100.0; 109 109 } 110 110 -
branches/std/src/lib/util/executor/executor.cc
r7201 r7203 105 105 value[4] = &value4; 106 106 107 printf("%s ::: paramCount: %d\n", this->getName(), this->paramCount);108 107 for (unsigned int i = 0; i < this->paramCount; i++) 109 108 { 110 109 if (*value[i] != MT_NULL) 111 110 { 112 printf("1:::: %d : %s \n",i, MultiType::MultiTypeToString(this->defaultValue[i].getType())); 113 114 this->defaultValue[i].debug(); 115 //this->defaultValue[i].setValueOf(*value[i]); 116 //printf("2::::%s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType())); 117 //this->defaultValue[i].debug(); 118 //this->defaultValue[i].setValueOf(*value[i]); 111 this->defaultValue[i].setValueOf(*value[i]); 119 112 } 120 113 } -
branches/std/src/lib/util/executor/executor.h
r7200 r7203 87 87 #define l_FLOAT_DEFGRAB(i) this->defaultValue[i].getFloat() 88 88 //! where to chek for default STRING values 89 #define l_STRING_DEFGRAB(i) this->defaultValue[i].getString() 90 //! where to chek for default CSTRING values 89 91 #define l_CSTRING_DEFGRAB(i) this->defaultValue[i].getCString() 90 92 … … 268 270 virtual void execute (BaseObject* object, const void* parameters = NULL) 269 271 { 270 SubString sub(( const char*) parameters, " \n\t,", '\\');271 printf("%s :: %s\n", this->getName(), ( const char*) parameters);272 SubString sub(((const std::string*) parameters)->c_str(), " \n\t,", '\\'); 273 printf("%s :: %s\n", this->getName(), ((const std::string*) parameters)->c_str()); 272 274 //! FUNCTOR_LIST is the List of Executive Functions 273 275 #define FUNCTOR_LIST(x) ExecutorExecute ## x -
branches/std/src/lib/util/executor/functor_list.h
r7199 r7203 75 75 76 76 #define l_CSTRING_TYPE const char* //!< The type of a STRING 77 #define l_CSTRING_FUNC is String//!< The function to parse a STRING78 #define l_CSTRING_NAME " string"//!< The name of a STRING77 #define l_CSTRING_FUNC isCString //!< The function to parse a STRING 78 #define l_CSTRING_NAME "cstring" //!< The name of a STRING 79 79 #define l_CSTRING_PARAM MT_STRING //!< the type of the parameter STRING 80 80 #define l_CSTRING_DEFAULT "" //!< a default Value for an STRING … … 98 98 99 99 FUNCTOR_LIST(0)(); 100 //! makes functions with one cstring 101 FUNCTOR_LIST(1)(l_CSTRING); 102 //! makes functions with two cstrings 103 FUNCTOR_LIST(2)(l_CSTRING, l_CSTRING); 104 //! makes functions with three cstrings 105 FUNCTOR_LIST(3)(l_CSTRING, l_CSTRING, l_CSTRING); 106 //! makes functions with four cstrings 107 FUNCTOR_LIST(4)(l_CSTRING, l_CSTRING, l_CSTRING, l_CSTRING); 108 100 109 //! makes functions with one string 101 FUNCTOR_LIST(1)(l_ CSTRING);110 FUNCTOR_LIST(1)(l_STRING); 102 111 //! makes functions with two strings 103 FUNCTOR_LIST(2)(l_ CSTRING, l_CSTRING);112 FUNCTOR_LIST(2)(l_STRING, l_STRING); 104 113 //! makes functions with three strings 105 FUNCTOR_LIST(3)(l_ CSTRING, l_CSTRING, l_CSTRING);114 FUNCTOR_LIST(3)(l_STRING, l_STRING, l_STRING); 106 115 //! makes functions with four strings 107 FUNCTOR_LIST(4)(l_CSTRING, l_CSTRING, l_CSTRING, l_CSTRING); 116 FUNCTOR_LIST(4)(l_STRING, l_STRING, l_STRING, l_STRING); 117 108 118 109 119 //! makes functions with one bool -
branches/std/src/lib/util/helper_functions.cc
r5331 r7203 22 22 23 23 /** 24 * checks if the input was a bool24 * @brief checks if the input was a bool 25 25 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false(case-insensitive) 26 26 * @param defaultValue a default value that is set, if BOOL is corrupt … … 42 42 43 43 /** 44 * checks if the input was a int44 * @brief checks if the input was a int 45 45 * @param INT a String that holds an int. 46 46 * @param defaultValue a default value that is set, if INT is corrupt … … 63 63 64 64 /** 65 * checks if the input was a float65 * @brief checks if the input was a float 66 66 * @param FLOAT a String that holds an float. 67 67 * @param defaultValue a default value that is set, if FLOAT is corrupt … … 83 83 84 84 /** 85 * checks if the input was a string85 * @brief checks if the input was a string 86 86 * @param STING a String(char-array) that holds an string. 87 87 * @param defaultValue a default value that is set, if STRING is corrupt 88 88 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 89 89 */ 90 const char* is String(const char* STRING, const char* defaultValue)90 const char* isCString(const char* STRING, const char* defaultValue) 91 91 { 92 92 if (STRING != NULL && strlen(STRING) > 0) … … 95 95 return defaultValue; 96 96 } 97 98 /** 99 * @brief checks if the input was a string 100 * @param STING a String(char-array) that holds an string. 101 * @param defaultValue a default value that is set, if STRING is corrupt 102 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 103 */ 104 std::string isString(const char* STRING, const std::string& defaultValue) 105 { 106 if (STRING != NULL && strlen(STRING) > 0) 107 return STRING; 108 else 109 return defaultValue; 110 } 111 112 113 /** 114 * @brief compares two strings without ignoring the case 115 * @param s1 first string 116 * @param s2 second string 117 */ 118 int nocase_cmp(const std::string& s1, const std::string& s2) 119 { 120 std::string::const_iterator it1=s1.begin(); 121 std::string::const_iterator it2=s2.begin(); 122 123 //stop when either string's end has been reached 124 while ( (it1!=s1.end()) && (it2!=s2.end()) ) 125 { 126 if(::toupper(*it1) != ::toupper(*it2)) //letters differ? 127 // return -1 to indicate smaller than, 1 otherwise 128 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 129 //proceed to the next character in each string 130 ++it1; 131 ++it2; 132 } 133 size_t size1=s1.size(), size2=s2.size();// cache lengths 134 //return -1,0 or 1 according to strings' lengths 135 if (size1==size2) 136 return 0; 137 return (size1<size2) ? -1 : 1; 138 } 139 -
branches/std/src/lib/util/helper_functions.h
r5141 r7203 6 6 #ifndef _HELPER_FUNCTIONS_H 7 7 #define _HELPER_FUNCTIONS_H 8 9 #include <string> 8 10 9 11 // FORWARD DECLARATION … … 15 17 int isInt(const char* INT, int defaultValue); 16 18 float isFloat(const char* FLOAT, float defaultValue); 17 const char* isString(const char* STRING, const char* defaultValue); 19 const char* isCString(const char* STRING, const char* defaultValue); 20 std::string isString(const char* STRING, const std::string& defaultValue); 21 22 23 int nocase_cmp(const std::string& s1, const std::string& s2); 24 18 25 19 26 #endif /* _HELPER_FUNCTIONS_H */ -
branches/std/src/lib/util/loading/game_loader.cc
r7193 r7203 86 86 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 87 87 */ 88 ErrorMessage GameLoader::loadCampaign(const char*fileName)88 ErrorMessage GameLoader::loadCampaign(const std::string& fileName) 89 89 { 90 90 ErrorMessage errorCode; 91 char*campaignName = ResourceManager::getFullName(fileName);92 if ( campaignName)91 std::string campaignName = ResourceManager::getFullName(fileName); 92 if (!campaignName.empty()) 93 93 { 94 94 this->currentCampaign = this->fileToCampaign(campaignName); 95 delete[] campaignName;96 95 } 97 96 } … … 105 104 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 106 105 */ 107 ErrorMessage GameLoader::loadNetworkCampaign(const char*fileName)106 ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName) 108 107 { 109 108 ErrorMessage errorCode; 110 char*campaignName = ResourceManager::getFullName(fileName);111 if ( campaignName)109 std::string campaignName = ResourceManager::getFullName(fileName); 110 if (!campaignName.empty()) 112 111 { 113 112 this->currentCampaign = this->fileToCampaign(campaignName); 114 delete[] campaignName;115 113 } 116 114 } … … 220 218 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 221 219 */ 222 Campaign* GameLoader::fileToCampaign(const char*fileName)220 Campaign* GameLoader::fileToCampaign(const std::string& fileName) 223 221 { 224 222 /* do not entirely load the campaign. just the current world … … 227 225 */ 228 226 229 if( fileName == NULL)227 if( fileName.empty()) 230 228 { 231 229 PRINTF(2)("No filename specified for loading"); … … 233 231 } 234 232 235 TiXmlDocument * XMLDoc = new TiXmlDocument(fileName);233 TiXmlDocument XMLDoc(fileName); 236 234 // load the campaign document 237 if( !XMLDoc ->LoadFile())235 if( !XMLDoc.LoadFile(fileName)) 238 236 { 239 237 // report an error 240 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 241 delete XMLDoc; 238 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 242 239 return NULL; 243 240 } 244 241 245 242 // check basic validity 246 TiXmlElement* root = XMLDoc ->RootElement();243 TiXmlElement* root = XMLDoc.RootElement(); 247 244 assert( root != NULL); 248 245 … … 251 248 // report an error 252 249 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 253 delete XMLDoc;254 250 return NULL; 255 251 } 256 252 257 253 // construct campaign 258 Campaign* c = new Campaign( root); 259 260 // free the XML data 261 delete XMLDoc; 262 263 return c; 254 return new Campaign( root); 264 255 } 265 256 -
branches/std/src/lib/util/loading/game_loader.h
r6981 r7203 44 44 static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; } 45 45 46 ErrorMessage loadCampaign(const char*name);46 ErrorMessage loadCampaign(const std::string& name); 47 47 ErrorMessage loadDebugCampaign(Uint32 campaignID); 48 ErrorMessage loadNetworkCampaign(const char*fileName);48 ErrorMessage loadNetworkCampaign(const std::string& fileName); 49 49 50 50 ErrorMessage init(); … … 62 62 GameLoader (); 63 63 64 Campaign* fileToCampaign(const char*name);64 Campaign* fileToCampaign(const std::string& name); 65 65 66 66 -
branches/std/src/lib/util/loading/load_param.cc
r7201 r7203 28 28 * @param executor the Executor, that executes the loading procedure. 29 29 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const char*paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)31 { 32 this->paramName = paramName; 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, const Executor& executor, bool inLoadCycle) 31 : paramName(paramName), object(object) 32 { 33 33 this->object = object; 34 34 this->inLoadCycle = inLoadCycle; … … 37 37 if (likely(!inLoadCycle)) 38 38 this->loadElem = grabParameterElement(root, paramName); 39 //this->loadString = grabParameter(root, paramName); 40 else if (!strcmp(root->Value(), paramName)) 39 else if (paramName == root->Value()) 41 40 this->loadElem = (TiXmlElement*)root->FirstChild(); 42 41 else … … 46 45 this->executor = executor.clone(); 47 46 48 if (this->executor)49 this->executor->setName(paramName);47 //if (this->executor) 48 // this->executor->setName(paramName); 50 49 } 51 50 … … 60 59 if (likely(this->executor != NULL)) 61 60 { 61 std::string loadString; 62 62 if (this->loadElem != NULL && this->loadElem->ToText()) 63 this->loadString = this->loadElem->Value(); 64 else 65 this->loadString = NULL; 63 loadString = this->loadElem->Value(); 66 64 if (likely(this->object != NULL) && 67 ( this->loadString != NULL||65 ( !loadString.empty() || 68 66 ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString))) 69 67 { 70 PRINTF(4)("Loading '%s' with Parameters '%s' onto: '%s'(%s)\n", this->paramName, this->loadString, this->object->getName(), this->object->getClassName());71 this->executor->execute(this->object, this->loadString);68 PRINTF(4)("Loading '%s' with Parameters '%s' onto: '%s'(%s)\n", this->paramName, loadString, this->object->getName(), this->object->getClassName()); 69 this->executor->execute(this->object, &loadString); 72 70 } 73 71 delete this->executor; … … 99 97 * @returns a pointer to itself. 100 98 */ 101 CLoadParam& CLoadParam::describe(const char*descriptionText)102 { 103 if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())99 CLoadParam& CLoadParam::describe(const std::string& descriptionText) 100 { 101 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 104 102 { 105 103 this->paramDesc->setDescription(descriptionText); … … 230 228 * @returns the Value of the parameter if found, NULL otherwise 231 229 */ 232 const char* grabParameter(const TiXmlElement* root, const char*parameterName)230 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName) 233 231 { 234 232 const TiXmlElement* element; 235 233 const TiXmlNode* node; 236 234 237 if (root == NULL || parameterName == NULL)235 if (root == NULL) 238 236 return NULL; 239 assert( parameterName != NULL);240 237 241 238 element = root->FirstChildElement( parameterName); … … 256 253 * @returns the Element of the parameter if found, NULL otherwise 257 254 */ 258 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char*parameterName)255 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName) 259 256 { 260 257 const TiXmlElement* element; 261 258 const TiXmlNode* node; 262 259 263 if (root == NULL || parameterName == NULL)260 if (root == NULL) 264 261 return NULL; 265 assert( parameterName != NULL);266 262 267 263 element = root->FirstChildElement( parameterName); -
branches/std/src/lib/util/loading/load_param.h
r7198 r7203 87 87 { 88 88 public: 89 CLoadParam(const TiXmlElement* root, const char*paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false);89 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false); 90 90 virtual ~CLoadParam(); 91 91 92 CLoadParam& describe(const char*descriptionText);92 CLoadParam& describe(const std::string& descriptionText); 93 93 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 94 94 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 95 95 const MultiType& value4 = MT_NULL); 96 CLoadParam& attribute(const char*attributeName, const Executor& executor);96 CLoadParam& attribute(const std::string& attributeName, const Executor& executor); 97 97 98 98 … … 101 101 Executor* executor; 102 102 BaseObject* object; 103 const char*paramName;103 const std::string paramName; 104 104 105 105 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter 106 106 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 107 107 const TiXmlElement* loadElem; //!< The Element to load. 108 const char* loadString; //!< The string loaded by this LoadParam109 108 const void* pointerToParam; //!< A Pointer to a Parameter. 110 109 … … 114 113 // helper function 115 114 116 const char* grabParameter(const TiXmlElement* root, const char*parameterName);117 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char*parameterName);115 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); 116 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); 118 117 119 118 #endif /* _LOAD_PARAM_H */ -
branches/std/src/lib/util/loading/load_param_description.cc
r7130 r7203 22 22 * @param paramName the name of the parameter to load 23 23 */ 24 LoadParamDescription::LoadParamDescription(const char*paramName)24 LoadParamDescription::LoadParamDescription(const std::string& paramName) 25 25 { 26 26 this->types = NULL; 27 this->description = NULL;28 27 this->defaultValues = NULL; 29 this->paramName = new char[strlen(paramName)+1]; 30 strcpy(this->paramName, paramName); 28 this->paramName = paramName; 31 29 } 32 30 … … 46 44 delete[] this->types; 47 45 delete[] this->defaultValues; 48 delete[] this->paramName;49 delete[] this->description;50 46 } 51 47 … … 53 49 * @param descriptionText The text to set as a description for this Parameter 54 50 */ 55 void LoadParamDescription::setDescription(const char* descriptionText) 56 { 57 this->description = new char[strlen(descriptionText)+1]; 58 strcpy(this->description, descriptionText); 51 void LoadParamDescription::setDescription(const std::string& descriptionText) 52 { 53 this->description = descriptionText; 59 54 } 60 55 … … 64 59 void LoadParamDescription::print() const 65 60 { 66 PRINT(3)(" <%s>", this->paramName );61 PRINT(3)(" <%s>", this->paramName.c_str()); 67 62 for (int i = 0; i < this->paramCount; i++) 68 63 { … … 101 96 // } 102 97 } 103 PRINT(3)("</%s>", this->paramName );104 if ( this->description)105 PRINT(3)(" -- %s", this->description );98 PRINT(3)("</%s>", this->paramName.c_str()); 99 if (!this->description.empty()) 100 PRINT(3)(" -- %s", this->description.c_str()); 106 101 // default values 107 102 if (this->paramCount > 0) … … 213 208 while (it != this->paramList.end()) 214 209 { 215 if ( !strcmp((*it)->paramName, paramName))210 if ((*it)->paramName == paramName) 216 211 { 217 212 return NULL; -
branches/std/src/lib/util/loading/load_param_description.h
r7130 r7203 36 36 friend class LoadParam; 37 37 friend class LoadClassDescription; 38 39 LoadParamDescription(const char*paramName);38 public: 39 LoadParamDescription(const std::string& paramName); 40 40 ~LoadParamDescription(); 41 41 42 void setDescription(const char*descriptionText);42 void setDescription(const std::string& descriptionText); 43 43 /** @returns the descriptionString */ 44 const char*getDescription() { return this->description; };44 const std::string& getDescription() { return this->description; }; 45 45 46 46 void print() const; 47 47 48 49 char*paramName; //!< The name of the parameter.48 private: 49 std::string paramName; //!< The name of the parameter. 50 50 int paramCount; //!< The count of parameters. 51 51 int* types; //!< What kind of parameters does this function take ?? 52 char*description; //!< A longer description about this function.52 std::string description; //!< A longer description about this function. 53 53 char** defaultValues; //!< The 'Default Values'. @TODO MAKE THIS A MULTITYPE 54 54 }; … … 58 58 { 59 59 friend class CLoadParam; 60 60 public: 61 61 LoadClassDescription(const char* className); 62 62 ~LoadClassDescription(); … … 69 69 static void printAll(const char* fileName = NULL); 70 70 static std::list<const char*> searchClassWithShort(const char* classNameBegin); 71 // static const LoadParamDescription* getClass(const char* className);71 // static const LoadParamDescription* getClass(const char* className); 72 72 73 73 private: 74 74 static bool parametersDescription; //!< if parameter-description should be enabled. 75 75 static std::list<LoadClassDescription*>* classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded) -
branches/std/src/lib/util/loading/resource_manager.cc
r7199 r7203 60 60 61 61 this->dataDir = new char[3]; 62 strcpy(this->dataDir, "./");62 this->dataDir = "./"; 63 63 this->tryDataDir("./data"); 64 65 this->_cwd = NULL;66 64 } 67 65 … … 80 78 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 81 79 82 // deleting the Directorie Lists83 while (!this->imageDirs.empty())84 {85 delete[] this->imageDirs.back();86 this->imageDirs.pop_back();87 }88 89 delete[] this->dataDir;90 if (this->_cwd)91 delete[] this->_cwd;92 80 ResourceManager::singletonRef = NULL; 93 81 } … … 97 85 * @param dataDir the DataDirectory. 98 86 */ 99 bool ResourceManager::setDataDir(const char*dataDir)100 { 101 char*realDir = ResourceManager::homeDirCheck(dataDir);87 bool ResourceManager::setDataDir(const std::string& dataDir) 88 { 89 std::string realDir = ResourceManager::homeDirCheck(dataDir); 102 90 if (isDir(realDir)) 103 91 { 104 delete[] this->dataDir; 105 if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\') 92 if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\') 106 93 { 107 this->dataDir = new char[strlen(realDir)+1]; 108 strcpy(this->dataDir, realDir); 94 this->dataDir = realDir; 109 95 } 110 96 else 111 97 { 112 this->dataDir = new char[strlen(realDir)+2]; 113 strcpy(this->dataDir, realDir); 114 this->dataDir[strlen(realDir)] = '/'; 115 this->dataDir[strlen(realDir)+1] = '\0'; 98 this->dataDir = realDir; 99 this->dataDir += '/'; 116 100 } 117 delete[] realDir;118 101 return true; 119 102 } 120 103 else 121 104 { 122 PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir); 123 delete[] realDir; 105 PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir.c_str(), this->dataDir.c_str()); 124 106 return false; 125 107 } … … 132 114 * this is essentially the same as setDataDir, but it ommits the error-message 133 115 */ 134 bool ResourceManager::tryDataDir(const char*dataDir)135 { 136 char*realDir = ResourceManager::homeDirCheck(dataDir);116 bool ResourceManager::tryDataDir(const std::string& dataDir) 117 { 118 std::string realDir = ResourceManager::homeDirCheck(dataDir); 137 119 if (isDir(realDir)) 138 120 { 139 delete[] this->dataDir; 140 if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\') 121 if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\') 141 122 { 142 this->dataDir = new char[strlen(realDir)+1]; 143 strcpy(this->dataDir, realDir); 123 this->dataDir = realDir; 144 124 } 145 125 else 146 126 { 147 this->dataDir = new char[strlen(realDir)+2]; 148 strcpy(this->dataDir, realDir); 149 this->dataDir[strlen(realDir)] = '/'; 150 this->dataDir[strlen(realDir)+1] = '\0'; 127 this->dataDir = realDir; 128 this->dataDir += '/'; 151 129 } 152 delete[] realDir;153 130 return true; 154 131 } 155 delete[] realDir;156 132 return false; 157 133 } … … 162 138 * @param fileInside is iniside of the given directory. 163 139 */ 164 bool ResourceManager::verifyDataDir(const char*fileInside)140 bool ResourceManager::verifyDataDir(const std::string& fileInside) 165 141 { 166 142 bool retVal; 167 143 if (!isDir(this->dataDir)) 168 144 { 169 PRINTF(1)("%s is not a directory\n", this->dataDir); 170 return false; 171 } 172 173 char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1]; 174 sprintf(testFile, "%s%s", this->dataDir, fileInside); 145 PRINTF(1)("%s is not a directory\n", this->dataDir.c_str()); 146 return false; 147 } 148 149 std::string testFile = this->dataDir + fileInside; 175 150 retVal = isFile(testFile); 176 delete[] testFile;177 151 return retVal; 178 152 } … … 185 159 false otherwise 186 160 */ 187 bool ResourceManager::addImageDir(const char* imageDir) 188 { 189 if (imageDir == NULL) 190 return false; 191 192 char* newDir; 193 if (imageDir[strlen(imageDir)-1] == '/' || imageDir[strlen(imageDir)-1] == '\\') 194 { 195 newDir = new char[strlen(imageDir)+1]; 196 strcpy(newDir, imageDir); 197 } 198 else 199 { 200 newDir = new char[strlen(imageDir)+2]; 201 strcpy(newDir, imageDir); 202 newDir[strlen(imageDir)] = '/'; 203 newDir[strlen(imageDir)+1] = '\0'; 161 bool ResourceManager::addImageDir(const std::string& imageDir) 162 { 163 std::string newDir; 164 if (imageDir[imageDir.size()-1] == '/' || imageDir[imageDir.size()-1] == '\\') 165 { 166 newDir = imageDir; 167 } 168 else 169 { 170 newDir = imageDir; 171 newDir += '/'; 204 172 } 205 173 // check if the param is a Directory … … 207 175 { 208 176 // check if the Directory has been added before 209 std::vector< char*>::const_iterator imageDir;177 std::vector<std::string>::const_iterator imageDir; 210 178 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 211 179 { 212 if ( !strcmp(*imageDir, newDir))180 if (*imageDir == newDir) 213 181 { 214 PRINTF(3)("Path %s already loaded\n", newDir); 215 delete[] newDir; 182 PRINTF(3)("Path %s already loaded\n", newDir.c_str()); 216 183 return true; 217 184 } … … 223 190 else 224 191 { 225 PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir); 226 delete[] newDir; 192 PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir.c_str()); 227 193 return false; 228 194 } … … 239 205 * @returns a pointer to a desired Resource. 240 206 */ 241 BaseObject* ResourceManager::load(const char*fileName, ResourcePriority prio,207 BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio, 242 208 const MultiType& param0, const MultiType& param1, const MultiType& param2) 243 209 { 244 if (fileName == NULL)245 return NULL;246 210 ResourceType tmpType; 247 211 #ifndef NO_MODEL 248 212 #define __IF_OK 249 if (!strncasecmp(fileName +(strlen(fileName)-4), ".obj", 4))213 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4)) 250 214 tmpType = OBJ; 251 else if (!strncmp(fileName +(strlen(fileName)-4), ".md2", 4))215 else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4)) 252 216 tmpType = MD2; 253 else if (!strcasecmp(fileName , "cube") ||254 !strcasecmp(fileName, "sphere") ||255 !strcasecmp(fileName, "plane") ||256 !strcasecmp(fileName, "cylinder") ||257 !strcasecmp(fileName, "cone"))217 else if (!strcasecmp(fileName.c_str(), "cube") || 218 !strcasecmp(fileName.c_str(), "sphere") || 219 !strcasecmp(fileName.c_str(), "plane") || 220 !strcasecmp(fileName.c_str(), "cylinder") || 221 !strcasecmp(fileName.c_str(), "cone")) 258 222 tmpType = PRIM; 259 223 #endif /* NO_MODEL */ … … 263 227 #endif 264 228 #define __IF_OK 265 if (!strncasecmp(fileName +(strlen(fileName)-4), ".wav", 4))229 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4)) 266 230 tmpType = WAV; 267 else if (!strncasecmp(fileName +(strlen(fileName)-4), ".mp3", 4))231 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4)) 268 232 tmpType = MP3; 269 else if (!strncasecmp(fileName +(strlen(fileName)-4), ".ogg", 4))233 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4)) 270 234 tmpType = OGG; 271 235 #endif /* NO_AUDIO */ … … 275 239 #endif 276 240 #define __IF_OK 277 if (!strncasecmp(fileName +(strlen(fileName)-4), ".ttf", 4))241 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4)) 278 242 tmpType = TTF; 279 243 #endif /* NO_TEXT */ … … 283 247 #endif 284 248 #define __IF_OK 285 if (!strncasecmp(fileName +(strlen(fileName)-5), ".vert", 5))249 if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5)) 286 250 tmpType = SHADER; 287 251 #endif /* NO_SHADERS */ … … 308 272 * during the initialisation instead of at Runtime. 309 273 */ 310 bool ResourceManager::cache(const char*fileName, ResourceType type, ResourcePriority prio,274 bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio, 311 275 const MultiType& param0, const MultiType& param1, const MultiType& param2) 312 276 { 313 assert(fileName != NULL);314 315 277 // searching if the resource was loaded before. 316 278 Resource* tmpResource; … … 359 321 * @returns a pointer to a desired Resource. 360 322 */ 361 BaseObject* ResourceManager::load(const char*fileName, ResourceType type, ResourcePriority prio,323 BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio, 362 324 const MultiType& param0, const MultiType& param1, const MultiType& param2) 363 325 { 364 assert(fileName != NULL);365 366 326 // searching if the resource was loaded before. 367 327 Resource* tmpResource; … … 397 357 * @returns a pointer to a desired Resource. 398 358 */ 399 Resource* ResourceManager::loadResource(const char*fileName, ResourceType type, ResourcePriority prio,359 Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, 400 360 const MultiType& param0, const MultiType& param1, const MultiType& param2) 401 361 { … … 406 366 tmpResource->prio = prio; 407 367 tmpResource->pointer = NULL; 408 tmpResource->name = new char[strlen(fileName)+1]; 409 strcpy(tmpResource->name, fileName); 368 tmpResource->name = fileName; 410 369 411 370 // creating the full name. (directoryName + FileName) 412 char*fullName = ResourceManager::getFullName(fileName);371 std::string fullName = ResourceManager::getFullName(fileName); 413 372 // Checking for the type of resource \see ResourceType 414 373 switch(type) … … 425 384 else 426 385 { 427 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName , dataDir);386 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str()); 428 387 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat()); 429 388 } … … 435 394 tmpResource->param[0] = 1.0f; 436 395 437 if ( !strcmp(tmpResource->name, "cube"))396 if (tmpResource->name == "cube") 438 397 tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat()); 439 else if ( !strcmp(tmpResource->name, "sphere"))398 else if (tmpResource->name == "sphere") 440 399 tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat()); 441 else if ( !strcmp(tmpResource->name, "plane"))400 else if (tmpResource->name == "plane") 442 401 tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat()); 443 else if ( !strcmp(tmpResource->name, "cylinder"))402 else if (tmpResource->name == "cylinder") 444 403 tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat()); 445 else if ( !strcmp(tmpResource->name, "cone"))404 else if (tmpResource->name == "cone") 446 405 tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat()); 447 406 break; … … 468 427 tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt()); 469 428 else 470 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName , this->dataDir);429 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str()); 471 430 break; 472 431 #endif /* NO_TEXT */ … … 494 453 else 495 454 { 496 std::vector< char*>::iterator imageDir;455 std::vector<std::string>::iterator imageDir; 497 456 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 498 457 { 499 char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1]; 500 sprintf(imgName, "%s%s", *imageDir, fileName); 458 std::string imgName = *imageDir + fileName; 501 459 if(isFile(imgName)) 502 460 { 503 461 PRINTF(4)("Image %s resides to %s\n", fileName, imgName); 504 462 tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt()); 505 delete[] imgName;506 463 break; 507 464 } 508 delete[] imgName;509 465 } 510 466 } 511 467 if(!tmpResource) 512 PRINTF(2)("!!Image %s not Found!!\n", fileName );468 PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str()); 513 469 break; 514 470 #endif /* NO_TEXTURES */ … … 520 476 { 521 477 MultiType param = param0; /// HACK 522 char*secFullName = ResourceManager::getFullName(param.getCString());478 std::string secFullName = ResourceManager::getFullName(param.getCString()); 523 479 if (ResourceManager::isFile(secFullName)) 524 480 { … … 526 482 tmpResource->pointer = new Shader(fullName, secFullName); 527 483 } 528 delete[] secFullName;529 484 } 530 485 else … … 538 493 default: 539 494 tmpResource->pointer = NULL; 540 PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name );495 PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str()); 541 496 break; 542 497 } 543 498 if (tmpResource->pointer != NULL) 544 499 this->resourceList.push_back(tmpResource); 545 delete[] fullName;546 547 500 548 501 if (tmpResource->pointer != NULL) … … 550 503 else 551 504 { 552 PRINTF(2)("Resource %s could not be loaded\n", fileName); 553 delete[] tmpResource->name; 505 PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str()); 554 506 delete tmpResource; 555 507 return NULL; … … 597 549 delete resource->pointer; 598 550 // deleting the List Entry: 599 PRINTF(4)("Resource %s safely removed.\n", resource->name); 600 delete[] resource->name; 551 PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str()); 601 552 std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource); 602 553 this->resourceList.erase(resourceIT); … … 604 555 } 605 556 else 606 PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name , resource->count);607 } 608 else 609 PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name );557 PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count); 558 } 559 else 560 PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str()); 610 561 return true; 611 562 } … … 633 584 if (round == 3) 634 585 PRINTF(2)("unable to unload %s because there are still %d references to it\n", 635 this->resourceList[index]->name , this->resourceList[index]->count);586 this->resourceList[index]->name.c_str(), this->resourceList[index]->count); 636 587 removeCount++; 637 588 } … … 653 604 * @returns a Pointer to the Resource if found, NULL otherwise. 654 605 */ 655 Resource* ResourceManager::locateResourceByInfo(const char*fileName, ResourceType type,606 Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type, 656 607 const MultiType& param0, const MultiType& param1, const MultiType& param2) const 657 608 { … … 659 610 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++) 660 611 { 661 if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))612 if ((*resource)->type == type && fileName == (*resource)->name) 662 613 { 663 614 bool match = false; … … 743 694 } 744 695 745 char*ResourceManager::toResourcableString(unsigned int i)746 { 747 int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));748 len += strlen(this->resourceList[i]->name);696 std::string ResourceManager::toResourcableString(unsigned int i) 697 { 698 /* int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); 699 len += this->resourceList[i]->name.size(); 749 700 if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1; 750 701 if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1; 751 702 if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1; 752 703 len += 10; 753 char*tmp = new char[len];704 std::string tmp = new char[len]; 754 705 tmp[0] = '\0'; 755 strcat( 706 strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type)); 756 707 strcat(tmp,","); 757 708 strcat (tmp, this->resourceList[i]->name); … … 771 722 strcat( tmp, this->resourceList[i]->param[2].getCString()); 772 723 } 773 return tmp; 724 return tmp;*/ 774 725 } 775 726 … … 778 729 * @param resourceableString the String to cache the resource from. 779 730 */ 780 bool ResourceManager::fromResourceableString(const char*resourceableString)781 { 782 SubString splits(resourceableString, ',');731 bool ResourceManager::fromResourceableString(const std::string& resourceableString) 732 { 733 /* SubString splits(resourceableString, ','); 783 734 splits.debug(); 784 735 if (splits.getCount() == 2) … … 793 744 else if (splits.getCount() == 5) 794 745 return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]), 795 RP_LEVEL, splits[2], splits[3], splits[4]); 746 RP_LEVEL, splits[2], splits[3], splits[4]);*/ 796 747 } 797 748 … … 802 753 * @returns true if it is a directory/symlink false otherwise 803 754 */ 804 bool ResourceManager::isDir(const char* directoryName) 805 { 806 if (directoryName == NULL) 807 return false; 808 809 char* tmpDirName = NULL; 755 bool ResourceManager::isDir(const std::string& directoryName) 756 { 757 std::string tmpDirName = directoryName; 810 758 struct stat status; 811 759 812 760 // checking for the termination of the string given. If there is a "/" at the end cut it away 813 if (directoryName[strlen(directoryName)-1] == '/' || 814 directoryName[strlen(directoryName)-1] == '\\') 815 { 816 tmpDirName = new char[strlen(directoryName)]; 817 strncpy(tmpDirName, directoryName, strlen(directoryName)-1); 818 tmpDirName[strlen(directoryName)-1] = '\0'; 819 } 820 else 821 { 822 tmpDirName = new char[strlen(directoryName)+1]; 823 strcpy(tmpDirName, directoryName); 824 } 825 826 if(!stat(tmpDirName, &status)) 761 if (directoryName[directoryName.size()-1] == '/' || 762 directoryName[directoryName.size()-1] == '\\') 763 { 764 tmpDirName.erase(tmpDirName.size()-1); 765 } 766 767 if(!stat(tmpDirName.c_str(), &status)) 827 768 { 828 769 if (status.st_mode & (S_IFDIR … … 832 773 )) 833 774 { 834 delete[] tmpDirName;835 775 return true; 836 776 } 837 777 else 838 {839 delete[] tmpDirName;840 778 return false; 841 } 842 } 843 else 844 { 845 delete[] tmpDirName; 846 return false; 847 } 779 } 780 else 781 return false; 848 782 } 849 783 … … 853 787 * @returns true if it is a regular file/symlink, false otherwise 854 788 */ 855 bool ResourceManager::isFile(const char* fileName) 856 { 857 if (fileName == NULL) 858 return false; 859 char* tmpFileName = ResourceManager::homeDirCheck(fileName); 789 bool ResourceManager::isFile(const std::string& fileName) 790 { 791 std::string tmpFileName = ResourceManager::homeDirCheck(fileName); 860 792 // actually checks the File 861 793 struct stat status; 862 if (!stat(tmpFileName , &status))794 if (!stat(tmpFileName.c_str(), &status)) 863 795 { 864 796 if (status.st_mode & (S_IFREG … … 868 800 )) 869 801 { 870 delete[] tmpFileName;871 802 return true; 872 803 } 873 804 else 874 {875 delete[] tmpFileName;876 805 return false; 877 } 878 } 879 else 880 { 881 delete[] tmpFileName; 882 return false; 883 } 806 } 807 else 808 return false; 884 809 } 885 810 … … 888 813 * @param fileName The file to touch 889 814 */ 890 bool ResourceManager::touchFile(const char*fileName)891 { 892 char*tmpName = ResourceManager::homeDirCheck(fileName);893 if (tmpName == NULL)815 bool ResourceManager::touchFile(const std::string& fileName) 816 { 817 std::string tmpName = ResourceManager::homeDirCheck(fileName); 818 if (tmpName.empty()) 894 819 return false; 895 820 FILE* stream; 896 if( (stream = fopen (tmpName, "w")) == NULL) 897 { 898 PRINTF(1)("could not open %s fro writing\n", fileName); 899 delete[] tmpName; 821 if( (stream = fopen (tmpName.c_str(), "w")) == NULL) 822 { 823 PRINTF(1)("could not open %s fro writing\n", fileName.c_str()); 900 824 return false; 901 825 } 902 826 fclose(stream); 903 904 delete[] tmpName;905 827 } 906 828 … … 909 831 * @param fileName the File to delete 910 832 */ 911 bool ResourceManager::deleteFile(const char* fileName) 912 { 913 if (fileName == NULL) 914 return false; 915 char* tmpName = ResourceManager::homeDirCheck(fileName); 916 unlink(tmpName); 917 delete[] tmpName; 833 bool ResourceManager::deleteFile(const std::string& fileName) 834 { 835 std::string tmpName = ResourceManager::homeDirCheck(fileName); 836 unlink(tmpName.c_str()); 918 837 } 919 838 … … 923 842 * IMPORTANT: this has to be deleted from the outside 924 843 */ 925 char* ResourceManager::homeDirCheck(const char* name) 926 { 927 if (name == NULL) 928 return NULL; 929 char* retName; 930 if (!strncmp(name, "~/", 2)) 844 std::string ResourceManager::homeDirCheck(const std::string& name) 845 { 846 std::string retName; 847 if (!strncmp(name.c_str(), "~/", 2)) 931 848 { 932 849 char tmpFileName[500]; … … 936 853 strcpy(tmpFileName, getenv("HOME")); 937 854 #endif 938 retName = new char[strlen(tmpFileName)+strlen(name)]; 939 sprintf(retName, "%s%s", tmpFileName, name+1); 940 } 941 else 942 { 943 retName = new char[strlen(name)+1]; 944 strcpy(retName, name); 855 retName = tmpFileName + name; 856 } 857 else 858 { 859 retName = name; 945 860 } 946 861 return retName; … … 949 864 /** 950 865 * @param name the relative name of the File/Directory. 951 * @returns a new char* with the name in abs-dir-format 952 */ 953 char* ResourceManager::getAbsDir(const char* name) 954 { 955 if (name == NULL) 956 return NULL; 957 char* retName; 958 if (strncmp(name, "/", 1)) 959 { 960 if (*name == '.' && *(name+1) != '.') 961 name++; 962 const char* absDir = ResourceManager::cwd(); 963 retName = new char[strlen(absDir)+strlen(name)+1]; 964 sprintf(retName, "%s%s", absDir, name); 965 } 966 else 967 { 968 retName = new char[strlen(name)+1]; 969 strcpy(retName, name); 866 * @returns a new std::string with the name in abs-dir-format 867 */ 868 std::string ResourceManager::getAbsDir(const std::string& name) 869 { 870 if (name.empty()) 871 return ""; 872 std::string retName = name; 873 if (strncmp(name.c_str(), "/", 1)) 874 { 875 if (name[0] == '.' && name[1] != '.') 876 retName.erase(0); 877 const std::string& absDir = ResourceManager::cwd(); 878 retName = absDir + retName; 970 879 } 971 880 return retName; … … 978 887 * !!IMPORTANT: this has to be deleted from the outside!! 979 888 */ 980 char* ResourceManager::getFullName(const char*fileName)981 { 982 if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)889 std::string ResourceManager::getFullName(const std::string& fileName) 890 { 891 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) 983 892 return NULL; 984 893 985 char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir()) 986 + strlen(fileName) + 1]; 987 sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 894 std::string retName = ResourceManager::getInstance()->getDataDir() +fileName; 988 895 if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName)) 989 896 return retName; 990 897 else 991 {992 delete[] retName;993 898 return NULL; 994 }995 899 } 996 900 … … 1005 909 * @returns the Current Woring Directory 1006 910 */ 1007 const char*ResourceManager::cwd()1008 { 1009 if (ResourceManager::getInstance()->_cwd == NULL)911 const std::string& ResourceManager::cwd() 912 { 913 if (ResourceManager::getInstance()->_cwd.empty()) 1010 914 { 1011 915 char cwd[1024]; 1012 916 char* errorCode = getcwd(cwd, 1024); 1013 917 if (errorCode == 0) 1014 return NULL; 1015 1016 ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1]; 1017 strcpy(ResourceManager::getInstance()->_cwd, cwd); 918 return ResourceManager::getInstance()->_cwd; 919 920 ResourceManager::getInstance()->_cwd = cwd; 1018 921 } 1019 922 return ResourceManager::getInstance()->_cwd; … … 1026 929 * @returns true if the file exists, false otherwise 1027 930 */ 1028 bool ResourceManager::isInDataDir(const char*fileName)1029 { 1030 if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)931 bool ResourceManager::isInDataDir(const std::string& fileName) 932 { 933 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty()) 1031 934 return false; 1032 935 1033 936 bool retVal = false; 1034 char* checkFile = new char[strlen(ResourceManager::getInstance()->getDataDir()) 1035 + strlen(fileName) + 1]; 1036 sprintf(checkFile, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 937 std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName; 1037 938 1038 939 if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile)) … … 1040 941 else 1041 942 retVal = false; 1042 delete[] checkFile;1043 943 return retVal; 1044 944 } … … 1055 955 // if it is not initialized 1056 956 PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef); 1057 PRINT(0)(" Data-Directory is: %s\n", this->dataDir );957 PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str()); 1058 958 PRINT(0)(" List of Image-Directories: "); 1059 std::vector< char*>::const_iterator imageDir;959 std::vector<std::string>::const_iterator imageDir; 1060 960 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++) 1061 PRINT(0)("%s ", (*imageDir) );961 PRINT(0)("%s ", (*imageDir).c_str()); 1062 962 PRINT(0)("\n"); 1063 963 … … 1068 968 { 1069 969 PRINT(0)("-----------------------------------------\n"); 1070 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name , (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));970 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type)); 1071 971 1072 972 PRINT(0)("gets deleted at "); -
branches/std/src/lib/util/loading/resource_manager.h
r7196 r7203 71 71 unsigned int count; //!< How many times this Resource has been loaded. 72 72 73 char*name; //!< Name of the Resource.73 std::string name; //!< Name of the Resource. 74 74 ResourceType type; //!< ResourceType of this Resource. 75 75 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) … … 96 96 inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager(); return singletonRef; }; 97 97 98 bool setDataDir(const char*dataDir);98 bool setDataDir(const std::string& dataDir); 99 99 /** @returns the Name of the data directory */ 100 inline const char*getDataDir() const { return this->dataDir; };100 inline const std::string& getDataDir() const { return this->dataDir; }; 101 101 102 102 103 bool tryDataDir(const char*dataDir);104 bool verifyDataDir(const char*fileInside);105 bool addImageDir(const char*imageDir);103 bool tryDataDir(const std::string& dataDir); 104 bool verifyDataDir(const std::string& fileInside); 105 bool addImageDir(const std::string& imageDir); 106 106 107 bool cache(const char*fileName, ResourceType type, ResourcePriority prio = RP_NO,107 bool cache(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO, 108 108 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 109 109 BaseObject* copy(BaseObject* resourcePointer); 110 110 111 BaseObject* load(const char*fileName, ResourcePriority prio = RP_NO,111 BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO, 112 112 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 113 BaseObject* load(const char*fileName, ResourceType type, ResourcePriority prio = RP_NO,113 BaseObject* load(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO, 114 114 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 115 115 bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO); … … 117 117 bool unloadAllByPriority(ResourcePriority prio); 118 118 119 Resource* locateResourceByInfo(const char*fileName, ResourceType type,119 Resource* locateResourceByInfo(const std::string& fileName, ResourceType type, 120 120 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const; 121 121 Resource* locateResourceByPointer(const void* pointer) const; 122 122 123 char*toResourcableString(unsigned int i);124 bool fromResourceableString(const char*resourceableString);123 std::string toResourcableString(unsigned int i); 124 bool fromResourceableString(const std::string& resourceableString); 125 125 /** @returns the Count of Resources the ResourceManager handles */ 126 126 unsigned int resourceCount() const { return this->resourceList.size(); } … … 130 130 131 131 // utility functions for handling files in and around the data-directory 132 static bool isDir(const char*directory);133 static bool isFile(const char*fileName);134 static bool touchFile(const char*fileName);135 static bool deleteFile(const char*fileName);136 static char* homeDirCheck(const char*fileName);137 static char* getFullName(const char*fileName);138 static bool isInDataDir(const char*fileName);139 static char* getAbsDir(const char*fileName);140 static const char*cwd();132 static bool isDir(const std::string& directory); 133 static bool isFile(const std::string& fileName); 134 static bool touchFile(const std::string& fileName); 135 static bool deleteFile(const std::string& fileName); 136 static std::string homeDirCheck(const std::string& fileName); 137 static std::string getFullName(const std::string& fileName); 138 static bool isInDataDir(const std::string& fileName); 139 static std::string getAbsDir(const std::string& fileName); 140 static const std::string& cwd(); 141 141 142 142 static const char* ResourceTypeToChar(ResourceType type); … … 145 145 private: 146 146 ResourceManager(); 147 Resource* loadResource(const char*fileName, ResourceType type, ResourcePriority prio,147 Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, 148 148 const MultiType& param0, const MultiType& param1, const MultiType& param2); 149 149 150 150 private: 151 static ResourceManager* singletonRef; //!< singleton Reference151 static ResourceManager* singletonRef; //!< singleton Reference 152 152 153 char*_cwd; //!< The currend Working directory.154 char*dataDir; //!< The Data Directory, where all relevant Data is stored.155 std::vector< char*>imageDirs; //!< A list of directories in which images are stored.153 std::string _cwd; //!< The currend Working directory. 154 std::string dataDir; //!< The Data Directory, where all relevant Data is stored. 155 std::vector<std::string> imageDirs; //!< A list of directories in which images are stored. 156 156 157 std::vector<Resource*> resourceList; //!< The List of Resources, that has already been loaded.157 std::vector<Resource*> resourceList; //!< The List of Resources, that has already been loaded. 158 158 159 static const char* resourceNames[RESOURCE_TYPE_SIZE];159 static const char* resourceNames[RESOURCE_TYPE_SIZE]; 160 160 }; 161 161 -
branches/std/src/orxonox.cc
r7193 r7203 86 86 this->port = -1; 87 87 88 this->configFileName = NULL;88 this->configFileName = ""; 89 89 } 90 90 … … 117 117 // orxonox class-stuff 118 118 delete this->iniParser; 119 delete[] this->configFileName;120 119 121 120 SDL_QuitSubSystem(SDL_INIT_TIMER); … … 162 161 163 162 /** 164 * this finds the config file163 * @brief this finds the config file 165 164 * @returns the new config-fileName 166 165 * Since the config file varies from user to user and since one may want to specify different config files … … 168 167 * it's path and name into configfilename 169 168 */ 170 const char*Orxonox::getConfigFile ()169 const std::string& Orxonox::getConfigFile () 171 170 { 172 171 if (ResourceManager::isFile("orxonox.conf")) 173 172 { 174 this->configFileName = new char[strlen("orxonox.conf")+1]; 175 strcpy(this->configFileName, "orxonox.conf"); 173 this->configFileName = "orxonox.conf"; 176 174 } 177 175 else … … 231 229 GraphicsEngine::getInstance()->initFromIniFile(this->iniParser); 232 230 233 char*iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");234 if ( iconName != NULL)231 std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp"); 232 if (!iconName.empty()) 235 233 { 236 234 GraphicsEngine::getInstance()->setWindowName(PACKAGE_NAME " " PACKAGE_VERSION, iconName); 237 delete[] iconName;238 235 } 239 236 return 0; … … 301 298 302 299 // init the resource manager 303 const char*dataPath;304 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL)300 std::string dataPath; 301 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= "") 305 302 { 306 303 if (!ResourceManager::getInstance()->setDataDir(dataPath) && 307 304 !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE)) 308 305 { 309 PRINTF(1)("Data Could not be located in %s\n", dataPath );306 PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); 310 307 } 311 308 } … … 315 312 PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ 316 313 "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", 317 ResourceManager::getInstance()->getDataDir(),318 this->configFileName,314 ResourceManager::getInstance()->getDataDir().c_str(), 315 this->configFileName.c_str(), 319 316 CONFIG_SECTION_DATA, 320 317 CONFIG_NAME_DATADIR ); … … 325 322 } 326 323 //! @todo this is a hack and should be loadable 327 char*imageDir = ResourceManager::getInstance()->getFullName("maps");324 std::string imageDir = ResourceManager::getInstance()->getFullName("maps"); 328 325 ResourceManager::getInstance()->addImageDir(imageDir); 329 delete[] imageDir;330 326 imageDir = ResourceManager::getInstance()->getFullName("pictures"); 331 327 ResourceManager::getInstance()->addImageDir(imageDir); 332 delete[] imageDir;333 328 334 329 DynamicLoader::loadDyLib("libtest.so"); -
branches/std/src/orxonox.h
r5996 r7203 41 41 int initMisc (); 42 42 43 const char*getConfigFile ();43 const std::string& getConfigFile (); 44 44 45 45 private: … … 47 47 48 48 IniParser* iniParser; //!< Reference to the ini-parser used in orxonox 49 char*configFileName; //!< Filename of the configuration-file.49 std::string configFileName; //!< Filename of the configuration-file. 50 50 GameLoader* gameLoader; //!< The gameLoader 51 51 -
branches/std/src/story_entities/game_world.cc
r7193 r7203 145 145 GameLoader* loader = GameLoader::getInstance(); 146 146 147 if( getLoadFile() == NULL)147 if( getLoadFile().empty()) 148 148 { 149 149 PRINTF(1)("GameWorld has no path specified for loading\n"); … … 155 155 if( !XMLDoc->LoadFile()) 156 156 { 157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile() , XMLDoc->ErrorRow(), XMLDoc->ErrorCol());157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getLoadFile().c_str(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 158 158 delete XMLDoc; 159 159 return (ErrorMessage){213,"XML File parsing error","GameWorld::load()"}; -
branches/std/src/story_entities/game_world_data.cc
r7193 r7203 129 129 // load the parameters 130 130 // name 131 const char*string = grabParameter( root, "name");132 if( string == NULL)131 std::string string = grabParameter( root, "name"); 132 if( string.empty() ) 133 133 { 134 134 PRINTF(2)("GameWorld is missing a proper 'name'\n"); … … 136 136 } 137 137 else 138 this->setName(string );138 this->setName(string.c_str()); 139 139 140 140 this->loadGUI(root); … … 363 363 { 364 364 PRINTF(3)("Setting Sound Track to %s\n", name); 365 char* oggFile = ResourceManager::getFullName(name); /// FIXME365 std::string oggFile = ResourceManager::getFullName(name); 366 366 this->music = new OggPlayer(oggFile); 367 delete[] oggFile;368 367 369 368 //(OggPlayer*)ResourceManager::getInstance()->load(name, OGG, RP_LEVEL); -
branches/std/src/story_entities/story_entity.cc
r7193 r7203 40 40 this->isRunning = false; 41 41 42 this->loadFile = NULL;42 this->loadFile = ""; 43 43 this->storyID = -1; 44 44 this->description = NULL; … … 100 100 * @param name the name of the path 101 101 */ 102 void StoryEntity::setLoadFile(const char* fileName) 103 { 104 if (this->loadFile) 105 delete this->loadFile; 102 void StoryEntity::setLoadFile(const std::string& fileName) 103 { 106 104 if (ResourceManager::isFile(fileName)) 107 105 { 108 this->loadFile = new char[strlen(fileName)+1]; 109 strcpy(this->loadFile, fileName); 106 this->loadFile = fileName; 110 107 } 111 108 else … … 149 146 { 150 147 PRINTF(3)("Grabbing the Worlds Settings\n", this->getLoadFile()); 151 if( getLoadFile() == NULL)152 return;148 if( getLoadFile().empty()) 149 return; 153 150 TiXmlDocument XMLDoc(this->getLoadFile()); 154 151 // load the xml world file for further loading 155 152 if( !XMLDoc.LoadFile()) 156 153 { 157 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile() , XMLDoc.ErrorRow(), XMLDoc.ErrorCol());154 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile().c_str(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); 158 155 return; 159 156 } -
branches/std/src/story_entities/story_entity.h
r6993 r7203 61 61 inline int getStoryID() { return this->storyID; } 62 62 63 void setLoadFile( const char*fileName);63 void setLoadFile(const std::string& fileName); 64 64 /** @returns the Filename this StoryEntity was loaded with */ 65 const char*getLoadFile() const { return this->loadFile; }65 const std::string& getLoadFile() const { return this->loadFile; } 66 66 67 67 void setNextStoryID(int nextStoryID); … … 86 86 87 87 protected: 88 bool isInit; //!< if the entity is initialized, this has to be true.89 bool isRunning; //!< is true if the entity is running90 bool isPaused; //!< is true if the entity is paused88 bool isInit; //!< if the entity is initialized, this has to be true. 89 bool isRunning; //!< is true if the entity is running 90 bool isPaused; //!< is true if the entity is paused 91 91 92 92 93 93 private: 94 int storyID; //!< this is the number of this entity, identifying it in a list/tree...95 int nextStoryID; //!< if this entity has finished, this entity shall be called96 char*loadFile; //!< The file from which this world is loaded94 int storyID; //!< this is the number of this entity, identifying it in a list/tree... 95 int nextStoryID; //!< if this entity has finished, this entity shall be called 96 std::string loadFile; //!< The file from which this world is loaded 97 97 98 char* description; //!< the description of the StoryEntity99 char* menuItemImage; //!< the item image of the StoryEntity100 char* menuScreenshoot; //!< the screenshoot of the StoryEntity101 bool bMenuEntry; //!< If true, this GameWorld apears in the SimpleMenu: SimpleMenu specific98 char* description; //!< the description of the StoryEntity 99 char* menuItemImage; //!< the item image of the StoryEntity 100 char* menuScreenshoot; //!< the screenshoot of the StoryEntity 101 bool bMenuEntry; //!< If true, this GameWorld apears in the SimpleMenu: SimpleMenu specific 102 102 }; 103 103 -
branches/std/src/world_entities/terrain.cc
r7193 r7203 146 146 this->heightMap = NULL; 147 147 148 char*hmName = ResourceManager::getFullName(heightMapFile);149 char*hmColorName = ResourceManager::getFullName(colorMap);148 std::string hmName = ResourceManager::getFullName(heightMapFile); 149 std::string hmColorName = ResourceManager::getFullName(colorMap); 150 150 151 151 … … 155 155 heightMap->setAbsCoor(this->getAbsCoor()); 156 156 heightMap->load(); 157 delete[] hmName;158 delete[] hmColorName;159 160 157 } 161 158 -
branches/std/src/world_entities/world_entity.cc
r7198 r7203 575 575 char* name = (char*)(getModel( 0 )->getName()); 576 576 577 if ( strstr(name, ResourceManager::getInstance()->getDataDir()))578 { 579 name += strlen(ResourceManager::getInstance()->getDataDir());577 if ( ResourceManager::getInstance()->getDataDir() == name ) /// FIXME (do not know what to do here.) 578 { 579 name += ResourceManager::getInstance()->getDataDir().size(); 580 580 } 581 581
Note: See TracChangeset
for help on using the changeset viewer.