Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7221 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Mar 15, 2006, 3:10:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

Location:
trunk/src/lib
Files:
103 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/Makefile.am

    r7193 r7221  
    5555
    5656SUBDIRS = \
     57        . \
    5758        math \
    5859        graphics \
     
    6566        parser \
    6667        shell \
    67         gui \
    68         .
     68        gui
  • trunk/src/lib/coord/p_node.cc

    r7193 r7221  
    540540 * @param childName the name of the child to add to this PNode
    541541 */
    542 void PNode::addChild (const char* childName)
     542void PNode::addChild (const std::string& childName)
    543543{
    544544  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
     
    624624 * @param parentName the name of the Parent to set to this PNode
    625625 */
    626 void PNode::setParent (const char* parentName)
     626void PNode::setParent (const std::string& parentName)
    627627{
    628628  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
     
    631631  else
    632632    PRINTF(2)("Not Found PNode's (%s::%s) new Parent by Name: %s\n",
    633               this->getClassName(), this->getName(), parentName);
     633        this->getClassName(), this->getName(), parentName.c_str());
    634634}
    635635
     
    680680 * @param bias the speed to iterate to this new Positions
    681681 */
    682 void PNode::setParentSoft(const char* parentName, float bias)
     682void PNode::setParentSoft(const std::string& parentName, float bias)
    683683{
    684684  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
     
    699699 * @param parentMode a String representing this parentingMode
    700700 */
    701 void PNode::setParentMode (const char* parentingMode)
    702 {
    703   this->setParentMode(PNode::charToParentingMode(parentingMode));
     701void PNode::setParentMode (const std::string& parentingMode)
     702{
     703  this->setParentMode(PNode::stringToParentingMode(parentingMode));
    704704}
    705705
     
    927927           this->getAbsDirV().y,
    928928           this->getAbsDirV().z,
    929            this->parentingModeToChar(parentMode),
     929           this->parentingModeToString(parentMode),
    930930           childNodeCount);
    931931  if (depth >= 2 || depth == 0)
     
    10491049 * @return the converted string
    10501050 */
    1051 const char* PNode::parentingModeToChar(int parentingMode)
     1051const char* PNode::parentingModeToString(int parentingMode)
    10521052{
    10531053  if (parentingMode == PNODE_LOCAL_ROTATE)
     
    10681068 * @return the int corresponding to the named parentingMode
    10691069 */
    1070 PARENT_MODE PNode::charToParentingMode(const char* parentingMode)
    1071 {
    1072   if (!strcmp(parentingMode, "local-rotate"))
     1070PARENT_MODE PNode::stringToParentingMode(const std::string& parentingMode)
     1071{
     1072  if (parentingMode == "local-rotate")
    10731073    return (PNODE_LOCAL_ROTATE);
    1074   else  if (!strcmp(parentingMode, "rotate-movement"))
     1074  else  if (parentingMode == "rotate-movement")
    10751075    return (PNODE_ROTATE_MOVEMENT);
    1076   else  if (!strcmp(parentingMode, "movement"))
     1076  else  if (parentingMode == "movement")
    10771077    return (PNODE_MOVEMENT);
    1078   else  if (!strcmp(parentingMode, "all"))
     1078  else  if (parentingMode == "all")
    10791079    return (PNODE_ALL);
    1080   else  if (!strcmp(parentingMode, "rotate-and-move"))
     1080  else  if (parentingMode == "rotate-and-move")
    10811081    return (PNODE_ROTATE_AND_MOVE);
    10821082}
  • trunk/src/lib/coord/p_node.h

    r7076 r7221  
    143143  // PARENTING //
    144144  void addChild (PNode* child);
    145   void addChild (const char* childName);
     145  void addChild (const std::string& childName);
    146146  void removeChild (PNode* child);
    147147  void removeNode();
     
    151151  /** @param parent the new parent of this node */
    152152  inline void setParent (PNode* parent) { parent->addChild(this); };
    153   void setParent (const char* parentName);
     153  void setParent (const std::string& parentName);
    154154  /** @returns the parent of this PNode */
    155155  inline PNode* getParent () const { return this->parent; };
     
    158158
    159159  void setParentSoft(PNode* parentNode, float bias = 1.0);
    160   void setParentSoft(const char* parentName, float bias = 1.0);
     160  void setParentSoft(const std::string& parentName, float bias = 1.0);
    161161
    162162  // PARENTING_MODE AND OTHER FLAGS //
    163163  void setParentMode (PARENT_MODE parentMode);
    164   void setParentMode (const char* parentingMode);
     164  void setParentMode (const std::string& parentingMode);
    165165  /** @returns the Parenting mode of this node */
    166166  int getParentMode() const { return 0x000f & this->parentMode; };
     
    183183
    184184  // HELPER_FUNCTIONS //
    185   static const char* parentingModeToChar(int parentingMode);
    186   static PARENT_MODE charToParentingMode(const char* parentingMode);
     185  static const char* parentingModeToString(int parentingMode);
     186  static PARENT_MODE stringToParentingMode(const std::string& parentingMode);
    187187  float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); };
    188188
  • trunk/src/lib/event/key_mapper.cc

    r6998 r7221  
    129129 * @param filename: The path and name of the file to load the bindings from
    130130*/
    131 void KeyMapper::loadKeyBindings (const char* fileName)
     131void KeyMapper::loadKeyBindings (const std::string& fileName)
    132132{
    133133  IniParser parser(fileName);
     
    145145
    146146  iniParser->firstVar();
    147   while(iniParser->getCurrentName())
     147  while(iniParser->getCurrentName() != "")
    148148  {
    149149    PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
     
    164164
    165165  iniParser->firstVar();
    166   while(iniParser->getCurrentName())
     166  while(iniParser->getCurrentName() != "")
    167167  {
    168168    PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
     
    177177 * @param the name of the button
    178178*/
    179 int* KeyMapper::nameToIndex (const char* name)
     179int* KeyMapper::nameToIndex (const std::string& name)
    180180{
    181181  coord[0] = -1;
     
    199199 * @param id of the key
    200200*/
    201 void KeyMapper::mapKeys(const char* name, int* index)
     201void KeyMapper::mapKeys(const std::string& name, int* index)
    202202{
    203203  for( int i = 0; map[i].pValue != NULL; ++i )
    204204    {
    205       if( !strcmp (name, map[i].pName))
     205      if( name == map[i].pName)
    206206      {
    207207        if( index[0] == 0)
  • trunk/src/lib/event/key_mapper.h

    r6998 r7221  
    2929  virtual ~KeyMapper();
    3030
    31   void loadKeyBindings(const char* fileName = NULL);
     31  void loadKeyBindings(const std::string& fileName = "" );
    3232  void loadKeyBindings(IniParser* iniParser);
    3333
     
    3535
    3636 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);
    3939
    4040 public:
  • trunk/src/lib/event/key_names.cc

    r5476 r7221  
    2323using namespace std;
    2424
    25 int buttonnameToSDLB(const char* name)
     25int buttonnameToSDLB(const std::string& name)
    2626{
    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;
    3232        return -1;
    3333}
     
    4343}
    4444
    45 int keynameToSDLK(const char* name)
     45int keynameToSDLK(const std::string& name)
    4646{
    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;
    180180        return -1;
    181181}
    182182
    183 const char* SDLKToKeyname( int key)
     183const char* SDLKToKeyname(int key)
    184184{
    185185        if( key == SDLK_BACKSPACE) return "BACKSPACE";
  • trunk/src/lib/event/key_names.h

    r5474 r7221  
    11/*!
    22 * @file keynames.h
    3   *  Key/button naming functions
    4 
    5                Converts strings to SDLK/SDL_BUTTON values and vice versa
    6 */
     3 *  Key/button naming functions
     4 *
     5 * Converts strings to SDLK/SDL_BUTTON values and vice versa
     6 */
    77#ifndef _KEY_NAMES_H
    88#define _KEY_NAMES_H
    99
    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>
    1611
    1712/**
    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 */
     17int 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 */
    2224const char* SDLBToButtonname( int button);
    2325
    2426/**
    25       *  converts a key name string to a integer representing the corresponding SDLK sym
    26       * @param name: the name of the key
    27       * @return the SDLK sym of the named key or -1 if the key name is not valid
    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 */
     31int keynameToSDLK(const std::string& name);
    3032
    3133/**
    32       *  converts an SDLK sym to a name string
    33       * @param key: the SDLK sym
    34       * @return a pointer to a string containig the name of the key
    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 */
    3638const char* SDLKToKeyname( int key);
    3739
  • trunk/src/lib/graphics/effects/fog_effect.cc

    r7193 r7221  
    126126 * @param mode the mode character
    127127 */
    128 GLint FogEffect::charToFogMode(const char* mode)
     128GLint FogEffect::stringToFogMode(const std::string& mode)
    129129{
    130   if( !strcmp( "GL_LINEAR", mode))
     130  if(mode == "GL_LINEAR")
    131131    return GL_LINEAR;
    132   else if( !strcmp("GL_EXP", mode))
     132  else if(mode == "GL_EXP")
    133133    return GL_EXP;
    134   else if(!strcmp("GL_EXP2", mode) )
     134  else if(mode == "GL_EXP2" )
    135135    return GL_EXP2;
    136136  else
  • trunk/src/lib/graphics/effects/fog_effect.h

    r7107 r7221  
    2626    virtual bool deactivate();
    2727
    28     inline void setFogMode(const char* mode) { this->fogMode = this->charToFogMode(mode); }
     28    inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); }
    2929    inline void setFogDensity(float density) { this->fogDensity = density; }
    3030    inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; }
     
    3333
    3434  private:
    35     GLint charToFogMode(const char* mode);
     35    GLint stringToFogMode(const std::string& mode);
    3636
    3737
  • trunk/src/lib/graphics/effects/lense_flare.cc

    r7193 r7221  
    131131 * @param mode the mode character
    132132 */
    133 GLint LenseFlare::charToFogMode(const char* mode)
     133GLint LenseFlare::stringToFogMode(const std::string& mode)
    134134{}
    135135
     
    147147 *  7th: Texture of the third burst
    148148 */
    149 void LenseFlare::addFlare(const char* textureName)
     149void LenseFlare::addFlare(const std::string& textureName)
    150150{
    151151  if( this->flares.size() > LF_MAX_FLARES)
     
    159159  bb->setSize(50, 50);
    160160  this->flares.push_back(bb);
    161   PRINTF(0)("Added a Lenseflare Billboard with texture %s\n", textureName);
     161  PRINTF(4)("Added a Lenseflare Billboard with texture %s\n", textureName.c_str());
    162162
    163163  // the first flare belongs to the light source
     
    167167    bb->setVisibility(true);
    168168  }
    169   PRINTF(0)("Finished adding\n", textureName);
     169  PRINTF(4)("Finished adding\n");
    170170}
    171171
  • trunk/src/lib/graphics/effects/lense_flare.h

    r7015 r7221  
    3939    virtual void tick(float dt);
    4040
    41     void addFlare(const char* textureName);
     41    void addFlare(const std::string& textureName);
    4242
    4343
    4444  private:
    45     GLint charToFogMode(const char* mode);
     45    GLint stringToFogMode(const std::string& mode);
    4646    void setSourceVisibility(bool visibility) ;
    4747
  • trunk/src/lib/graphics/graphics_engine.cc

    r7193 r7221  
    7878  this->screen = NULL;
    7979
    80 
    81   // Hardware
    82   this->hwRenderer = NULL;
    83   this->hwVendor = NULL;
    84   this->hwVersion = NULL;
    85   this->hwExtensions = NULL;
    86 
    8780  // initialize the Modules
    8881  TextEngine::getInstance();
     
    10396  // delete what has to be deleted here
    10497  this->displayFPS( false );
    105 
    106   delete[] this->hwRenderer;
    107   delete[] this->hwVendor;
    108   delete[] this->hwVersion;
    109   delete this->hwExtensions;
    11098
    11199  //TextEngine
     
    169157{
    170158  // 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"))
     159  const std::string fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");
     160  if (fullscreen[0] == '1' || fullscreen == "true")
    173161    this->fullscreenFlag = SDL_FULLSCREEN;
    174162
    175163  // 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"))
    178     Texture::setTextureEnableState( true);
     164  const std::string textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");
     165  if (textures[0] == '1' || textures == "true")
     166    Texture::setTextureEnableState(true);
    179167  else
    180168    Texture::setTextureEnableState(false);
    181169
    182170  // searching for a usefull resolution
    183   SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x');
     171  SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480").c_str(), 'x'); ///FIXME
    184172  //resolution.debug();
    185 
    186   this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
     173  MultiType x = resolution.getString(0), y = resolution.getString(1);
     174  this->initVideo(x.getInt(), y.getInt(), 16);
    187175
    188176  //   GraphicsEffect* fe = new FogEffect(NULL);
     
    262250 * @param icon The name of the Icon on the Disc
    263251 */
    264 void GraphicsEngine::setWindowName(const char* windowName, const char* icon)
    265 {
    266   SDL_Surface* iconSurf = SDL_LoadBMP(icon);
     252void GraphicsEngine::setWindowName(const std::string& windowName, const std::string& icon)
     253{
     254  SDL_Surface* iconSurf = SDL_LoadBMP(icon.c_str());
    267255  if (iconSurf != NULL)
    268256  {
    269257    Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0);
    270258    SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey);
    271     SDL_WM_SetIcon(iconSurf,NULL);
     259    SDL_WM_SetIcon(iconSurf, NULL);
    272260    SDL_FreeSurface(iconSurf);
    273261  }
    274262
    275   SDL_WM_SetCaption (windowName, icon);
     263  SDL_WM_SetCaption (windowName.c_str(), icon.c_str());
    276264}
    277265
     
    312300  //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
    313301
    314   if (this->hwRenderer == NULL && renderer != NULL)
    315   {
    316     this->hwRenderer = new char[strlen(renderer)+1];
    317     strcpy(this->hwRenderer, renderer);
    318   }
    319   if (this->hwVendor == NULL && vendor != NULL)
    320   {
    321     this->hwVendor = new char[strlen(vendor)+1];
    322     strcpy(this->hwVendor, vendor);
    323   }
    324   if (this->hwVersion == NULL && version != NULL)
    325   {
    326     this->hwVersion = new char[strlen(version)+11];
    327     strcpy(this->hwVersion, version);
    328   }
    329 
    330   if (this->hwExtensions == NULL && extensions != NULL)
    331     this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,");
     302  if (renderer != NULL)
     303  {
     304    this->hwRenderer == renderer;
     305  }
     306  if (vendor != NULL)
     307  {
     308    this->hwVendor == vendor;
     309  }
     310  if (version != NULL)
     311  {
     312    this->hwVersion == version;
     313  }
     314
     315  if (extensions != NULL)
     316    this->hwExtensions.split(extensions, " \n\t,");
    332317
    333318  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
    334319  PRINT(4)("Extensions:\n");
    335   if (this->hwExtensions != NULL)
    336     for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
    337       PRINT(4)("%d: %s\n", i, this->hwExtensions->getString(i));
     320  for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
     321    PRINT(4)("%d: %s\n", i, this->hwExtensions.getString(i).c_str());
    338322
    339323
     
    529513 * @return true if it is, false otherwise
    530514 */
    531 bool GraphicsEngine::hwSupportsEXT(const char* extension)
    532 {
    533   if (this->hwExtensions != NULL)
    534     for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
    535       if (!strcmp(extension, this->hwExtensions->getString(i)))
    536         return true;
     515bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
     516{
     517  for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
     518    if ( this->hwExtensions.getString(i) == extension)
     519      return true;
    537520  return false;
    538521}
     
    587570void GraphicsEngine::draw() const
    588571{
    589 //  LightManager::getInstance()->draw();
     572  //  LightManager::getInstance()->draw();
    590573
    591574  GraphicsEngine::storeMatrices();
     
    668651  switch (event.type)
    669652  {
    670       case EV_VIDEO_RESIZE:
    671       this->resolutionChanged(event.resize);
    672       break;
    673   }
    674 }
     653  case EV_VIDEO_RESIZE:
     654    this->resolutionChanged(event.resize);
     655    break;
     656  }
     657}
  • trunk/src/lib/graphics/graphics_engine.h

    r6990 r7221  
    1414#include "sdlincl.h"
    1515#include "glincl.h"
     16#include <list>
    1617
    17 #include <list>
     18#include "substring.h"
    1819
    1920// Forward Declaration
    2021class Text;
    2122class IniParser;
    22 class SubString;
    2323class WorldEntity;
    2424class GraphicsEffect;
     
    4141    int initFromIniFile(IniParser* iniParser);
    4242
    43     void setWindowName(const char* windowName, const char* icon);
     43    void setWindowName(const std::string& windowName, const std::string& icon);
    4444
    4545    int setResolution(int width, int height, int bpp);
     
    7474
    7575    void listModes();
    76     bool hwSupportsEXT(const char* extension);
     76    bool hwSupportsEXT(const std::string& extension);
    7777
    7878    /** @brief swaps the GL_BUFFERS */
     
    116116
    117117    // HARDWARE-Settings:
    118     char*                      hwRenderer;         //!< HW-renderer-string
    119     char*                      hwVendor;           //!< HW-vendor-string
    120     char*                      hwVersion;          //!< HW-version-string
    121     SubString*                 hwExtensions;       //!< All suported Extensions.
     118    std::string                hwRenderer;         //!< HW-renderer-string
     119    std::string                hwVendor;           //!< HW-vendor-string
     120    std::string                hwVersion;          //!< HW-version-string
     121    SubString                  hwExtensions;       //!< All suported Extensions.
    122122
    123123    // FPS-related
  • trunk/src/lib/graphics/importer/height_map.cc

    r7193 r7221  
    333333}
    334334
    335 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel()
     335HeightMap::HeightMap(const std::string& height_map_name = "")
     336  : VertexArrayModel()
    336337{
    337338   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    338    heightMap =  IMG_Load(height_map_name);
     339   heightMap =  IMG_Load(height_map_name.c_str());
    339340   if(heightMap!=NULL) {
    340341
    341                  PRINTF(0)("loading Image %s\n", height_map_name);
     342     PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    342343                 PRINTF(0)("width : %i\n", heightMap->w);
    343344                 PRINTF(0)("height : %i\n", heightMap->h);
     
    350351                }
    351352
    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());
    353354
    354355
     
    361362}
    362363
    363 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel()
     364HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL)
     365  : VertexArrayModel()
    364366{
    365367this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    366368
    367    heightMap =  IMG_Load(height_map_name);
     369   heightMap =  IMG_Load(height_map_name.c_str());
    368370   if(heightMap!=NULL) {
    369371
    370                  PRINTF(0)("loading Image %s\n", height_map_name);
     372     PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    371373                 PRINTF(0)("width : %i\n", heightMap->w);
    372374                 PRINTF(0)("height : %i\n", heightMap->h);
     
    379381                }
    380382
    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());
    382384
    383385
     
    385387
    386388  colourMap=NULL;
    387   if(colour_map_name != NULL)
     389  if(colour_map_name != "")
    388390  {
    389   colourMap = IMG_Load(colour_map_name);
     391    colourMap = IMG_Load(colour_map_name.c_str());
    390392  }
    391393
    392394  if(colourMap != NULL)
    393395                {
    394                  PRINTF(0)("loading Image %s\n", colour_map_name);
     396                  PRINTF(0)("loading Image %s\n", colour_map_name.c_str());
    395397                 PRINTF(0)("width : %i\n", colourMap->w);
    396398                 PRINTF(0)("height : %i\n", colourMap->h);
  • trunk/src/lib/graphics/importer/height_map.h

    r6981 r7221  
    5959void load();
    6060void load(int Mode);
    61 void load(const char*, int Mode);
     61void load(const std::string&, int Mode);
    6262void scale( Vector V);
    6363void setAbsCoor(Vector V);
     
    6565float getNormal(float x, float y);
    6666HeightMap();
    67 HeightMap(const char*);
    68 HeightMap(const char*, const char*);
     67HeightMap(const std::string&);
     68HeightMap(const std::string&, const std::string&);
    6969virtual ~HeightMap();
    7070
  • trunk/src/lib/graphics/importer/material.cc

    r7193 r7221  
    3434 * @param mtlName Name of the Material to be added to the Material List
    3535 */
    36 Material::Material (const char* mtlName)
     36Material::Material (const std::string& mtlName)
    3737{
    3838  this->setClassID(CL_MATERIAL, "Material");
     
    278278 * @param pathName The Path to add.
    279279*/
    280 void Material::addTexturePath(const char* pathName)
     280void Material::addTexturePath(const std::string& pathName)
    281281{
    282282  ResourceManager::getInstance()->addImageDir(pathName);
     
    289289 * @param dMap the Name of the Image to Use
    290290*/
    291 void Material::setDiffuseMap(const char* dMap, GLenum target)
     291void Material::setDiffuseMap(const std::string& dMap, GLenum target)
    292292{
    293293  PRINTF(5)("setting Diffuse Map %s\n", dMap);
     
    297297  //! @todo check if RESOURCE MANAGER is availiable
    298298  //! @todo Textures from .mtl-file need special care.
    299   if (dMap != NULL)
     299  if (!dMap.empty())
    300300    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
    301301  else
     
    308308   @todo implement this
    309309*/
    310 void Material::setAmbientMap(const char* aMap, GLenum target)
     310void Material::setAmbientMap(const std::string& aMap, GLenum target)
    311311{
    312312  SDL_Surface* ambientMap;
     
    319319   @todo implement this
    320320*/
    321 void Material::setSpecularMap(const char* sMap, GLenum target)
     321void Material::setSpecularMap(const std::string& sMap, GLenum target)
    322322{
    323323  SDL_Surface* specularMap;
     
    330330   @todo implemet this
    331331*/
    332 void Material::setBump(const char* bump)
    333 {
    334 
    335 }
     332void Material::setBump(const std::string& bump)
     333{
     334
     335}
  • trunk/src/lib/graphics/importer/material.h

    r7057 r7221  
    2626{
    2727 public:
    28   Material (const char* mtlName = NULL);
     28  Material (const std::string& mtlName = "");
    2929  virtual ~Material ();
    3030
     
    4949
    5050 // 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);
    5555  GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; };
    5656
    57   static void addTexturePath(const char* pathName);
     57  static void addTexturePath(const std::string& pathName);
    5858
    5959  private:
  • trunk/src/lib/graphics/importer/md2Model.cc

    r7193 r7221  
    7575  \brief simple constructor initializing all variables
    7676*/
    77 MD2Model::MD2Model(const char* modelFileName, const char* skinFileName, float scale)
     77MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale)
    7878{
    7979  this->setClassID(CL_MD2_MODEL, "MD2Model");
    8080  /* this creates the data container via ressource manager */
    81   this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale);
     81  if (!modelFileName.empty())
     82    this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale);
    8283  if( unlikely(this->data == NULL))
    8384    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
     
    352353{
    353354  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);
     355  PRINT(0)("=  Model FileName:\t%s\n", this->data->fileName.c_str());
     356  PRINT(0)("=  Skin FileName:\t%s\n", this->data->skinFileName.c_str());
    356357  PRINT(0)("=  Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size
    357358  PRINT(0)("=  Number of Vertices:\t%i\n", this->data->header->numVertices);
     
    370371  \brief simple constructor
    371372*/
    372 MD2Data::MD2Data(const char* modelFileName, const char* skinFileName, float scale)
     373MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    373374{
    374375  scale *= 0.1f;
     
    387388  this->scaleFactor = scale;
    388389
    389   this->fileName = NULL;
    390   this->skinFileName = NULL;
     390  this->fileName = "";
     391  this->skinFileName = "";
    391392  this->loadModel(modelFileName);
    392393  this->loadSkin(skinFileName);
     
    401402MD2Data::~MD2Data()
    402403{
    403   delete [] this->fileName;
    404   delete [] this->skinFileName;
    405404  delete this->header;
    406405
     
    419418  \return true if success
    420419*/
    421 bool MD2Data::loadModel(const char* fileName)
     420bool MD2Data::loadModel(const std::string& fileName)
    422421{
    423422  FILE *pFile;                            //file stream
     
    428427
    429428  //! @todo this chek should include deleting a loaded model (eventually)
    430   if (fileName == NULL)
     429  if (fileName.empty())
    431430    return false;
    432431
    433   pFile = fopen(fileName, "rb");
     432  pFile = fopen(fileName.c_str(), "rb");
    434433  if( unlikely(!pFile))
    435434    {
     
    442441  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
    443442    {
    444       PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName);
     443      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
    445444      return false;
    446445    }
    447446
    448   this->fileName = new char[strlen(fileName)+1];
    449   strcpy(this->fileName, fileName);
     447  this->fileName =fileName;
    450448  /* got the data: map it to locals */
    451449  this->numFrames = this->header->numFrames;
     
    507505  \return true if success
    508506*/
    509 bool MD2Data::loadSkin(const char* fileName)
    510 {
    511   if( fileName == NULL)
    512     {
    513       this->skinFileName = NULL;
     507bool MD2Data::loadSkin(const std::string& fileName)
     508{
     509  if( fileName.empty())
     510    {
     511      this->skinFileName = "";
    514512      return false;
    515513    }
    516514
    517   this->skinFileName = new char[strlen(fileName)+1];
    518   strcpy(this->skinFileName, fileName);
     515  this->skinFileName = fileName;
    519516
    520517  this->material.setName("md2ModelMaterial");
  • trunk/src/lib/graphics/importer/md2Model.h

    r7123 r7221  
    189189{
    190190 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);
    192192  virtual ~MD2Data();
    193193
    194194 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 = "");
    197197
    198198 public:
     
    202202  int                numTexCoor;            //!< number of texture coordinates
    203203  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
    204   char*              fileName;              //!< file name of the model File
    205   char*              skinFileName;          //!< file name of the skin file
     204  std::string        fileName;              //!< file name of the model File
     205  std::string        skinFileName;          //!< file name of the skin file
    206206  MD2Header*         header;                //!< the header file
    207207
     
    223223
    224224public:
    225   MD2Model(const char* modelFileName, const char* skinFileName = NULL, float scale = 1.0f);
     225  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
    226226  virtual ~MD2Model();
    227227
  • trunk/src/lib/graphics/importer/media_container.cc

    r7193 r7221  
    3434 * Default constructor
    3535 */
    36 MediaContainer::MediaContainer(const char* filename)
     36MediaContainer::MediaContainer(const std::string& filename)
    3737{
    3838  // set the class id for the base object
     
    4141  fps = 0;
    4242  mediaLoaded = false;
    43 
    44   this->loadMedia(filename);
     43  if (!filename.empty())
     44    this->loadMedia(filename);
    4545}
    4646
     
    8484}
    8585
    86 bool MediaContainer::loadMedia(const char* filename)
     86bool MediaContainer::loadMedia(const std::string& filename)
    8787{
    8888  this->unloadMedia();
    8989
    90   if(filename == NULL)
     90  if(filename.empty())
    9191    return false;
    9292  // check whether file exists
    9393  if(!ResourceManager::isInDataDir(filename))
    9494  {
    95     PRINTF(1)("Could not find %s\n", filename);
     95    PRINTF(1)("Could not find %s\n", filename.c_str());
    9696    return false;
    9797  }
     
    101101
    102102  // 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());
    106106    return false;
    107107  }
     
    110110  if (av_find_stream_info(format_context) < 0)
    111111  {
    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());
    113113    return false;
    114114  }
     
    116116  // Find the first video stream and take it
    117117  video_stream = av_find_default_stream_index(format_context);
    118  
     118
    119119  if(video_stream == -1)
    120120  {
    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());
    122122    return false;
    123123  }
     
    202202      // Free the packet that was allocated by av_read_frame
    203203      av_free_packet(&packet);
    204      
     204
    205205      // Did we get a video frame?
    206206      if(frame_finished)
     
    216216          memcpy(&data[i*codec_context->width*3],
    217217                 ((AVPicture*)RGB_frame)->data[0]+i *
    218                  ((AVPicture*)RGB_frame)->linesize[0], 
     218                 ((AVPicture*)RGB_frame)->linesize[0],
    219219                  codec_context->width*sizeof(uint8_t)*3);
    220220
     
    258258  }
    259259  else
    260     return NULL;
    261 }
     260    return 0;
     261}
  • trunk/src/lib/graphics/importer/media_container.h

    r6981 r7221  
    4444public:
    4545
    46   MediaContainer(const char* filename = NULL);
     46  MediaContainer(const std::string& filename = "");
    4747  virtual ~MediaContainer();
    4848
    49   bool loadMedia(const char* filename);
     49  bool loadMedia(const std::string& filename);
    5050  void loadFrames();
    5151
  • trunk/src/lib/graphics/importer/movie_player.cc

    r7193 r7221  
    3131
    3232
    33 MoviePlayer::MoviePlayer(const char* filename)
     33MoviePlayer::MoviePlayer(const std::string& filename)
    3434{
    3535  // set the class id for the base object
     
    4242  mediaLoaded = false;
    4343
    44   this->loadMovie(filename);
    45 
     44  if (!filename.empty())
     45    this->loadMovie(filename);
    4646}
    4747
     
    8383
    8484
    85 bool MoviePlayer::loadMovie(const char* filename)
     85bool MoviePlayer::loadMovie(const std::string& filename)
    8686{
    8787  this->unloadMedia();
    8888
    89   if(filename == NULL)
     89  if(filename.empty())
    9090    return false;
    9191  // check whether file exists
    9292  if(!ResourceManager::isInDataDir(filename))
    9393  {
    94     PRINTF(1)("Could not find %s\n", filename);
     94    PRINTF(1)("Could not find %s\n", filename.c_str());
    9595    return false;
    9696  }
     
    100100
    101101  // 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());
    105105    return false;
    106106  }
     
    109109  if (av_find_stream_info(format_context) < 0)
    110110  {
    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());
    112112    return false;
    113113  }
     
    118118  if(video_stream == -1)
    119119  {
    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());
    121121    return false;
    122122  }
  • trunk/src/lib/graphics/importer/movie_player.h

    r6981 r7221  
    5858public:
    5959
    60   MoviePlayer(const char* filename = NULL);
     60  MoviePlayer(const std::string& filename = "");
    6161  virtual ~MoviePlayer();
    6262
    63   bool loadMovie(const char* filename);
     63  bool loadMovie(const std::string& filename);
    6464
    6565  void start(float start_time);
  • trunk/src/lib/graphics/importer/objModel.cc

    r6162 r7221  
    3232 * @param scaling The factor that the model will be scaled with.
    3333*/
    34 OBJModel::OBJModel(const char* fileName, float scaling) : StaticModel(fileName)
     34OBJModel::OBJModel(const std::string& fileName, float scaling)
     35  : StaticModel(fileName)
    3536{
    3637  this->setClassID(CL_OBJ_MODEL, "OBJModel");
     
    5152*/
    5253OBJModel::~OBJModel()
    53 {
    54   PRINTF(4)("Deleting the obj-names\n");
    55   if (this->objPath)
    56     delete []this->objPath;
    57 }
     54{ }
    5855
    5956/**
     
    6360   Splits the FileName from the DirectoryName
    6461*/
    65 bool OBJModel::importFile (const char* fileName)
    66 {
     62bool OBJModel::importFile (const std::string& fileNameInput)
     63{
     64  const char* fileName = fileNameInput.c_str();
    6765  PRINTF(4)("preparing to read in file: %s\n", fileName);
    6866  // splitting the
     
    7472    {
    7573      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());
    7876      this->objPath[len] = '\0';
    7977      PRINTF(4)("Resolved file %s to Path %s.\n", fileName, this->objPath);
     
    9189   This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
    9290*/
    93 bool OBJModel::readFromObjFile(const char* fileName)
     91bool OBJModel::readFromObjFile(const std::string& fileName)
    9492{
    9593  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());
    9997      return false;
    10098    }
     
    162160 * that a material does not have to be able to read itself in from a File.
    163161 */
    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);
     162bool OBJModel::readMtlLib (const std::string& mtlFile)
     163{
     164  std::string fileName = this->objPath + mtlFile;
    168165
    169166  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());
    174170      return false;
    175171    }
     
    258254    }
    259255  fclose(stream);
    260   delete []fileName;
    261256  return true;
    262257}
  • trunk/src/lib/graphics/importer/objModel.h

    r6022 r7221  
    1313{
    1414 public:
    15   OBJModel(const char* fileName, float scaling = 1.0);
     15   OBJModel(const std::string& fileName, float scaling = 1.0);
    1616  virtual ~OBJModel();
    1717
    1818 private:
    1919  ///// 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);
    2323
    2424 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.
    2626};
    2727
  • trunk/src/lib/graphics/importer/static_model.cc

    r6423 r7221  
    2323#include <stdarg.h>
    2424
    25 #include "vector.h"
    26 
    2725using namespace std;
    2826
     
    8684{
    8785  PRINTF(4)("Adding new Group\n");
    88   this->name = NULL;
     86  this->name = "";
    8987  this->faceMode = -1;
    9088  this->faceCount = 0;
     
    109107  if (this->listNumber != 0)
    110108    glDeleteLists(this->listNumber, 1);
    111 
    112   if (this->name != NULL)
    113     delete[] this->name;
    114109
    115110  if (this->next !=NULL)
     
    142137 * assigns it a Name and a Type
    143138 */
    144 StaticModel::StaticModel(const char* modelName)
     139StaticModel::StaticModel(const std::string& modelName)
    145140{
    146141  this->setClassID(CL_STATIC_MODEL, "StaticModel");
     
    230225  ModelGroup* tmpGroup = this->firstGroup;
    231226  while (tmpGroup != NULL)
    232     {
    233       PRINTF(5)("Drawing model %s\n", tmpGroup->name);
    234       glCallList (tmpGroup->listNumber);
    235       tmpGroup = tmpGroup->next;
    236     }
     227  {
     228    PRINTF(5)("Drawing model %s\n", tmpGroup->name);
     229    glCallList (tmpGroup->listNumber);
     230    tmpGroup = tmpGroup->next;
     231  }
    237232}
    238233
     
    247242{
    248243  if (unlikely(groupNumber >= this->groupCount))
    249     {
    250       PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
    251       return;
    252     }
     244  {
     245    PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
     246    return;
     247  }
    253248  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    254249  ModelGroup* tmpGroup = this->firstGroup;
    255250  int counter = 0;
    256251  while (tmpGroup != NULL)
     252  {
     253    if (counter == groupNumber)
    257254    {
    258       if (counter == groupNumber)
    259         {
    260           PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
    261           glCallList (tmpGroup->listNumber);
    262           return;
    263         }
    264       ++counter;
    265       tmpGroup = tmpGroup->next;
     255      PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
     256      glCallList (tmpGroup->listNumber);
     257      return;
    266258    }
     259    ++counter;
     260    tmpGroup = tmpGroup->next;
     261  }
    267262  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName());
    268263  return;
     
    276271 * It does this by just calling the List that must have been created earlier.
    277272 */
    278 void StaticModel::draw (char* groupName) const
    279 {
    280   if (groupName == NULL)
    281      return;
     273void StaticModel::draw (const std::string& groupName) const
     274{
    282275  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    283276  ModelGroup* tmpGroup = this->firstGroup;
    284277  while (tmpGroup != NULL)
     278  {
     279    if (tmpGroup->name == groupName)
    285280    {
    286       if (tmpGroup->name != NULL && !strcmp(tmpGroup->name, groupName))
    287         {
    288           PRINTF(4)("Drawing model %s\n", tmpGroup->name);
    289           glCallList (tmpGroup->listNumber);
    290           return;
    291         }
    292       tmpGroup = tmpGroup->next;
     281      PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str());
     282      glCallList (tmpGroup->listNumber);
     283      return;
    293284    }
    294   PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->getName());
     285    tmpGroup = tmpGroup->next;
     286  }
     287  PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getName());
    295288  return;
    296289}
     
    341334 * @returns the added material
    342335 */
    343 Material* StaticModel::addMaterial(const char* materialName)
     336Material* StaticModel::addMaterial(const std::string& materialName)
    344337{
    345338  ModelMaterial* modMat = new ModelMaterial;
     
    357350 * @returns the Material if found, NULL otherwise
    358351 */
    359 Material* StaticModel::findMaterialByName(const char* materialName)
     352Material* StaticModel::findMaterialByName(const std::string& materialName)
    360353{
    361354  list<ModelMaterial*>::iterator modMat;
    362355  for  (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)
    363     if (!strcmp((*modMat)->material->getName(), materialName))
     356    if (materialName == (*modMat)->material->getName())
    364357      return (*modMat)->material;
    365358  return NULL;
     
    373366 * With it you should be able to create Models with more than one SubModel inside
    374367 */
    375 bool StaticModel::addGroup(const char* groupString)
     368bool StaticModel::addGroup(const std::string& groupString)
    376369{
    377370  PRINTF(5)("Read Group: %s.\n", groupString);
    378371  if (this->groupCount != 0 && this->currentGroup->faceCount > 0)
    379     {
    380       // finalizeGroup(currentGroup);
    381       this->currentGroup = this->currentGroup->next = new ModelGroup;
    382     }
     372  {
     373    // finalizeGroup(currentGroup);
     374    this->currentGroup = this->currentGroup->next = new ModelGroup;
     375  }
    383376  // 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);
    388     }
     377  if (groupString == "default")
     378  {
     379    this->currentGroup->name = groupString;
     380  }
    389381  ++this->groupCount;
    390382}
     
    396388 *  If a vertex line is found this function will inject it into the vertex-Array
    397389 */
    398 bool StaticModel::addVertex (const char* vertexString)
     390bool StaticModel::addVertex (const std::string& vertexString)
    399391{
    400392  float subbuffer1;
    401393  float subbuffer2;
    402394  float subbuffer3;
    403   sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
     395  sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    404396  this->vertices.push_back(subbuffer1*scaleFactor);
    405397  this->vertices.push_back(subbuffer2*scaleFactor);
     
    431423 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    432424 */
    433 bool StaticModel::addVertexNormal (const char* normalString)
     425bool StaticModel::addVertexNormal (const std::string& normalString)
    434426{
    435427  float subbuffer1;
    436428  float subbuffer2;
    437429  float subbuffer3;
    438   sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
     430  sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    439431  this->normals.push_back(subbuffer1);
    440432  this->normals.push_back(subbuffer2);
     
    471463 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
    472464 */
    473 bool StaticModel::addVertexTexture (const char* vTextureString)
     465bool StaticModel::addVertexTexture (const std::string& vTextureString)
    474466{
    475467  float subbuffer1;
    476468  float subbuffer2;
    477   sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
     469  sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2);
    478470  this->vTexture.push_back(subbuffer1);
    479471  this->vTexture.push_back(1 - subbuffer2);
     
    507499 * String is different from the argument addFace,
    508500 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0
    509  */
    510 bool StaticModel::addFace (const char* faceString)
    511 {
     501 *
     502 * @TODO make it std::string conform
     503 */
     504bool StaticModel::addFace (const std::string& faceStringInput)
     505{
     506  const char* faceString = faceStringInput.c_str();
    512507  if (this->currentGroup->faceCount >0)
    513508    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     
    516511  tmpElem->next = NULL;
    517512  while(strcmp (faceString, "\0"))
     513  {
     514    if (this->currentGroup->currentFace->vertexCount>0)
     515      tmpElem = tmpElem->next = new ModelFaceElement;
     516    tmpElem->next = NULL;
     517
     518    char tmpValue [50];
     519    int tmpLen;
     520    char* vertex = NULL;
     521    char* texture = NULL;
     522    char* normal = NULL;
     523
     524    sscanf (faceString, "%s", tmpValue);
     525    tmpLen = strlen(tmpValue);
     526    vertex = tmpValue;
     527
     528    if ((texture = strstr (vertex, "/")) != NULL)
    518529    {
    519       if (this->currentGroup->currentFace->vertexCount>0)
    520           tmpElem = tmpElem->next = new ModelFaceElement;
    521       tmpElem->next = NULL;
    522 
    523       char tmpValue [50];
    524       int tmpLen;
    525       char* vertex = NULL;
    526       char* texture = NULL;
    527       char* normal = NULL;
    528 
    529       sscanf (faceString, "%s", tmpValue);
    530       tmpLen = strlen(tmpValue);
    531       vertex = tmpValue;
    532 
    533       if ((texture = strstr (vertex, "/")) != NULL)
    534         {
    535           texture[0] = '\0';
    536           texture ++;
    537 
    538           if ((normal = strstr (texture, "/")) !=NULL)
    539             {
    540               normal[0] = '\0';
    541               normal ++;
    542             }
    543         }
    544       if (vertex)
    545         tmpElem->vertexNumber = atoi(vertex)-1;
    546       if (texture)
    547         tmpElem->texCoordNumber = atoi(texture)-1;
    548       if (normal)
    549         tmpElem->normalNumber = atoi(normal)-1;
    550 
    551       faceString += tmpLen;
    552       if (strcmp (faceString, "\0"))
    553         faceString++;
    554       this->currentGroup->currentFace->vertexCount++;
     530      texture[0] = '\0';
     531      texture ++;
     532
     533      if ((normal = strstr (texture, "/")) !=NULL)
     534      {
     535        normal[0] = '\0';
     536        normal ++;
     537      }
    555538    }
     539    if (vertex)
     540      tmpElem->vertexNumber = atoi(vertex)-1;
     541    if (texture)
     542      tmpElem->texCoordNumber = atoi(texture)-1;
     543    if (normal)
     544      tmpElem->normalNumber = atoi(normal)-1;
     545
     546    faceString += tmpLen;
     547    if (strcmp (faceString, "\0"))
     548      faceString++;
     549    this->currentGroup->currentFace->vertexCount++;
     550  }
    556551
    557552  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
     
    575570
    576571  for (int i = 0; i < faceElemCount; i++)
    577     {
    578       if (this->currentGroup->currentFace->vertexCount > 0)
    579         tmpElem = tmpElem->next = new ModelFaceElement;
    580 
    581       tmpElem->vertexNumber = va_arg (itemlist, int);
    582       if (type & TEXCOORD)
    583         tmpElem->texCoordNumber = va_arg (itemlist, int);
    584       if (type & NORMAL)
    585         tmpElem->normalNumber = va_arg(itemlist, int);
    586       this->currentGroup->currentFace->vertexCount++;
    587     }
     572  {
     573    if (this->currentGroup->currentFace->vertexCount > 0)
     574      tmpElem = tmpElem->next = new ModelFaceElement;
     575
     576    tmpElem->vertexNumber = va_arg (itemlist, int);
     577    if (type & TEXCOORD)
     578      tmpElem->texCoordNumber = va_arg (itemlist, int);
     579    if (type & NORMAL)
     580      tmpElem->normalNumber = va_arg(itemlist, int);
     581    this->currentGroup->currentFace->vertexCount++;
     582  }
    588583  va_end(itemlist);
    589584
     
    596591 * @param matString the Material that will be set.
    597592*/
    598 bool StaticModel::setMaterial(const char* matString)
     593bool StaticModel::setMaterial(const std::string& matString)
    599594{
    600595  if (this->currentGroup->faceCount > 0)
     
    647642  ModelGroup* tmpGroup = firstGroup;
    648643  while (tmpGroup != NULL)
     644  {
     645    ModelFace* tmpFace = tmpGroup->firstFace;
     646    while (tmpFace != NULL)
    649647    {
    650       ModelFace* tmpFace = tmpGroup->firstFace;
    651       while (tmpFace != NULL)
     648      if (tmpFace->firstElem != NULL)
     649      {
     650        ModelFaceElement* firstElem = tmpFace->firstElem;
     651        ModelFaceElement* prevElem;
     652        ModelFaceElement* curElem = firstElem;
     653        ModelFaceElement* nextElem;
     654        ModelFaceElement* lastElem;
     655        // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
     656        while (curElem != NULL)
    652657        {
    653           if (tmpFace->firstElem != NULL)
    654             {
    655               ModelFaceElement* firstElem = tmpFace->firstElem;
    656               ModelFaceElement* prevElem;
    657               ModelFaceElement* curElem = firstElem;
    658               ModelFaceElement* nextElem;
    659               ModelFaceElement* lastElem;
    660               // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
    661               while (curElem != NULL)
    662                 {
    663                   prevElem = curElem;
    664                   curElem = curElem->next;
    665                 }
    666               lastElem = prevElem;
    667 
    668               curElem = firstElem;
    669               for (int j=0; j<tmpFace->vertexCount; j++)
    670                 {
    671                   if (!(nextElem = curElem->next))
    672                     nextElem = firstElem;
    673                   curElem->normalNumber = curElem->vertexNumber;
    674 
    675                   curV = Vector (this->vertices[curElem->vertexNumber*3],
    676                                  this->vertices[curElem->vertexNumber*3+1],
    677                                  this->vertices[curElem->vertexNumber*3+2]);
    678 
    679                   prevV = Vector (this->vertices[prevElem->vertexNumber*3],
    680                                   this->vertices[prevElem->vertexNumber*3+1],
    681                                   this->vertices[prevElem->vertexNumber*3+2]) - curV;
    682 
    683                   nextV = Vector (this->vertices[nextElem->vertexNumber*3],
    684                                   this->vertices[nextElem->vertexNumber*3+1],
    685                                   this->vertices[nextElem->vertexNumber*3+2]) - curV;
    686                   normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
    687 
    688                   prevElem = curElem;
    689                   curElem = curElem->next;
    690                 }
    691             }
    692           tmpFace = tmpFace->next;
     658          prevElem = curElem;
     659          curElem = curElem->next;
    693660        }
    694       tmpGroup = tmpGroup->next;
     661        lastElem = prevElem;
     662
     663        curElem = firstElem;
     664        for (int j=0; j<tmpFace->vertexCount; j++)
     665        {
     666          if (!(nextElem = curElem->next))
     667            nextElem = firstElem;
     668          curElem->normalNumber = curElem->vertexNumber;
     669
     670          curV = Vector (this->vertices[curElem->vertexNumber*3],
     671                         this->vertices[curElem->vertexNumber*3+1],
     672                         this->vertices[curElem->vertexNumber*3+2]);
     673
     674          prevV = Vector (this->vertices[prevElem->vertexNumber*3],
     675                          this->vertices[prevElem->vertexNumber*3+1],
     676                          this->vertices[prevElem->vertexNumber*3+2]) - curV;
     677
     678          nextV = Vector (this->vertices[nextElem->vertexNumber*3],
     679                          this->vertices[nextElem->vertexNumber*3+1],
     680                          this->vertices[nextElem->vertexNumber*3+2]) - curV;
     681          normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
     682
     683          prevElem = curElem;
     684          curElem = curElem->next;
     685        }
     686      }
     687      tmpFace = tmpFace->next;
    695688    }
     689    tmpGroup = tmpGroup->next;
     690  }
    696691
    697692  for (int i=0; i < this->vertices.size()/3;i++)
    698     {
    699       normArray[i].normalize();
    700       PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    701 
    702       this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
    703 
    704     }
     693  {
     694    normArray[i].normalize();
     695    PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
     696
     697    this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
     698
     699  }
    705700  delete[] normArray;
    706701}
     
    721716
    722717  while (this->currentGroup != NULL)
     718  {
     719
     720    // creating a glList for the Group
     721    if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
    723722    {
    724 
    725       // creating a glList for the Group
    726       if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
     723      PRINTF(2)("glList could not be created for this Model\n");
     724      return false;
     725    }
     726    glNewList (this->currentGroup->listNumber, GL_COMPILE);
     727
     728    // Putting Faces to GL
     729    ModelFace* tmpFace = this->currentGroup->firstFace;
     730    while (tmpFace != NULL)
     731    {
     732      if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
     733      {
     734        if (this->currentGroup->faceMode != -1)
     735          glEnd();
     736        this->currentGroup->faceMode = 0;
     737        Material* tmpMat;
     738        if (tmpFace->material != NULL)
    727739        {
    728           PRINTF(2)("glList could not be created for this Model\n");
    729           return false;
     740          tmpFace->material->select();
     741          PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
    730742        }
    731       glNewList (this->currentGroup->listNumber, GL_COMPILE);
    732 
    733       // Putting Faces to GL
    734       ModelFace* tmpFace = this->currentGroup->firstFace;
    735       while (tmpFace != NULL)
     743      }
     744
     745      else if (tmpFace->vertexCount == 3)
     746      {
     747        if (this->currentGroup->faceMode != 3)
    736748        {
    737           if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
    738             {
    739               if (this->currentGroup->faceMode != -1)
    740                 glEnd();
    741               this->currentGroup->faceMode = 0;
    742               Material* tmpMat;
    743               if (tmpFace->material != NULL)
    744                 {
    745                   tmpFace->material->select();
    746                   PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
    747                 }
    748             }
    749 
    750           else if (tmpFace->vertexCount == 3)
    751             {
    752               if (this->currentGroup->faceMode != 3)
    753                 {
    754                   if (this->currentGroup->faceMode != -1)
    755                     glEnd();
    756                   glBegin(GL_TRIANGLES);
    757                 }
    758 
    759               this->currentGroup->faceMode = 3;
    760               PRINTF(5)("found triag.\n");
    761             }
    762 
    763           else if (tmpFace->vertexCount == 4)
    764             {
    765               if (this->currentGroup->faceMode != 4)
    766                 {
    767                   if (this->currentGroup->faceMode != -1)
    768                     glEnd();
    769                   glBegin(GL_QUADS);
    770                 }
    771               this->currentGroup->faceMode = 4;
    772               PRINTF(5)("found quad.\n");
    773             }
    774 
    775           else if (tmpFace->vertexCount > 4)
    776             {
    777               if (this->currentGroup->faceMode != -1)
    778                 glEnd();
    779               glBegin(GL_POLYGON);
    780               PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
    781               this->currentGroup->faceMode = tmpFace->vertexCount;
    782             }
    783 
    784           ModelFaceElement* tmpElem = tmpFace->firstElem;
    785           while (tmpElem != NULL)
    786             {
    787               //      PRINTF(2)("%s\n", tmpElem->value);
    788               this->addGLElement(tmpElem);
    789               tmpElem = tmpElem->next;
    790             }
    791           tmpFace = tmpFace->next;
     749          if (this->currentGroup->faceMode != -1)
     750            glEnd();
     751          glBegin(GL_TRIANGLES);
    792752        }
    793       glEnd();
    794       glEndList();
    795 
    796       this->currentGroup = this->currentGroup->next;
     753
     754        this->currentGroup->faceMode = 3;
     755        PRINTF(5)("found triag.\n");
     756      }
     757
     758      else if (tmpFace->vertexCount == 4)
     759      {
     760        if (this->currentGroup->faceMode != 4)
     761        {
     762          if (this->currentGroup->faceMode != -1)
     763            glEnd();
     764          glBegin(GL_QUADS);
     765        }
     766        this->currentGroup->faceMode = 4;
     767        PRINTF(5)("found quad.\n");
     768      }
     769
     770      else if (tmpFace->vertexCount > 4)
     771      {
     772        if (this->currentGroup->faceMode != -1)
     773          glEnd();
     774        glBegin(GL_POLYGON);
     775        PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
     776        this->currentGroup->faceMode = tmpFace->vertexCount;
     777      }
     778
     779      ModelFaceElement* tmpElem = tmpFace->firstElem;
     780      while (tmpElem != NULL)
     781      {
     782        //      PRINTF(2)("%s\n", tmpElem->value);
     783        this->addGLElement(tmpElem);
     784        tmpElem = tmpElem->next;
     785      }
     786      tmpFace = tmpFace->next;
    797787    }
     788    glEnd();
     789    glEndList();
     790
     791    this->currentGroup = this->currentGroup->next;
     792  }
    798793}
    799794
     
    814809  ModelFace* tmpFace;              //!< the temporary face referece
    815810
     811  bool warned = false;
     812
    816813  /* count the number of triangles */
    817814  /* now iterate through all groups and build up the triangle list */
     
    834831      else if( tmpFace->vertexCount > 4)
    835832      {
    836         PRINTF(1)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName());
    837       //exit(0);
     833        if (!warned)
     834        {
     835          PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName());
     836          warned = true;
     837        }
     838        //exit(0);
    838839      }
    839840      tmpFace = tmpFace->next;
     
    858859  while( this->currentGroup != NULL)
    859860  {
    860       // Putting Faces to GL
     861    // Putting Faces to GL
    861862    tmpFace = this->currentGroup->firstFace;
    862863    while( tmpFace != NULL)
     
    931932
    932933  if (elem->texCoordNumber != -1)
    933     {
    934       if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor))
    935         glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
    936       else
    937         PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
    938                   elem->texCoordNumber, this->pModelInfo.numTexCoor);
    939     }
     934  {
     935    if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor))
     936      glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
     937    else
     938      PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
     939                elem->texCoordNumber, this->pModelInfo.numTexCoor);
     940  }
    940941  if (elem->normalNumber != -1)
    941     {
     942  {
    942943    if (likely(elem->normalNumber < this->pModelInfo.numNormals))
    943944      glNormal3fv(&this->normals[0] + elem->normalNumber * 3);
    944945    else
    945         PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
    946                   elem->normalNumber, this->pModelInfo.numNormals);
    947     }
     946      PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
     947                elem->normalNumber, this->pModelInfo.numNormals);
     948  }
    948949  if (elem->vertexNumber != -1)
    949     {
    950       if (likely(elem->vertexNumber < this->pModelInfo.numVertices))
    951           glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
    952       else
    953         PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
    954                   elem->vertexNumber, this->pModelInfo.numVertices);
    955     }
     950  {
     951    if (likely(elem->vertexNumber < this->pModelInfo.numVertices))
     952      glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
     953    else
     954      PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
     955                elem->vertexNumber, this->pModelInfo.numVertices);
     956  }
    956957
    957958}
  • trunk/src/lib/graphics/importer/static_model.h

    r6423 r7221  
    1313#include <vector>
    1414#include <list>
    15 
    16 // FORWARD DECLARATION //
    17 template<class T> class tArray;
    1815
    1916// definition of different modes for setting up Faces
     
    7067  void cleanup();
    7168
    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.
    7370  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
    7471  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
     
    9895{
    9996 public:
    100   StaticModel(const char* modelName = NULL);
     97  StaticModel(const std::string& modelName = "");
    10198  virtual ~StaticModel();
    10299
    103100  virtual void draw() const;
    104101  void draw(int groupNumber) const;
    105   void draw(char* groupName) const;
     102  void draw(const std::string& groupName) const;
    106103
    107104  void rebuild();
    108105
    109106  Material* addMaterial(Material* material);
    110   Material* addMaterial(const char* materialName);
     107  Material* addMaterial(const std::string& materialName);
    111108
    112   bool addGroup(const char* groupString);
     109  bool addGroup(const std::string& groupString);
    113110
    114   bool addVertex(const char* vertexString);
     111  bool addVertex(const std::string& vertexString);
    115112  bool addVertex(float x, float y, float z);
    116113
    117   bool addFace(const char* faceString);
     114  bool addFace(const std::string& faceString);
    118115  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
    119116
    120   bool addVertexNormal(const char* normalString);
     117  bool addVertexNormal(const std::string& normalString);
    121118  bool addVertexNormal(float x, float y, float z);
    122119
    123   bool addVertexTexture(const char* vTextureString);
     120  bool addVertexTexture(const std::string& vTextureString);
    124121  bool addVertexTexture(float u, float v);
    125122
    126   bool setMaterial(const char* mtlString);
     123  bool setMaterial(const std::string& mtlString);
    127124  bool setMaterial(Material* mtl);
    128125
     
    133130  void cubeModel();
    134131
    135   Material* findMaterialByName(const char* materialName);
     132  Material* findMaterialByName(const std::string& materialName);
    136133
    137134 protected:
  • trunk/src/lib/graphics/importer/texture.cc

    r6871 r7221  
    3232 *  Constructor for a Texture
    3333*/
    34 Texture::Texture(const char* imageName, GLenum target)
     34Texture::Texture(const std::string& imageName, GLenum target)
    3535{
    3636  this->setClassID(CL_TEXTURE, "Texture");
     
    4141  this->priority = 0.5;
    4242
    43   if (imageName != NULL)
     43  if (!imageName.empty())
    4444  {
    4545    this->setName(imageName);
     
    6767 * @param imageName The image to load
    6868*/
    69 bool Texture::loadImage(const char* imageName, GLenum target)
     69bool Texture::loadImage(const std::string& imageName, GLenum target)
    7070{
    7171  if (Texture::texturesEnabled)
     
    8181      this->texture = 0;
    8282    }
    83     if (imageName != NULL)
     83    if (!imageName.empty())
    8484    {
    8585      SDL_Surface* tmpSurf;
     
    8787        glDeleteTextures(1, &this->texture);
    8888      // load the new Image to memory
    89       tmpSurf = IMG_Load(imageName);
     89      tmpSurf = IMG_Load(imageName.c_str());
    9090      if(tmpSurf != NULL)
    9191      {
  • trunk/src/lib/graphics/importer/texture.h

    r6981 r7221  
    1818  {
    1919    public:
    20       Texture(const char* imageName = NULL, GLenum target = GL_TEXTURE_2D);
     20      Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);
    2121  //  Texture(TEXTURE_TYPE type, int resolution);
    2222      virtual ~Texture();
    2323
    24       bool loadImage(const char* imageName, GLenum target = GL_TEXTURE_2D);
     24      bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    2525      virtual bool rebuild();
    2626
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r6624 r7221  
    124124 * @returns true on success
    125125 */
    126 bool TextureSequence::addFrame(const char* imageName)
     126bool TextureSequence::addFrame(const std::string& imageName)
    127127{
    128   if (imageName == NULL)
    129     return false;
    130 
    131   SDL_Surface* addSurface = IMG_Load(imageName);
     128  SDL_Surface* addSurface = IMG_Load(imageName.c_str());
    132129  bool success = this->addFrame(addSurface);
    133130  delete addSurface;
  • trunk/src/lib/graphics/importer/texture_sequence.h

    r7195 r7221  
    2323    bool loadImageSeries(unsigned int count, ...);
    2424    bool loadImageSeries(unsigned int count, va_list textureNames);
    25     bool addFrame(const char* image);
     25    bool addFrame(const std::string& image);
    2626    bool addFrame(SDL_Surface* surface);
    2727    bool addFrame(GLuint texture);
  • trunk/src/lib/graphics/render2D/billboard.cc

    r7193 r7221  
    7878void Billboard::loadParams(const TiXmlElement* root)
    7979{
    80   LoadParam(root, "texture", this, Billboard, setTexture)
     80  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
    8181      .describe("the texture-file to load onto the Billboard");
    8282
     
    100100 * @param textureFile The texture-file to load onto the crosshair
    101101 */
    102 void Billboard::setTexture(const char* textureFile)
     102void Billboard::setTexture(const std::string& textureFile)
    103103{
    104104  this->material->setDiffuseMap(textureFile);
  • trunk/src/lib/graphics/render2D/billboard.h

    r6815 r7221  
    3030
    3131    void setSize(float sizeX, float sizeY);
    32     void setTexture(const char* textureFile);
     32    void setTexture(const std::string& textureFile);
    3333    void attachTo(PNode* pnode);
    3434
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7199 r7221  
    180180 * @param alignment the alignment @see loadParams
    181181*/
    182 void Element2D::setAlignment(const char* alignment)
    183 {
    184   if (!strcmp(alignment, "center"))
     182void Element2D::setAlignment(const std::string& alignment)
     183{
     184  if (alignment == "center")
    185185    this->setAlignment(E2D_ALIGN_CENTER);
    186   else if (!strcmp(alignment, "left"))
     186  else if (alignment == "left")
    187187    this->setAlignment(E2D_ALIGN_LEFT);
    188   else if (!strcmp(alignment, "right"))
     188  else if (alignment == "right")
    189189    this->setAlignment(E2D_ALIGN_RIGHT);
    190   else if (!strcmp(alignment, "screen-center"))
     190  else if (alignment == "screen-center")
    191191    this->setAlignment(E2D_ALIGN_SCREEN_CENTER);
    192192}
     
    213213/**
    214214 * sets the layer onto which this 2D-element is projected to.
    215  * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const char* layer)
    216  */
    217 void Element2D::setLayer(const char* layer)
     215 * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const std::string& layer)
     216 */
     217void Element2D::setLayer(const std::string& layer)
    218218{
    219219  this->setLayer(Element2D::charToLayer2D(layer));
     
    235235 * @param bindNode the name of the Node (should be existing)
    236236 */
    237 void Element2D::setBindNode(const char* bindNode)
     237void Element2D::setBindNode(const std::string& bindNode)
    238238{
    239239  const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));
     
    572572 * @param childName the name of the child to add to this PNode
    573573 */
    574 void Element2D::addChild2D (const char* childName)
     574void Element2D::addChild2D (const std::string& childName)
    575575{
    576576  Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
     
    651651 * @param parentName the name of the Parent to set to this Element2D
    652652 */
    653 void Element2D::setParent2D (const char* parentName)
     653void Element2D::setParent2D (const std::string& parentName)
    654654{
    655655  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     
    658658  else
    659659    PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n",
    660                 this->getClassName(), this->getName(), parentName);
     660                this->getClassName(), this->getName(), parentName.c_str());
    661661}
    662662
     
    704704 * @param bias the speed to iterate to this new Positions
    705705 */
    706 void Element2D::setParentSoft2D(const char* parentName, float bias)
     706void Element2D::setParentSoft2D(const std::string& parentName, float bias)
    707707{
    708708  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     
    724724 * @param parentMode a String representing this parentingMode
    725725 */
    726 void Element2D::setParentMode2D (const char* parentingMode)
    727 {
    728   this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
     726void Element2D::setParentMode2D (const std::string& parentingMode)
     727{
     728  this->setParentMode2D(Element2D::stringToParentingMode2D(parentingMode));
    729729}
    730730
     
    952952            this->relCoordinate.y,
    953953            this->getAbsDir2D(),
    954             Element2D::parentingModeToChar2D(parentMode),
     954            Element2D::parentingModeToString2D(parentMode),
    955955            Element2D::layer2DToChar(this->layer));
    956956
     
    10741074 * @return the converted string
    10751075 */
    1076 const char* Element2D::parentingModeToChar2D(int parentingMode)
     1076const char* Element2D::parentingModeToString2D(int parentingMode)
    10771077{
    10781078  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
     
    10931093 * @return the int corresponding to the named parentingMode
    10941094 */
    1095 E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
    1096 {
    1097   if (!strcmp(parentingMode, "local-rotate"))
     1095E2D_PARENT_MODE Element2D::stringToParentingMode2D(const std::string& parentingMode)
     1096{
     1097  if (parentingMode == "local-rotate")
    10981098    return (E2D_PARENT_LOCAL_ROTATE);
    1099   else  if (!strcmp(parentingMode, "rotate-movement"))
     1099  else  if (parentingMode == "rotate-movement")
    11001100    return (E2D_PARENT_ROTATE_MOVEMENT);
    1101   else  if (!strcmp(parentingMode, "movement"))
     1101  else  if (parentingMode == "movement")
    11021102    return (E2D_PARENT_MOVEMENT);
    1103   else  if (!strcmp(parentingMode, "all"))
     1103  else  if (parentingMode == "all")
    11041104    return (E2D_PARENT_ALL);
    1105   else  if (!strcmp(parentingMode, "rotate-and-move"))
     1105  else  if (parentingMode == "rotate-and-move")
    11061106    return (E2D_PARENT_ROTATE_AND_MOVE);
    11071107}
     
    11391139 * @returns the E2D_LAYER on success, E2D_DEFAULT_LAYER on error.
    11401140 */
    1141 E2D_LAYER Element2D::charToLayer2D(const char* layer)
    1142 {
    1143   if (!strcmp(layer, "top"))
     1141E2D_LAYER Element2D::charToLayer2D(const std::string& layer)
     1142{
     1143  if (layer =="top")
    11441144    return (E2D_LAYER_TOP);
    1145   else  if (!strcmp(layer, "medium"))
     1145  else  if (layer == "medium")
    11461146    return (E2D_LAYER_MEDIUM);
    1147   else  if (!strcmp(layer, "bottom"))
     1147  else  if (layer == "bottom")
    11481148    return (E2D_LAYER_BOTTOM);
    1149   else  if (!strcmp(layer, "below-all"))
     1149  else  if (layer == "below-all")
    11501150    return (E2D_LAYER_BELOW_ALL);
    11511151  else
  • trunk/src/lib/graphics/render2D/element_2d.h

    r7052 r7221  
    102102    /** @param alignment the new Alignment of the 2D-Element */
    103103    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
    104     void setAlignment(const char* alignment);
     104    void setAlignment(const std::string& alignment);
    105105    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
    106106
    107107    // LAYERING //
    108108    void setLayer(E2D_LAYER layer);
    109     void setLayer(const char* layer);
     109    void setLayer(const std::string& layer);
    110110    /** @returns the Layer this Element is drawn to */
    111111    inline E2D_LAYER getLayer() const { return this->layer; };
     
    121121    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
    122122    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
    123     void setBindNode(const char* bindNode);
     123    void setBindNode(const std::string& bindNode);
    124124    inline const PNode* getBindNode() const { return this->bindNode; };
    125125
     
    181181
    182182    void addChild2D (Element2D* child);
    183     void addChild2D (const char* childName);
     183    void addChild2D (const std::string& childName);
    184184    void removeChild2D (Element2D* child);
    185185    void remove2D();
     
    187187    /** @param parent the new parent of this Element2D */
    188188    void setParent2D (Element2D* parent) { parent->addChild2D(this); };
    189     void setParent2D (const char* parentName);
     189    void setParent2D (const std::string& parentName);
    190190    /** @returns the parent of this Element2D */
    191191    inline Element2D* getParent2D () const { return this->parent; };
     
    194194
    195195    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
    196     void setParentSoft2D(const char* parentName, float bias = 1.0);
     196    void setParentSoft2D(const std::string& parentName, float bias = 1.0);
    197197
    198198    void setParentMode2D (E2D_PARENT_MODE parentMode);
    199     void setParentMode2D (const char* parentingMode);
     199    void setParentMode2D (const std::string& parentingMode);
    200200    /** @returns the Parenting mode of this node */
    201201    int getParentMode2D() const { return this->parentMode; };
     
    212212
    213213    // helper functions //
    214     static const char* parentingModeToChar2D(int parentingMode);
    215     static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
     214    static const char* parentingModeToString2D(int parentingMode);
     215    static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode);
    216216
    217217    static const char* layer2DToChar(E2D_LAYER layer);
    218     static E2D_LAYER charToLayer2D(const char* layer);
     218    static E2D_LAYER charToLayer2D(const std::string& layer);
    219219
    220220  private:
  • trunk/src/lib/graphics/shader.cc

    r7193 r7221  
    3636 * standard constructor
    3737*/
    38 Shader::Shader (const char* vertexShaderFile, const char* fragmentShaderFile)
     38Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
    3939{
    4040   this->setClassID(CL_SHADER, "Shader");
    4141
    42    this->fragmentShaderFile = NULL;
    43    this->vertexShaderFile = NULL;
     42   this->fragmentShaderFile = "";
     43   this->vertexShaderFile = "";
    4444   this->shaderProgram = 0;
    4545   this->vertexShader = 0;
     
    5252       this->shaderProgram = glCreateProgramObjectARB();
    5353
    54        if (vertexShaderFile != NULL)
     54       if (!vertexShaderFile.empty())
    5555         this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
    56        if (fragmentShaderFile != NULL)
     56       if (!fragmentShaderFile.empty())
    5757         this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
    5858       glLinkProgramARB(this->shaderProgram);
     
    103103}
    104104
    105 Shader* Shader::getShader(const char* vertexShaderFile, const char* fragmentShaderFile)
     105Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
    106106{
    107107  return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, fragmentShaderFile);
     
    116116
    117117
    118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const char* fileName)
     118bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName)
    119119{
    120120  GLhandleARB shader = 0;
     
    129129  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    130130  {
    131     this->vertexShaderFile = new char[strlen(fileName)+1];
    132     strcpy(this->vertexShaderFile, fileName);
     131    this->vertexShaderFile = fileName;
    133132
    134133    shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
     
    137136  if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
    138137  {
    139     this->fragmentShaderFile = new char[strlen(fileName)+1];
    140     strcpy(this->fragmentShaderFile, fileName);
     138    this->fragmentShaderFile = fileName;
    141139
    142140    shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
     
    146144  {
    147145    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);
    149148    glCompileShaderARB(shader);
    150149    // checking on error.
     
    160159}
    161160
    162 char* Shader::fileRead(const char* fileName)
     161char* Shader::fileRead(const std::string& fileName)
    163162{
    164163  FILE* fileHandle;
     
    167166  int count = 0;
    168167
    169   if (fileName == NULL)
     168  if (fileName.empty())
    170169    return NULL;
    171170
    172   fileHandle = fopen(fileName, "rt");
     171  fileHandle = fopen(fileName.c_str(), "rt");
    173172
    174173  if (fileHandle == NULL)
     
    187186
    188187
    189 std::vector<char*>* Shader::fileReadArray(const char* fileName)
     188std::vector<char*>* Shader::fileReadArray(const std::string& fileName)
    190189{
    191190  FILE*    stream;           //< The stream we use to read the file.
    192191
    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());
    196195    return NULL;
    197196  }
     
    234233  if (type == SHADER_VERTEX && this->vertexShader != 0)
    235234  {
    236     delete[] this->vertexShaderFile;
    237     this->vertexShaderFile = NULL;
     235    this->vertexShaderFile = "";
    238236    glDetachObjectARB(this->shaderProgram, this->vertexShader);
    239237    glDeleteObjectARB(this->vertexShader);
     
    245243  else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
    246244  {
    247     delete[] this->fragmentShaderFile;
    248     this->fragmentShaderFile = NULL;
     245    this->fragmentShaderFile = "";
    249246    glDetachObjectARB(this->shaderProgram, this->fragmentShader);
    250247    glDeleteObjectARB(this->fragmentShader);
  • trunk/src/lib/graphics/shader.h

    r7195 r7221  
    2727
    2828  public:
    29   Shader(const char* vertexShaderFile = NULL, const char* fragmentShaderFile = NULL);
     29  Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
    3030  virtual ~Shader();
    31   static Shader* getShader(const char* vertexShaderFile, const char* fragmentShaderFile);
     31  static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile);
    3232  static bool unload(Shader* shader);
    3333
    34   bool loadShaderProgramm(SHADER_TYPE type, const char* fileName);
     34  bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName);
    3535  void activateShader();
    3636  static void deactivateShader();
    3737  void deleteProgram(SHADER_TYPE type);
    3838
    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);
    4141
    4242  static bool checkShaderAbility();
     
    5454
    5555 private:
    56    char*                  fragmentShaderFile;
    57    char*                  vertexShaderFile;
     56   std::string            fragmentShaderFile;
     57   std::string            vertexShaderFile;
    5858   GLhandleARB            shaderProgram;
    5959   GLhandleARB            vertexShader;
  • trunk/src/lib/graphics/text_engine/font.cc

    r6609 r7221  
    3737 * @param fontSize the Size of the Font in Pixels
    3838 */
    39 Font::Font(const char* fontFile, unsigned int renderSize)
     39Font::Font(const std::string& fontFile, unsigned int renderSize)
    4040{
    4141  this->init();
     
    4444  this->setStyle("c");
    4545
    46   if (fontFile != NULL)
     46  if (!fontFile.empty())
    4747    this->loadFontFromTTF(fontFile);
    4848}
     
    5252 * @param imageFile the ImageFile to load the Font From.
    5353 */
    54 Font::Font(const char* imageFile)
     54Font::Font(const std::string& imageFile)
    5555{
    5656  this->init();
     
    5858  //  this->setSize(fontSize);
    5959  SDL_Surface* image = NULL;
    60   if (imageFile != NULL)
    61     image = IMG_Load(imageFile);
     60  if (!imageFile.empty())
     61    image = IMG_Load(imageFile.c_str());
    6262  else
    6363    return;
     
    6868  }
    6969  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());
    7171}
    7272
     
    114114
    115115  //! @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);
    119119
    120120  // erease this font out of the memory.
     
    140140 * @returns true if loaded, false if something went wrong, or if a font was loaded before.
    141141 */
    142 bool Font::loadFontFromTTF(const char* fontFile)
     142bool Font::loadFontFromTTF(const std::string& fontFile)
    143143{
    144144  // checking for existent Font.
     
    222222 *   i: italic, b: bold, u, underline
    223223 */
    224 void Font::setStyle(const char* renderStyle)
     224void Font::setStyle(const std::string& renderStyle)
    225225{
    226226  this->renderStyle = TTF_STYLE_NORMAL;
    227227
    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')
    230231      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  }
    236237  if (likely(this->fontTTF != NULL))
    237238    TTF_SetFontStyle(this->fontTTF, this->renderStyle);
    238 //  else
    239 //    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");
    240241}
    241242
     
    247248 * @param fileName the File to write the image into.
    248249 */
    249 void Font::createAsciiImage(const char* fileName, unsigned int size) const
     250void Font::createAsciiImage(const std::string& fileName, unsigned int size) const
    250251{
    251252  if (this->fontTTF == NULL)
     
    258259  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    259260  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
    260                                                height*size, height*size,
    261                                                32,
     261                          height*size, height*size,
     262                          32,
    262263#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    263                                                0x000000FF,
    264                                                0x0000FF00,
    265                                                0x00FF0000,
    266                                                0xFF000000
     264                          0x000000FF,
     265                          0x0000FF00,
     266                          0x00FF0000,
     267                          0xFF000000
    267268#else
    268                                                0xFF000000,
    269                                                0x00FF0000,
    270                                                0x0000FF00,
    271                                                0x000000FF
     269                          0xFF000000,
     270                          0x00FF0000,
     271                          0x0000FF00,
     272                          0x000000FF
    272273#endif
    273274                                              );
     
    299300    }
    300301  }
    301   SDL_SaveBMP(tmpSurf, fileName);
     302  SDL_SaveBMP(tmpSurf, fileName.c_str());
    302303  SDL_FreeSurface(tmpSurf);
    303304}
     
    409410
    410411  this->initGlyphs(32, numberOfGlyphs);
    411 //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
     412  //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
    412413
    413414  int rectSize = this->findOptimalFastTextureSize();
     
    418419  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    419420  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
    420                                                rectSize, rectSize,
    421                                                32,
     421                          rectSize, rectSize,
     422                          32,
    422423#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    423                                                0x000000FF,
    424                                                0x0000FF00,
    425                                                0x00FF0000,
    426                                                0xFF000000
     424                          0x000000FF,
     425                          0x0000FF00,
     426                          0x00FF0000,
     427                          0xFF000000
    427428#else
    428                                                0xFF000000,
    429                                                0x00FF0000,
    430                                                0x0000FF00,
    431                                                0x000000FF
     429                          0xFF000000,
     430                          0x00FF0000,
     431                          0x0000FF00,
     432                          0x000000FF
    432433#endif
    433434                                              );
     
    457458        break;
    458459      }
    459           // reading in the new Glyph
     460      // reading in the new Glyph
    460461      if (likely(this->fontTTF != NULL))
    461462      {
     
    521522  for (int i = from; i <= lastGlyph; i++)
    522523  {
    523       // setting up all the Glyphs we like.
     524    // setting up all the Glyphs we like.
    524525    glyphArray[i] = getGlyphMetrics(i);
    525526  }
     
    555556      if((tmpGlyph = this->glyphArray[i]) != NULL)
    556557      {
    557               // getting the height of the highest Glyph in the Line.
     558        // getting the height of the highest Glyph in the Line.
    558559        if (tmpGlyph->height*this->renderSize > maxLineHeight)
    559560          maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
     
    563564          x = 0;
    564565          y = y + maxLineHeight;
    565                   //maxLineHeight = 0;
     566          //maxLineHeight = 0;
    566567        }
    567568        if (y + maxLineHeight + 1 > size)
     
    592593  if(style==TTF_STYLE_NORMAL)
    593594    PRINTF(0)(" normal");
    594   else {
     595  else
     596  {
    595597    if(style&TTF_STYLE_BOLD)
    596598      PRINTF(0)(" bold");
  • trunk/src/lib/graphics/text_engine/font.h

    r6609 r7221  
    5555{
    5656  public:
    57     Font(const char* fontFile,
     57    Font(const std::string& fontFile,
    5858         unsigned int renderSize);
    59     Font(const char* imageFile);
     59    Font(const std::string& imageFile);
    6060    Font(char** xpmArray);
    6161    virtual ~Font();
     
    6464
    6565  //  font
    66     bool loadFontFromTTF(const char* fontFile);
     66    bool loadFontFromTTF(const std::string& fontFile);
    6767    bool loadFontFromSDL_Surface(SDL_Surface* surface);
    6868
    69     void setStyle(const char* renderStyle);
     69    void setStyle(const std::string& renderStyle);
    7070
    7171    /** @returns a Pointer to the Array of Glyphs */
     
    7878    inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
    7979
    80     void createAsciiImage(const char* fileName, unsigned int size) const;
     80    void createAsciiImage(const std::string& fileName, unsigned int size) const;
    8181    static void initDefaultFont();
    8282    static void removeDefaultFont();
  • trunk/src/lib/graphics/text_engine/text.cc

    r7193 r7221  
    3232 * @param type The renderType to display this font in
    3333 */
    34 Text::Text(const char* fontFile, unsigned int textSize)
     34Text::Text(const std::string& fontFile, unsigned int textSize)
    3535{
    3636  this->init();
    3737
    38   if (fontFile != NULL)
     38  if (!fontFile.empty())
    3939    this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
    4040  this->setSizeY2D(textSize);
     
    5050  if (this->font != NULL && this->font != Font::getDefaultFont())
    5151    ResourceManager::getInstance()->unload(this->font);
    52 
    53   if (this->text)
    54     delete[] this->text;
    5552}
    5653
     
    6461  // initialize this Text
    6562  this->font = NULL;
    66   this->text = NULL;
    67   this->externText = NULL;
     63  this->text = "";
    6864  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
    6965  this->blending = TEXT_DEFAULT_BLENDING;
    7066  this->color = TEXT_DEFAULT_COLOR;
    7167  this->setSize(TEXT_DEFAULT_SIZE);
    72   this->setText(NULL);
     68  this->setText("");
    7369}
    7470
     
    7874 * @param fontSize the Size of the Font
    7975 */
    80 void Text::setFont(const char* fontFile, unsigned int fontSize)
     76void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    8177{
    8278  Font* tmpFont;
     
    9086
    9187  // load a new Font
    92   if (fontFile != NULL)
     88  if (!fontFile.empty())
    9389  {
    9490    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
     
    9692      this->font = tmpFont;
    9793    else
    98       PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
     94      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    9995  }
    10096}
     
    104100 * @param text the new text to set
    105101 */
    106 void Text::setText(const char* text, bool isExtern)
    107 {
    108   if (isExtern)
    109   {
    110     this->externText = text;
    111 
    112     if (unlikely(this->text != NULL))
    113     {
    114       delete[] this->text;
    115       this->text = NULL;
    116     }
    117   }
    118   else
    119   {
    120     this->externText = NULL;
    121     if (this->text)
    122       delete[] this->text;
    123     if (text != NULL)
    124     {
    125       this->text = new char[strlen(text)+1];
    126       strcpy(this->text, text);
    127     }
    128     else
    129       this->text = NULL;
    130   }
     102void Text::setText(const std::string& text)
     103{
     104  this->text = text;
    131105
    132106  // setting up the Text-Width if DYNAMIC
     
    138112
    139113    float width = 0;
    140     const char* tmpText = this->externText;
    141     if (this->externText == NULL)
    142       tmpText = this->text;
    143     if (tmpText != NULL)
     114    if (!this->text.empty())
    144115    {
    145       while (*tmpText != '\0')
     116      for (unsigned int i = 0; i < this->text.size(); i++)
    146117      {
    147         if(glyphArray[*tmpText] != NULL)
     118        if(glyphArray[this->text[i]] != NULL)
    148119        {
    149           width += glyphArray[*tmpText]->advance;
     120          width += glyphArray[this->text[i]]->advance;
    150121        }
    151         tmpText++;
    152122      }
    153123      this->setSizeX2D(width *this->getSizeY2D());
     
    190160    glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture());
    191161  }
    192   const char* tmpText = this->externText;
    193   if (this->externText == NULL)
    194     tmpText = this->text;
    195   if (likely(tmpText != NULL))
     162  if (likely(!this->text.empty()))
    196163  {
    197164    glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
     
    201168
    202169    glBegin(GL_QUADS);
    203     while (likely(*tmpText != '\0'))
     170    for (unsigned int i = 0; i < this->text.size(); i++)
    204171    {
    205       if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL))
     172      if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
    206173      {
    207174        glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
     
    219186        posX += tmpGlyph->advance * this->getSizeY2D();
    220187      }
    221       ++tmpText;
    222188    }
    223189    glEnd();
     
    232198void Text::debug() const
    233199{
    234   if (this->externText == NULL)
    235     PRINT(0)("=== TEXT: %s ===\n", this->text);
    236   else
    237     PRINT(0)("=== TEXT: %s ===\n", this->externText);
     200  PRINT(0)("=== TEXT: %s ===\n", this->text.c_str());
    238201
    239202  if (this->getBindNode())
  • trunk/src/lib/graphics/text_engine/text.h

    r6981 r7221  
    3939{
    4040  public:
    41     Text(const char* fontFile = NULL, unsigned int fontSize = TEXT_DEFAULT_SIZE);
     41    Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE);
    4242    virtual ~Text();
    4343    void init();
    4444
    45     void setFont(const char* fontFile, unsigned int renderSize);
     45    void setFont(const std::string& fontFile, unsigned int renderSize);
    4646
    47     void setText(const char* text, bool isExtern = false);
     47    void setText(const std::string& text);
    4848
    4949    /** @returns the String this Text displays */
    50     inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };
     50    inline const std::string& getText() const { return this->text; };
    5151    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    5252    inline void setBlending(float blending) { this->blending = blending; };
     
    6969    Font*             font;           //!< Font of this text
    7070
    71     char*             text;           //!< The text to display
    72     const char*       externText;     //!< the text to Display from an external Source.
     71    std::string       text;           //!< The text to display
    7372    Vector            color;          //!< The color of the font.
    7473    float             blending;       //!< The blending intensity.
  • trunk/src/lib/gui/gl_gui/glgui_button.cc

    r6287 r7221  
    5454}
    5555
    56 void GLGuiButton::setLabel(const char* label)
     56void GLGuiButton::setLabel(const std::string& label)
    5757{
    5858  this->label->setText(label);
  • trunk/src/lib/gui/gl_gui/glgui_button.h

    r5427 r7221  
    3535
    3636   void init();
    37    void setLabel(const char* label);
     37   void setLabel(const std::string& label);
    3838
    3939   virtual void draw() const;
  • trunk/src/lib/gui/gl_gui/glgui_menu.h

    r5391 r7221  
    2424  void init();
    2525
    26   void addItem(const char* itemName);
    27   void removeItem(const char* itemName);
     26  void addItem(const std::string& itemName);
     27  void removeItem(const std::string& itemName);
    2828  void removeItem(unsigned int itemNumber);
    29   void selectItem(const char* itemName);
     29  void selectItem(const std::string& itemName);
    3030  void selectItem(unsigned int itemNumber);
    3131
  • trunk/src/lib/gui/gl_gui/glgui_widget.h

    r7062 r7221  
    4747    virtual char* save() {};
    4848    /** loads options of the Widget. @param loadString a string containing the Options */
    49     virtual void load(const char* loadString) {};
     49    virtual void load(const std::string& loadString) {};
    5050
    5151    void show();
  • trunk/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.cc

    r7193 r7221  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
     15   co-programmer: Benjamin GRauer
    1616*/
    1717
     
    8484
    8585/**
    86   * sets the background image name
     86  * @brief sets the background image name
    8787  * @param backImageName name of the backgroun-image
    8888 */
    89 void GLMenuImageScreen::setBackgroundImage (const char* backImageName)
     89void GLMenuImageScreen::setBackgroundImage (const std::string& backImageName)
    9090{
    9191  this->backMat->setDiffuseMap(backImageName);
     
    9393
    9494/**
    95  * sets position of the ImageScreen
     95 * @brief sets position of the ImageScreen
    9696 * @param offsetX offset from the top left corner in percent(0-1) of the screensize
    9797 * @param offsetY offset from the top left corner in percent(0-1) of the screensize
     
    104104
    105105/**
    106   \brief sets size of the ImageScreen
     106 * @brief sets size of the ImageScreen
    107107 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))
    108108 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))
     
    115115
    116116/**
    117   \brief sets position and size of the ImageScreen
    118 * @param offsetX offset from the top left corner in percent(0-1) of the screensize
    119 * @param offsetY offset from the top left corner in percent(0-1) of the screensize
    120 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))
    121 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))
     117 * @brief sets position and size of the ImageScreen
     118 * @param offsetX offset from the top left corner in percent(0-1) of the screensize
     119 * @param offsetY offset from the top left corner in percent(0-1) of the screensize
     120 * @param scaleX the scaleing of the image into the x-direction (in percent (0-1))
     121 * @param scaleY the scaleing of the image into the y-direction (in percent (0-1))
    122122*/
    123123void GLMenuImageScreen::setPosScale(float offsetX, float offsetY, float scaleX, float scaleY)
     
    130130 * @param barImage An image for the Bar
    131131*/
    132 void GLMenuImageScreen::setBarImage(const char* barImage)
     132void GLMenuImageScreen::setBarImage(const std::string& barImage)
    133133{
    134134  this->barMat->setDiffuseMap(barImage);
     
    136136
    137137/**
    138  * sets the Position and the Size of the bar
     138 * @brief sets the Position and the Size of the bar
    139139 * @param barX The Position in the x-direction in percent of the screen (0-1)
    140140 * @param barY The Position in the y-direction in percent of the screen (0-1)
     
    152152
    153153/**
    154  * set the maximum of countable steps
     154 * @brief set the maximum of countable steps
    155155 * @param maxValue of steps
    156156*/
     
    161161
    162162/**
    163  * set current value
     163 * @brief set current value
    164164 * @param currentValue value to set
    165165*/
     
    172172
    173173/**
    174  * get the current value
     174 * @brief get the current value
    175175 */
    176176int GLMenuImageScreen::getValue()
     
    181181
    182182/**
    183   * call this to trigger a progress event
    184 
    185    this has to redraw the progress bar and the whole image
     183 * @brief call this to trigger a progress event
     184 *
     185 * this has to redraw the progress bar and the whole image
    186186 */
    187187void GLMenuImageScreen::step ()
     
    199199
    200200/**
    201  * draws the ImageScreen to the screenbuffer
     201 * @brief draws the ImageScreen to the screenbuffer
    202202*/
    203203void GLMenuImageScreen::draw ()
  • trunk/src/lib/gui/gl_gui/glmenu/glmenu_imagescreen.h

    r6512 r7221  
    1313
    1414//! A class to display a loadScreen
    15 class GLMenuImageScreen : public BaseObject {
     15class GLMenuImageScreen : public BaseObject
     16{
    1617
    17  public:
     18public:
    1819  GLMenuImageScreen (const TiXmlElement* root = NULL);
    1920  virtual void loadParams(const TiXmlElement* root);
     
    2223  void draw();
    2324
    24   void setBackgroundImage(const char* backImageName);
     25  void setBackgroundImage(const std::string& backImageName);
    2526  void setPosition(float offsetX, float offsetY);
    2627  void setScale (float scaleX, float scaleY);
    2728  void setPosScale(float offsetX, float offsetY, float scaleX, float scaleY);
    2829
    29   void setBarImage(const char* barImage);
     30  void setBarImage(const std::string& barImage);
    3031  void setBarPosScale(float barX, float barY, float barW, float barH);
    3132
     
    3940
    4041
    41  private:
     42private:
    4243  // background image
    43   char*         backImageName;       //!< the name of the file of the background image
     44  std::string         backImageName;       //!< the name of the file of the background image
    4445  float         offsetX;             //!< X-offset of the the image from the left
    4546  float         offsetY;             //!< Y-offset of the image from the top
  • trunk/src/lib/gui/gtk_gui/gui_exec.cc

    r7193 r7221  
    4747  Frame* execFrame;            //!< The Frame that holds the ExecutionOptions.
    4848
    49   this->confFile = NULL;
    50   this->confDir = NULL;
     49  this->confFile = "";
     50  this->confDir = "";
    5151
    5252  execFrame = new Frame("Execute-Tags:");
     
    137137GuiExec::~GuiExec()
    138138{
    139   if(this->confFile)
    140     delete []this->confFile;
    141   if(this->confDir)
    142     delete []this->confDir;
    143139}
    144140
     
    156152  //! @todo F** Windows-support
    157153#ifndef __WIN32__
    158   mkdir(this->confDir, 0755);
     154  mkdir(this->confDir.c_str(), 0755);
    159155#else /* __WiN32__ */
    160   mkdir(this->confDir);
     156  mkdir(this->confDir.c_str());
    161157#endif /* __WIN32__ */
    162158}
     
    170166void GuiExec::setConfFile(const char* fileName)
    171167{
    172   if (!this->confDir)
     168  if (this->confDir.empty())
    173169    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;
    176171  PRINTF(5)("ConfigurationFile is %s.\n", this->confFile);
    177172}
     
    182177const char* GuiExec::getConfigFile() const
    183178{
    184   return this->confFile;
     179  return this->confFile.c_str();
    185180}
    186181
     
    204199  IniParser iniParser;
    205200  this->writeFileText(widget, &iniParser, 0);
    206   char* fileName = ResourceManager::homeDirCheck(confFile);
     201  std::string fileName = ResourceManager::homeDirCheck(confFile);
    207202  iniParser.writeFile(fileName);
    208   delete[] fileName;
    209203}
    210204
     
    259253void GuiExec::readFromFile(Widget* widget)
    260254{
    261   char* fileName = ResourceManager::homeDirCheck(confFile);
     255  std::string fileName = ResourceManager::homeDirCheck(confFile);
    262256  IniParser iniParser(fileName);
    263   delete[] fileName;
    264257  if (!iniParser.isOpen())
    265258    return;
     
    267260  iniParser.firstSection();
    268261  Widget* groupWidget = widget;
    269   const char* groupName;
    270   const char* widgetName;
     262  std::string groupName;
     263  std::string widgetName;
    271264  VarInfo varInfo;
    272   while (groupName = iniParser.getCurrentSection())
     265  while ((groupName = iniParser.getCurrentSection()) != "")
    273266  {
    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)
    276269      {
    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());
    278271        groupWidget = widget;
    279272        continue;
     
    282275      PRINT(4)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName);
    283276
    284     const char* entryName;
     277    std::string entryName;
    285278    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();
    291284      groupWidget->walkThrough(this->readFileText, &varInfo, 0);
    292285      iniParser.nextVar();
  • trunk/src/lib/gui/gtk_gui/gui_exec.h

    r6981 r7221  
    1111#include "gui_gtk.h"
    1212
     13#include <string>
     14
    1315class Widget;
    1416class CheckButton;
     
    2224  CheckButton* saveSettings;   //!< A CheckBox for if the Options should be saved.
    2325
    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.
    2628
    2729  //! A struct that holds informations about variables.
     
    5860struct HashTable
    5961{
    60   char* name;           //!< name of the entry
    61   char* value;          //!< value of the entry
     62  std::string name;           //!< name of the entry
     63  std::string value;          //!< value of the entry
    6264  HashTable* next;      //!< pointer to the next entry
    6365};
  • trunk/src/lib/lang/base_object.cc

    r7193 r7221  
    3434BaseObject::BaseObject()
    3535{
     36  this->classID = CL_BASE_OBJECT;
    3637  this->className = "BaseObject";
    37   this->classID = CL_BASE_OBJECT;
    38 
    39   this->objectName = NULL;
     38
     39  this->objectName = "";
    4040  this->classList = NULL;
    4141  this->xmlElem = NULL;
     
    5252
    5353  //  delete []this->className;
    54   if (this->objectName)
    55     delete[] this->objectName;
    5654  if (this->xmlElem != NULL)
    5755    delete this->xmlElem;
     
    8078 * @param className the class name
    8179*/
    82 void BaseObject::setClassID(ClassID classID, const char* className)
     80void BaseObject::setClassID(ClassID classID, const std::string& className)
    8381{
    8482  //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
     
    9593 * @brief set the name of the Object
    9694 */
    97 void BaseObject::setName (const char* objectName)
    98 {
    99   if (this->objectName)
    100     delete[] this->objectName;
    101   if (objectName != NULL)
    102   {
    103     this->objectName = new char[strlen(objectName)+1];
    104     strcpy(this->objectName, objectName);
    105   }
    106   else
    107     this->objectName = NULL;
     95void BaseObject::setName (const std::string& objectName)
     96{
     97  this->objectName = objectName;
    10898}
    10999
     
    160150 * @returns true if it is, false otherwise
    161151 */
    162 bool BaseObject::isA (const char* className) const
     152bool BaseObject::isA (const std::string& className) const
    163153{
    164154  ClassID classID = ClassList::StringToID(className);
     
    173163 * @returns true on match, false otherwise.
    174164 */
    175 bool BaseObject::operator==(const char* objectName)
    176 {
    177   if (likely(this->objectName != NULL && objectName != NULL))
    178     return (strcmp(this->objectName, objectName)) ? false : true;
     165bool BaseObject::operator==(const std::string& objectName)
     166{
     167  return (this->objectName == objectName);
    179168}
    180169
     
    197186int BaseObject::writeState( const byte * data, int length, int sender )
    198187{
    199   SYNCHELP_READ_BEGIN();
    200 
    201   if ( objectName )
     188  /// FIXME STD
     189
     190  /*  SYNCHELP_READ_BEGIN();
     191
     192  if ( !objectName.empty() )
    202193  {
    203194    delete[] objectName;
     
    211202  }
    212203
    213   return SYNCHELP_READ_N;
     204  return SYNCHELP_READ_N;*/
    214205}
    215206
     
    222213int BaseObject::readState( byte * data, int maxLength )
    223214{
    224   SYNCHELP_WRITE_BEGIN();
     215///FIXME STD
     216  /*  SYNCHELP_WRITE_BEGIN();
    225217
    226218  //PRINTF(0)("objectname = %s\n", this->objectName);
    227219  SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME );
    228220
    229   return SYNCHELP_WRITE_N;
    230 }
     221  return SYNCHELP_WRITE_N;*/
     222}
  • trunk/src/lib/lang/base_object.h

    r6587 r7221  
    1616#endif
    1717
     18#include <string>
    1819#include "stdincl.h"
    1920
     
    3031
    3132  virtual void loadParams(const TiXmlElement* root);
    32   void setName (const char* newName);
     33  void setName (const std::string& newName);
    3334  /** returns the Name of this Object */
    34   inline const char* getName ()const { return this->objectName; };
     35  inline const char* getName ()const { return this->objectName.c_str(); };
    3536  /** @returns the XML-Element with whicht this Object was loaded */
    3637  inline TiXmlNode* getXmlElem() const { return this->xmlElem; };
    3738
    3839  /** @returns the className of the corresponding Object */
    39   inline const char* getClassName() const { return this->className; };
     40  inline const char* getClassName() const { return this->className.c_str(); };
    4041  /** @returns the classID of the corresponding Object */
    4142  inline int getClassID() const { return this->classID; };
     
    4344
    4445  bool isA (ClassID classID) const;
    45   bool isA (const char* className) const;
     46  bool isA (const std::string& className) const;
    4647  void whatIs() const;
    4748
    48   bool operator==(const char* objectName);
     49  bool operator==(const std::string& objectName);
    4950  /** @param classID comparer for a ClassID @returns true on match, false otherwise */
    5051  bool operator==(ClassID classID) { return this->isA(classID); };
     
    5455
    5556 protected:
    56   void setClassID(ClassID classID, const char* className);
     57   void setClassID(ClassID classID, const std::string& className);
    5758
    5859 private:
    59     const char*        className;        //!< the name of the class
     60    std::string        className;        //!< the name of the class
    6061    long               classID;          //!< this is the id from the class_id.h enumeration
    61     char*              objectName;       //!< The name of this object
     62    std::string        objectName;       //!< The name of this object
    6263
    6364    ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
  • trunk/src/lib/lang/class_list.cc

    r7199 r7221  
    3737 *  Creates a new ClassList
    3838*/
    39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char* className)
    40 {
    41   this->className = className;
     39ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className)
     40  : className(className)
     41{
    4242  this->classID = classID;
    4343  this->classIDFull = classIDFull;
     
    5656
    5757//! a List of all strings of all classes, that have registered so far.
    58 std::list<const char*> ClassList::classNames;
     58std::list<std::string> ClassList::classNames;
    5959
    6060/**
     
    6767 * !! Before unsing the ClassList, as it creates the ClassLits
    6868 */
    69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className)
     69ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className)
    7070{
    7171  if (unlikely(classList == NULL))
    7272    ClassList::classList = new list<ClassList>();
    7373
    74   PRINTF(5)("subscribe a '%s'\n", className );
     74  PRINTF(5)("subscribe a '%s'\n", className.c_str() );
    7575
    7676  ClassList* regClass = ClassList::getClassList(classID);
     
    113113 * befor it changes anything.
    114114 */
    115 const std::list<const char*>* ClassList::getClassNames()
     115const std::list<std::string>* ClassList::getClassNames()
    116116{
    117117  if (ClassList::classNames.size() != ClassList::classList->size())
     
    155155 * @return the List accessed by classID, or NULL if not found
    156156 */
    157 const std::list<BaseObject*>* ClassList::getList(const char* className)
     157const std::list<BaseObject*>* ClassList::getList(const std::string& className)
    158158{
    159159  ClassList* fl;
     
    191191 * @returns the ClassList with className as specifyer, or NULL if not
    192192 */
    193 ClassList* ClassList::getClassList(const char* className)
    194 {
    195   if (className == NULL)
     193ClassList* ClassList::getClassList(const std::string& className)
     194{
     195  if (className.empty())
    196196    return NULL;
    197197  std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className);
     
    207207 * @todo: speed this up!!
    208208 */
    209 BaseObject* ClassList::getObject(const char* objectName, ClassID classID)
     209BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID)
    210210{
    211211  if (classID != CL_NULL)
     
    216216      std::list<BaseObject*>::iterator bo;
    217217      for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++)
    218         if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))
     218        if ((*bo)->getName() != NULL && objectName == (*bo)->getName())
    219219          return (*bo);
    220220    }
     
    227227      std::list<BaseObject*>::iterator bo;
    228228      for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++)
    229         if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))
     229        if ((*bo)->getName() != NULL && objectName == (*bo)->getName())
    230230          return (*bo);
    231231    }
     
    276276    if (object->isA((*cl).classID))
    277277  {
    278     PRINT(0)("=%s::0x%.8X=-", (*cl).className, (*cl).classID);
     278    PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID);
    279279  }
    280280}
     
    285285 * @return a String containing the name of the Class, NULL if the Class was not found
    286286 */
    287 const char* ClassList::IDToString(ClassID classID)
    288 {
     287const std::string& ClassList::IDToString(ClassID classID)
     288{
     289  static const std::string empty("");
     290
    289291  ClassList* cl = ClassList::getClassList(classID);
    290   return (cl != NULL) ? cl->className : NULL;
     292  return (cl != NULL) ? cl->className : empty;
    291293}
    292294
     
    296298 * @return the ClassID. CL_NULL, if the class was not found.
    297299 */
    298 ClassID ClassList::StringToID(const char* className)
     300ClassID ClassList::StringToID(const std::string& className)
    299301{
    300302  ClassList* cl = ClassList::getClassList(className);
     
    307309 * @returns true on match, false otherwise
    308310 */
    309 bool ClassList::operator==(const char* className)
    310 {
    311   if (likely( className != NULL && this->className != NULL))
    312     return (!strcmp(this->className, className));
    313   else
    314     return false;
     311bool ClassList::operator==(const std::string& className)
     312{
     313  return (this->className == className);
    315314}
    316315
     
    342341      while (pow(10, lenCount) <= (*cl).objectList.size())
    343342        ++lenCount;
    344       for (int i=0; i < 30-strlen((*cl).className) - lenCount; i++)
     343      for (int i=0; i < 30-(*cl).className.size() - lenCount; i++)
    345344        (niceString[i]) = ' ';
    346       niceString[30-strlen((*cl).className) - lenCount] = '\0';
    347 
    348       PRINT(0)("| CLASS %s::%s %d\n", (*cl).className, niceString, (*cl).objectList.size());
     345      niceString[30-(*cl).className.size() - lenCount] = '\0';
     346
     347      PRINT(0)("| CLASS %s::%s %d\n", (*cl).className.c_str(), niceString, (*cl).objectList.size());
    349348
    350349      if (debugLevel >=2 && (*cl).objectList.size() > 0)
     
    371370 * @see ClassList::debug
    372371 */
    373 void ClassList::debugS(const char* className, unsigned int debugLevel)
     372void ClassList::debugS(const std::string& className, unsigned int debugLevel)
    374373{
    375374  ClassList::debug(debugLevel, ClassList::StringToID(className));
  • trunk/src/lib/lang/class_list.h

    r7165 r7221  
    1010#include "class_id.h"
    1111#include <list>
     12#include <string>
    1213#ifndef NULL
    1314#define NULL     0    //!< NULL
     
    3233class ClassList {
    3334  public:
    34     ClassList(ClassID classID, unsigned long classIDFull, const char* className);
     35    ClassList(ClassID classID, unsigned long classIDFull, const std::string& className);
    3536    virtual ~ClassList();
    3637
    3738    /* MAINTENANCE FUNCTIONS THESE ARE !!ONLY FOR BASEOBJECT !! */
    38     static ClassList*                     addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className);
     39    static ClassList*                     addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className);
    3940    static void                           removeFromClassList(BaseObject* objectPointer);
    4041
     
    4243
    4344    static const std::list<BaseObject*>*  getList(ClassID classID = CL_NULL);// { return (ClassList* fl = ClassList::getClassList(classID) != NULL)? &(fl->objectList) : NULL; };
    44     static const std::list<BaseObject*>*  getList(const char* className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL;  };
    45     static const std::list<const char*>*  getClassNames();
    46     static BaseObject*                    getObject(const char* name, ClassID classID = CL_NULL);
     45    static const std::list<BaseObject*>*  getList(const std::string& className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL;  };
     46    static const std::list<std::string>*  getClassNames();
     47    static BaseObject*                    getObject(const std::string& name, ClassID classID = CL_NULL);
    4748    static bool                           exists(const BaseObject* object, ClassID classID = CL_NULL);
    4849
     
    5152    static void                           whatIs(const BaseObject* object);
    5253
    53     static const char*                    IDToString(ClassID classID = CL_NULL);
    54     static ClassID                        StringToID(const char* className);
     54    static const std::string&             IDToString(ClassID classID = CL_NULL);
     55    static ClassID                        StringToID(const std::string& className);
    5556    static void                           debug(unsigned int debugLevel = 0, ClassID classID = CL_NULL);
    56     static void                           debugS(const char* className = NULL, unsigned int debugLevel = 0);
     57    static void                           debugS(const std::string& className = "", unsigned int debugLevel = 0);
    5758
    5859    inline bool                           operator==(ClassID classID) { return (this->classID == classID); };
    59     bool                                  operator==(const char* className);
     60    bool                                  operator==(const std::string& className);
    6061    inline ClassID                        getLeafClassID() const { return this->classID; };
    6162
    6263  private:
    6364    static ClassList*                     getClassList(ClassID classID);
    64     static ClassList*                     getClassList(const char* className);
     65    static ClassList*                     getClassList(const std::string& className);
    6566
    6667  private:
    67     ClassID                         classID;                //!< ClassID stored in this ClassList
    68     unsigned long                   classIDFull;            //!< The Full ClassID of this Class.
     68    ClassID                               classID;                //!< ClassID stored in this ClassList
     69    unsigned long                         classIDFull;            //!< The Full ClassID of this Class.
    6970
    70     const char*                     className;              //!< Name of the Class Stored here
     71    const std::string                     className;              //!< Name of the Class Stored here
    7172
    72     std::list<BaseObject*>          objectList;             //!< A list of Objects belonging to this Class
     73    std::list<BaseObject*>                objectList;             //!< A list of Objects belonging to this Class
    7374
    7475    // STATIC MEMBERS
    75     static std::list<ClassList>*    classList;              //!< The first Class in the List
    76     static std::list<const char*>   classNames;             //!< a List of all Names of all classes, that have registered so far.
     76    static std::list<ClassList>*          classList;              //!< The first Class in the List
     77    static std::list<std::string>         classNames;             //!< a List of all Names of all classes, that have registered so far.
    7778};
    7879
  • trunk/src/lib/parser/ini_parser/ini_parser.cc

    r5953 r7221  
    4040 * @param fileName: the path and name of the file to parse
    4141 */
    42 IniParser::IniParser (const char* fileName)
    43 {
    44   this->fileName = NULL;
    45   this->comment = NULL;
    46 
    47   if (fileName != NULL)
     42IniParser::IniParser (const std::string& fileName)
     43{
     44  this->fileName = "";
     45  this->comment = "";
     46
     47  if (!fileName.empty())
    4848    this->readFile(fileName);
    4949}
     
    5656{
    5757  this->deleteSections();
    58   this->setFileName(NULL);
    59 }
     58  this->setFileName("");
     59}
     60
     61const std::string IniParser::emptyString = "";
    6062
    6163
     
    6668{
    6769  // in all sections
    68   while(!this->sections.empty())
    69   {
    70      IniSection section = this->sections.front();
    71 
    72     // in all entries of the sections
    73     while(!section.entries.empty())
    74     {
    75       // delete all strings of entries.
    76       IniEntry entry = section.entries.front();
    77       delete[] entry.name;
    78       delete[] entry.value;
    79       delete[] entry.comment;
    80       section.entries.pop_front();
    81     }
    82     // delete all Sections
    83     delete[] section.name;
    84     delete[] section.comment;
    85     this->sections.pop_front();
    86   }
     70  this->sections.clear();
     71
    8772  this->currentSection = this->sections.end();
    88   this->setFileName(NULL);
     73  this->setFileName("");
    8974}
    9075
     
    9580 * If fileName is NULL the new Name will be set to NULL too.
    9681 */
    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;
     82void IniParser::setFileName(const std::string& fileName)
     83{
     84  this->comment = "";
     85  this->fileName = fileName;
    11286}
    11387
     
    12195 * and the new one will be opened.
    12296 */
    123 bool IniParser::readFile(const char* fileName)
     97bool IniParser::readFile(const std::string& fileName)
    12498{
    12599  FILE*    stream;           //< The stream we use to read the file.
    126100  int      lineCount = 0;    //< The Count of lines.
    127101
    128   if (this->fileName != NULL)
     102  if (!this->fileName.empty())
    129103    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);
     104
     105  if( fileName.empty())
     106    return false;
     107
     108  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
     109  {
     110    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
    136111    return false;
    137112  }
     
    143118    // READING IN THE INI-FILE //
    144119    /////////////////////////////
    145     char lineBuffer[PARSELINELENGHT];
    146     char buffer[PARSELINELENGHT];
     120    char lineBuffer[PARSELINELENGHT+1];
     121    char buffer[PARSELINELENGHT+1];
    147122    const char* lineBegin;
    148123    char* ptr;
     
    154129      if( (ptr = strchr( lineBuffer, '\n')) != NULL)
    155130        *ptr = 0;
     131      else
     132        lineBuffer[PARSELINELENGHT] = 0;
    156133      // cut up to the beginning of the line.
    157134      while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer))
    158135        ++lineBegin;
    159136
     137      if ( !strcmp( lineBegin, "" ) )
     138        continue;
     139
    160140      // check if we have a FileComment
    161141      if ( (*lineBegin == '#' || *lineBegin == ';'))
    162142      {
    163         char* newCommenLine = new char[strlen(lineBegin)+1];
    164         strcpy(newCommenLine, lineBegin);
     143        string newCommenLine = lineBegin;
    165144        this->commentList.push_back(newCommenLine);
    166145        continue;
     
    191170          continue;
    192171        }
    193         if( ptr == lineBegin) {
     172        if( ptr == lineBegin)
     173        {
    194174          lineCount++;
    195175          continue;
     
    228208 * @return true on success false otherwise
    229209 */
    230 bool IniParser::writeFile(const char* fileName) const
     210bool IniParser::writeFile(const std::string& fileName) const
    231211{
    232212  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);
     213  if( fileName.empty())
     214    return false;
     215
     216  if( (stream = fopen (fileName.c_str(), "w")) == NULL)
     217  {
     218    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
     219    return false;
     220  }
     221  else
     222  {
     223    if (!this->comment.empty())
     224      fprintf(stream, "%s\n\n", this->comment.c_str());
    245225
    246226    std::list<IniSection>::const_iterator section;
    247227    for (section = this->sections.begin(); section != this->sections.end(); section++)
     228    {
     229      if (!(*section).comment.empty())
     230        fprintf(stream, "%s", (*section).comment.c_str());
     231      fprintf(stream, "\n [%s]\n", (*section).name.c_str());
     232
     233      std::list<IniEntry>::const_iterator entry;
     234      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    248235      {
    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          }
     236        if (!(*entry).comment.empty())
     237          fprintf(stream, "%s", (*entry).comment.c_str());
     238        fprintf(stream, "   %s = %s\n", (*entry).name.c_str(), (*entry).value.c_str());
    260239      }
     240    }
    261241  }
    262242  fclose(stream);
    263243}
    264244
    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 
     245void IniParser::setFileComment(const std::string& fileComment)
     246{
     247  this->comment = fileComment;
     248}
    279249
    280250/**
     
    284254 * @return true on success... there is only success or segfault :)
    285255 */
    286 bool IniParser::addSection(const char* sectionName)
    287 {
    288   if (sectionName == NULL)
    289     return false;
    290   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);
     256bool IniParser::addSection(const std::string& sectionName)
     257{
     258  if (sectionName.empty())
     259    return false;
     260  IniSection newSection;
     261  newSection.name = sectionName;
     262  newSection.comment = "";
     263
     264  this->sections.push_back(newSection);
    294265
    295266  this->currentSection = --this->sections.end();
    296267  if (!this->sections.empty())
    297       this->currentEntry = (*this->currentSection).entries.begin();
    298   PRINTF(5)("Added Section %s\n", sectionName);
     268    this->currentEntry = (*this->currentSection).entries.begin();
     269  PRINTF(5)("Added Section %s\n", sectionName.c_str());
    299270  return true;
    300271}
     
    306277 * @return true on success or false if the section could not be found
    307278 */
    308 bool IniParser::getSection(const char* sectionName)
     279bool IniParser::getSection(const std::string& sectionName)
    309280{
    310281  this->currentSection = this->getSectionIT(sectionName);
     
    321292 *
    322293 */
    323 void IniParser::setSectionComment(const char* comment, const char* sectionName)
     294void IniParser::setSectionComment(const std::string& comment, const std::string& sectionName)
    324295{
    325296  std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
     
    327298    return;
    328299
    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;
     300  (*section).comment = comment;
    338301}
    339302
     
    342305 * @returns the Comment, or NULL on error.
    343306 */
    344 const char* IniParser::getSectionComment(const char* sectionName) const
     307const std::string& IniParser::getSectionComment(const std::string& sectionName) const
    345308{
    346309  std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     
    348311    return (*section).comment;
    349312  else
    350     return NULL;
     313    return IniParser::emptyString;
    351314}
    352315
     
    367330 * @returns the name of the section if found, NULL otherwise
    368331 */
    369 const char* IniParser::nextSection()
     332const std::string& IniParser::nextSection()
    370333{
    371334  if (this->currentSection == this->sections.end())
    372     return NULL;
     335    return IniParser::emptyString;
    373336
    374337  this->currentSection++;
    375338
    376339  if (this->currentSection != this->sections.end())
    377     {
    378       this->currentEntry = (*this->currentSection).entries.begin();
    379       return this->currentSection->name;
    380     }
    381   else
    382     return NULL;
     340  {
     341    this->currentEntry = (*this->currentSection).entries.begin();
     342    return this->currentSection->name;
     343  }
     344  else
     345    return IniParser::emptyString;
    383346}
    384347
     
    393356 * @return true if everything is ok false on error
    394357 */
    395 bool IniParser::addVar(const char* entryName, const char* value, const char* sectionName)
     358bool IniParser::addVar(const std::string& entryName, const std::string& value, const std::string& sectionName)
    396359{
    397360  std::list<IniSection>::iterator section;
    398361
    399   if (sectionName != NULL)
     362  if (!sectionName.empty())
    400363  {
    401364    for (section = this->sections.begin(); section != this->sections.end(); section++)
    402       if (!strcmp((*section).name, sectionName))
     365      if ((*section).name == sectionName)
    403366        break;
    404367  }
     
    411374  if (section == this->sections.end())
    412375  {
    413     PRINTF(2)("section '%s' not found for value '%s'\n", sectionName, entryName);
     376    PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str());
    414377    return false;
    415378  }
     
    417380  {
    418381    (*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);
     382    (*section).entries.back().comment = "";
     383    (*section).entries.back().name = entryName;
     384    (*section).entries.back().value = value;
    424385    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);
     386              (*section).entries.back().name.c_str(),
     387              (*section).entries.back().value.c_str(),
     388              (*section).name.c_str());
    428389    this->currentEntry = --(*section).entries.end();
    429390    return true;
     
    442403 * lead to unwanted behaviour.
    443404*/
    444 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
    445 {
    446   if (this->fileName != NULL)
     405const std::string& IniParser::getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue) const
     406{
     407  if (!this->fileName.empty())
    447408  {
    448409    std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
    449     if (entry != NULL &&  !strcmp((*entry).name, entryName))
     410    if (entry != NULL &&  (*entry).name == entryName)
    450411      return (*entry).value;
    451     PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
    452 
     412    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str());
    453413  }
    454414  else
     
    456416
    457417  return defaultValue;
    458 
    459418}
    460419
     
    465424 * @param sectionName the Name of the Section
    466425 */
    467 void IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
     426void IniParser::setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName)
    468427{
    469428  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 
     429  (*entry).comment = comment;
    482430}
    483431
     
    487435 * @returns the queried Comment.
    488436 */
    489 const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
     437const std::string& IniParser::getEntryComment(const std::string& entryName, const std::string& sectionName) const
    490438{
    491439  std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
     
    501449{
    502450  if (!this->sections.empty() &&
    503        this->currentSection != this->sections.end())
     451      this->currentSection != this->sections.end())
    504452    this->currentEntry = (*this->currentSection).entries.begin();
    505453}
     
    530478 * @returns the name of the Current selected Section
    531479 */
    532 const char* IniParser::getCurrentSection() const
     480const std::string& IniParser::getCurrentSection() const
    533481{
    534482  if (!this->sections.empty() &&
     
    536484    return this->currentSection->name;
    537485  else
    538     return NULL;
    539  }
     486    return IniParser::emptyString ;
     487}
    540488
    541489
     
    543491 * @returns the current entries Name, or NULL if we havn't selected a Entry
    544492 */
    545 const char* IniParser::getCurrentName() const
    546 {
    547  if (!this->sections.empty() &&
    548      this->currentSection != this->sections.end() &&
    549      this->currentEntry != (*this->currentSection).entries.end())
    550    return (*this->currentEntry).name;
    551  else
    552    return NULL;
     493const std::string& IniParser::getCurrentName() const
     494{
     495  if (!this->sections.empty() &&
     496      this->currentSection != this->sections.end() &&
     497      this->currentEntry != (*this->currentSection).entries.end())
     498    return (*this->currentEntry).name;
     499  else
     500    return emptyString;
    553501}
    554502
     
    556504 * @returns the current entries Value, or NULL if we havn't selected a Entry
    557505 */
    558 const char* IniParser::getCurrentValue() const
     506const std::string& IniParser::getCurrentValue() const
    559507{
    560508  if (!this->sections.empty() &&
     
    563511    return (*this->currentEntry).value;
    564512  else
    565     return NULL;
     513    return IniParser::emptyString;
    566514}
    567515
     
    571519 * @param sectionName the Name of the Section to get the Iterator from
    572520 */
    573 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const
     521std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const std::string& sectionName) const
    574522{
    575523  std::list<IniSection>::const_iterator section = this->currentSection;
    576   if (sectionName == NULL)
     524  if (sectionName.empty())
    577525    return this->currentSection;
    578526  else
    579527    for (section = this->sections.begin(); section != this->sections.end(); section++)
    580       if (!strcmp((*section).name, sectionName))
     528      if ((*section).name == sectionName)
    581529        break;
    582530  return section;
     
    588536 * @param sectionName the Name of the Section to get the Iterator from
    589537 */
    590 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const char* sectionName)
     538std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const std::string& sectionName)
    591539{
    592540  std::list<IniSection>::iterator section = this->currentSection;
    593   if (sectionName == NULL)
     541  if (sectionName.empty())
    594542    return this->currentSection;
    595543  else
    596544    for (section = this->sections.begin(); section != this->sections.end(); section++)
    597       if (!strcmp((*section).name, sectionName))
     545      if ((*section).name == sectionName)
    598546        break;
    599547  return section;
     
    606554 * @param sectionName the Name of the Section to get the Iterator from
    607555 */
    608 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const
    609 {
    610   if (entryName == NULL)
     556std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) const
     557{
     558  if (entryName.empty())
    611559    return this->currentEntry;
    612560  std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     
    615563  if (section != this->sections.end())
    616564    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    617       if (!strcmp((*entry).name, entryName))
     565      if ((*entry).name == entryName)
    618566        break;
    619567  if (entry == (*section).entries.end())
     
    629577 * @param sectionName the Name of the Section to get the Iterator from
    630578 */
    631 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const char* entryName, const char* sectionName)
    632 {
    633   if (entryName == NULL)
     579std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName)
     580{
     581  if (entryName.empty())
    634582    return this->currentEntry;
    635583  std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
     
    638586  if (section != this->sections.end())
    639587    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    640       if (!strcmp((*entry).name, entryName))
     588      if ((*entry).name == entryName)
    641589        break;
    642590  if (entry == (*section).entries.end())
     
    652600void IniParser::setFileComment()
    653601{
    654   if (this->comment != NULL)
    655     delete[] this->comment;
    656 
    657   if (this->commentList.empty()) {
    658     this->comment = NULL;
     602  if (this->commentList.empty())
     603  {
     604    this->comment = "";
    659605    return;
    660606  }
    661607
    662   unsigned int stringLength = 1;
    663608  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';
     609
    669610  while (!this->commentList.empty())
    670611  {
    671     if (*this->comment != '\0')
    672       strcat(this->comment, "\n");
    673     strcat(this->comment, this->commentList.front());
    674     delete[] this->commentList.front();
     612    if (this->comment[0] != '\0')
     613      this->comment += "\n";
     614    this->comment += this->commentList.front();
    675615    this->commentList.pop_front();
    676616  }
     
    682622void IniParser::setSectionComment()
    683623{
    684   if ((*this->currentSection).comment != NULL)
    685     delete[] (*this->currentSection).comment;
    686 
    687   if (this->commentList.empty()) {
    688     (*this->currentSection).comment = NULL;
     624  (*this->currentSection).comment = "";
     625
     626  if (this->commentList.empty())
    689627    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';
     628
    699629  while (!this->commentList.empty())
    700630  {
    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();
     631    if ((*this->currentSection).comment[0] != '\0')
     632      (*this->currentSection).comment += "\n";
     633    (*this->currentSection).comment += this->commentList.front();
    705634    this->commentList.pop_front();
    706635  }
     
    712641void IniParser::setEntryComment()
    713642{
    714   if ((*this->currentEntry).comment != NULL)
    715     delete[] (*this->currentEntry).comment;
    716 
    717   if (this->commentList.empty()) {
    718     (*this->currentEntry).comment = NULL;
     643  (*this->currentEntry).comment = "";
     644  if (this->commentList.empty())
    719645    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';
     646
    729647  while (!this->commentList.empty())
    730648  {
    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();
     649    if ((*this->currentEntry).comment[0] != '\0')
     650      (*this->currentEntry).comment += "\n";
     651    (*this->currentEntry).comment += this->commentList.front();
    735652    this->commentList.pop_front();
    736653  }
    737 
    738654}
    739655
     
    744660void IniParser::debug() const
    745661{
    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)
     662  PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str());
     663  if (!this->comment.empty())
     664    PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str());
     665
     666  if (!this->fileName.empty())
    751667  {
    752668    std::list<IniSection>::const_iterator section;
    753669    for (section = this->sections.begin(); section != this->sections.end(); section++)
    754670    {
    755       if ((*section).comment != NULL)
    756         PRINTF(0)(" %s\n", (*section).comment);
    757       PRINTF(0)(" [%s]\n", (*section).name);
     671      if (!(*section).comment.empty())
     672        PRINTF(0)(" %s\n", (*section).comment.c_str());
     673      PRINTF(0)(" [%s]\n", (*section).name.c_str());
    758674
    759675      std::list<IniEntry>::const_iterator entry;
    760676      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    761677      {
    762         if ((*entry).comment != NULL)
    763           PRINTF(0)(" %s\n", (*entry).comment);
    764         PRINTF(0)("   '%s' -> '%s'\n", (*entry).name, (*entry).value);
     678        if (!(*entry).comment.empty())
     679          PRINTF(0)(" %s\n", (*entry).comment.c_str());
     680        PRINTF(0)("   '%s' -> '%s'\n", (*entry).name.c_str(), (*entry).value.c_str());
    765681      }
    766682    }
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r6981 r7221  
    1515
    1616#include <list>
     17#include <string>
    1718
    1819//! ini-file parser
     
    2728    struct IniEntry
    2829    {
    29       char*               comment;  //!< A Comment that is appendet to the Top of this Entry.
    30       char*               name;     //!< name of a given Entry
    31       char*               value;    //!< value of a given Entry
     30      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
    3233    };
    3334
     
    3536    struct IniSection
    3637    {
    37       char*               comment;  //!< A Comment that is appendet to the Top of this Section.
    38       char*               name;     //!< name of a given section
     38      std::string         comment;  //!< A Comment that is appendet to the Top of this Section.
     39      std::string         name;     //!< name of a given section
    3940      std::list<IniEntry> entries;  //!< a list of entries for this section
    4041    };
     
    4243
    4344  public:
    44     IniParser (const char* filename = NULL);
     45    IniParser (const std::string& filename = "");
    4546    virtual ~IniParser ();
    4647
    4748    /** @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; };
    4950    /** @returns the fileName we have opened. */
    50     const char* getFileName() const { return this->fileName; };
     51    const std::string& getFileName() const { return this->fileName; };
    5152
    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;
    5455
    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; };
    5758
    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;
    6263
    6364    // iterate through sections with these Functions
    6465    void firstSection();
    65     const char* nextSection();
     66    const std::string& nextSection();
    6667
    6768
    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 = "" );
     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;
    7273
    7374    // iterate Through Variables with these Functions.
     
    7778
    7879    // 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;
    8283
    8384
     
    8889  private:
    8990    void deleteSections();
    90     void setFileName(const char* fileName);
     91    void setFileName(const std::string& fileName);
    9192
    9293    void setFileComment();
     
    9495    void setEntryComment();
    9596
    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);
    9899
    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 = "") const;
     101    std::list<IniEntry>::iterator getEntryIT(const std::string& entryName, const std::string& sectionName = "");
    101102
    102103  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.
    105106    std::list<IniSection>            sections;        //!< a list of all stored Sections of the Parser
    106107    std::list<IniSection>::iterator  currentSection;  //!< the current selected Section
    107108    std::list<IniEntry>::iterator    currentEntry;    //!< the current selected entry (in currentSection)
    108109
    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;
    110114};
    111115
  • trunk/src/lib/parser/tinyxml/tinyxml.h

    r5819 r7221  
    2626#ifndef TINYXML_INCLUDED
    2727#define TINYXML_INCLUDED
     28
     29#define TIXML_USE_STL
    2830
    2931#ifdef _MSC_VER
     
    8183                #define TIXML_SNSCANF  snscanf
    8284        #endif
    83 #endif 
     85#endif
    8486
    8587class TiXmlDocument;
     
    9698const int TIXML_PATCH_VERSION = 2;
    9799
    98 /*      Internal structure for tracking location of items 
     100/*      Internal structure for tracking location of items
    99101        in the XML file.
    100102*/
     
    110112
    111113// Only used by Attribute::Query functions
    112 enum 
    113 { 
     114enum
     115{
    114116        TIXML_SUCCESS,
    115117        TIXML_NO_ATTRIBUTE,
     
    162164        /**     All TinyXml classes can print themselves to a filestream.
    163165                This is a formatted print, and will insert tabs and newlines.
    164                
     166
    165167                (For an unformatted stream, use the << operator.)
    166168        */
     
    206208        static const int utf8ByteTable[256];
    207209
    208         virtual const char* Parse(      const char* p, 
    209                                                                 TiXmlParsingData* data, 
     210        virtual const char* Parse(      const char* p,
     211                                                                TiXmlParsingData* data,
    210212                                                                TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
    211213
     
    245247
    246248        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' );
    250252        }
    251253
     
    334336    /// Field containing a generic user pointer
    335337        void*                   userData;
    336        
     338
    337339        // None of these methods are reliable for any language except English.
    338340        // Good for approximation, not great for accuracy.
     
    386388
    387389public:
    388         #ifdef TIXML_USE_STL   
     390        #ifdef TIXML_USE_STL
    389391
    390392            /** An input stream operator, for every class. Tolerant of newlines and
     
    400402                    a node to a stream is very well defined. You'll get a nice stream
    401403                    of output, without any extra whitespace or newlines.
    402                    
     404
    403405                    But reading is not as well defined. (As it always is.) If you create
    404406                    a TiXmlElement (for example) and read that from an input stream,
     
    408410                    A TiXmlDocument will read nodes until it reads a root element, and
    409411                        all the children of that root element.
    410             */ 
     412            */
    411413            friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
    412414
     
    470472    #ifdef TIXML_USE_STL
    471473        /// STL std::string form.
    472         void SetValue( const std::string& _value )   
    473         {         
     474        void SetValue( const std::string& _value )
     475        {
    474476                StringToBuffer buf( _value );
    475                 SetValue( buf.buffer ? buf.buffer : "" );       
    476         }       
     477                SetValue( buf.buffer ? buf.buffer : "" );
     478        }
    477479        #endif
    478480
     
    492494        TiXmlNode* LastChild()  { return lastChild; }
    493495        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 );
    495497
    496498    #ifdef TIXML_USE_STL
     
    649651
    650652        /** Create an exact duplicate of this node and return it. The memory must be deleted
    651                 by the caller. 
     653                by the caller.
    652654        */
    653655        virtual TiXmlNode* Clone() const = 0;
     
    731733        /** QueryIntValue examines the value string. It is an alternative to the
    732734                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
    734736                the call returns TIXML_SUCCESS. If it is not
    735737                an integer, it returns TIXML_WRONG_TYPE.
     
    750752    #ifdef TIXML_USE_STL
    751753        /// STL std::string form.
    752         void SetName( const std::string& _name )       
    753         {       
     754        void SetName( const std::string& _name )
     755        {
    754756                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        {
    760762                StringToBuffer buf( _value );
    761                 SetValue( buf.buffer ? buf.buffer : "error" ); 
     763                SetValue( buf.buffer ? buf.buffer : "error" );
    762764        }
    763765        #endif
     
    801803/*      A class used to manage a group of attributes.
    802804        It is only used internally, both by the ELEMENT and the DECLARATION.
    803        
     805
    804806        The set can be changed transparent to the Element and Declaration
    805807        classes that use it, but NOT transparent to the Attribute
     
    882884        /** QueryIntAttribute examines the attribute - it is an alternative to the
    883885                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
    885887                the call returns TIXML_SUCCESS. If it is not
    886888                an integer, it returns TIXML_WRONG_TYPE. If the attribute
    887889                does not exist, then TIXML_NO_ATTRIBUTE is returned.
    888         */     
     890        */
    889891        int QueryIntAttribute( const char* name, int* _value ) const;
    890892        /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
     
    913915
    914916        /// 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        {
    917919                StringToBuffer n( name );
    918920                StringToBuffer v( _value );
    919921                if ( n.buffer && v.buffer )
    920                         SetAttribute (n.buffer, v.buffer );     
    921         }       
     922                        SetAttribute (n.buffer, v.buffer );
     923        }
    922924        ///< STL std::string form.
    923         void SetAttribute( const std::string& name, int _value )       
    924         {       
     925        void SetAttribute( const std::string& name, int _value )
     926        {
    925927                StringToBuffer n( name );
    926928                if ( n.buffer )
    927                         SetAttribute (n.buffer, _value);       
    928         }       
     929                        SetAttribute (n.buffer, _value);
     930        }
    929931        #endif
    930932
     
    954956                and concise, GetText() is limited compared to getting the TiXmlText child
    955957                and accessing it directly.
    956        
     958
    957959                If the first child of 'this' is a TiXmlText, the GetText()
    958960                returns the character string of the Text node, else null is returned.
     
    964966                @endverbatim
    965967
    966                 'str' will be a pointer to "This is text". 
    967                
     968                'str' will be a pointer to "This is text".
     969
    968970                Note that this function can be misleading. If the element foo was created from
    969971                this XML:
    970972                @verbatim
    971                 <foo><b>This is text</b></foo> 
     973                <foo><b>This is text</b></foo>
    972974                @endverbatim
    973975
     
    975977                another element. From this XML:
    976978                @verbatim
    977                 <foo>This is <b>text</b></foo> 
     979                <foo>This is <b>text</b></foo>
    978980                @endverbatim
    979981                GetText() will return "This is ".
    980982
    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
    983985                                 safe type casts on the referenced node.
    984986        */
     
    10541056
    10551057
    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
    10571059        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
    10591061        SetCDATA() and query it with CDATA().
    10601062*/
     
    10631065        friend class TiXmlElement;
    10641066public:
    1065         /** Constructor for text element. By default, it is treated as 
     1067        /** Constructor for text element. By default, it is treated as
    10661068                normal, encoded text. If you want it be output as a CDATA text
    10671069                element, set the parameter _cdata to 'true'
     
    12791281                - The ErrorDesc() method will return the name of the error. (very useful)
    12801282                - The ErrorRow() and ErrorCol() will return the location of the error (if known)
    1281         */     
     1283        */
    12821284        bool Error() const                                              { return error; }
    12831285
     
    12901292        int ErrorId()   const                           { return errorId; }
    12911293
    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,
    12931295                and the first row is row 1. A value of 0 means the row and column wasn't applicable
    12941296                (memory errors, for example, have no row/column) or the parser lost the error. (An
     
    13031305                to report the correct values for row and column. It does not change the output
    13041306                or input in any way.
    1305                
     1307
    13061308                By calling this method, with a tab size
    13071309                greater than 0, the row and column of each node and attribute is stored
     
    13311333                state is automatically cleared if you Parse a new XML block.
    13321334        */
    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;
    13381340                                                                                        }
    13391341
     
    13811383        @endverbatim
    13821384
    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
    13841386        easy to write a *lot* of code that looks like:
    13851387
     
    14011403
    14021404        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
    14041406        and correct to use:
    14051407
     
    14221424
    14231425        @verbatim
    1424         int i=0; 
     1426        int i=0;
    14251427        while ( true )
    14261428        {
     
    14331435        @endverbatim
    14341436
    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
    14371439        to. Instead, prefer:
    14381440
     
    14641466        TiXmlHandle FirstChildElement( const char * value ) const;
    14651467
    1466         /** Return a handle to the "index" child with the given name. 
     1468        /** Return a handle to the "index" child with the given name.
    14671469                The first child is 0, the second 1, etc.
    14681470        */
    14691471        TiXmlHandle Child( const char* value, int index ) const;
    1470         /** Return a handle to the "index" child. 
     1472        /** Return a handle to the "index" child.
    14711473                The first child is 0, the second 1, etc.
    14721474        */
    14731475        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.
    14751477                The first child element is 0, the second 1, etc. Note that only TiXmlElements
    14761478                are indexed: other types are not counted.
    14771479        */
    14781480        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.
    14801482                The first child element is 0, the second 1, etc. Note that only TiXmlElements
    14811483                are indexed: other types are not counted.
     
    14921494
    14931495        /// Return the handle as a TiXmlNode. This may return null.
    1494         TiXmlNode* Node() const                 { return node; } 
     1496        TiXmlNode* Node() const                 { return node; }
    14951497        /// Return the handle as a TiXmlElement. This may return null.
    14961498        TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
  • trunk/src/lib/particles/dot_particles.h

    r6652 r7221  
    2121  virtual void loadParams(const TiXmlElement* root);
    2222
    23   void setMaterialTexture(const char* textureFile);
     23  void setMaterialTexture(const std::string& textureFile);
    2424
    2525  /** @returns the Material that lies on this particles */
  • trunk/src/lib/particles/model_particles.cc

    r7198 r7221  
    8989 * @param textureFile the Texture to load onto these ModelParticles
    9090 */
    91 void ModelParticles::setMaterialTexture(const char* textureFile)
     91void ModelParticles::setMaterialTexture(const std::string& textureFile)
    9292{
    9393  this->material.setDiffuseMap(textureFile);
  • trunk/src/lib/particles/model_particles.h

    r6629 r7221  
    2020  virtual void loadParams(const TiXmlElement* root);
    2121
    22   void setMaterialTexture(const char* textureFile);
     22  void setMaterialTexture(const std::string& textureFile);
    2323
    2424  /** @returns the Material that lies on this particles */
  • trunk/src/lib/particles/particle_system.cc

    r7199 r7221  
    485485void ParticleSystem::debug() const
    486486{
    487   PRINT(0)("  ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, 100*this->count/this->maxCount);
     487  PRINT(0)("  ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, ((this->maxCount!=0)?100*this->count/this->maxCount:0));
    488488  if (deadList)
    489489  {
  • trunk/src/lib/particles/spark_particles.cc

    r7193 r7221  
    6868{
    6969  this->setClassID(CL_SPARK_PARTICLES, "SparkParticles");
    70 
    71   this->material = NULL;
    7270}
    7371
  • trunk/src/lib/particles/sprite_particles.cc

    r7198 r7221  
    8989 * @param textureFile the Texture to load onto these SpriteParticles
    9090 */
    91 void SpriteParticles::setMaterialTexture(const char* textureFile)
     91void SpriteParticles::setMaterialTexture(const std::string& textureFile)
    9292{
    9393  this->material.setDiffuseMap(textureFile);
  • trunk/src/lib/particles/sprite_particles.h

    r6626 r7221  
    2121  virtual void loadParams(const TiXmlElement* root);
    2222
    23   void setMaterialTexture(const char* textureFile);
     23  void setMaterialTexture(const std::string& textureFile);
    2424
    2525  /** @returns the Material that lies on this particles */
  • trunk/src/lib/physics/physics_connection.cc

    r7193 r7221  
    7373 * @param subjectName the name of the Subject for this PhysicsConnection
    7474*/
    75 void PhysicsConnection::setSubject(const char* subjectName)
     75void PhysicsConnection::setSubject(const std::string& subjectName)
    7676{
    7777  this->subject = PhysicsEngine::getInstance()->getPhysicsInterfaceByName(subjectName);
    7878  if (this->subject == NULL)
    7979  {
    80     PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName);
     80    PRINTF(2)("subject: (%s) not found for PhysicsConnection\n", subjectName.c_str());
    8181  }
    8282  else
     
    8787* @param fieldName the Name of the Field for this connection
    8888*/
    89 void PhysicsConnection::setField(const char* fieldName)
     89void PhysicsConnection::setField(const std::string& fieldName)
    9090{
    9191  this->field = PhysicsEngine::getInstance()->getFieldByName(fieldName);
    9292  if (this->field == NULL)
    9393  {
    94         PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName);
     94    PRINTF(2)("field: (%s) not found for PhysicsConnection\n", fieldName.c_str());
    9595  }
    9696  else
  • trunk/src/lib/physics/physics_connection.h

    r5257 r7221  
    3535  virtual ~PhysicsConnection();
    3636
    37   void setSubject(const char* subjectName);
    38   void setField(const char* fieldName);
     37  void setSubject(const std::string& subjectName);
     38  void setField(const std::string& fieldName);
    3939
    4040  void apply() const;
  • trunk/src/lib/physics/physics_engine.cc

    r7193 r7221  
    128128  @returns the PhysicsInterface if found, or NULL if not
    129129 */
    130 PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const char* physicsInterfaceName) const
     130PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const
    131131{
    132132  BaseObject* interface = ClassList::getObject(physicsInterfaceName, CL_PHYSICS_INTERFACE);
     
    157157
    158158/**
    159 * @param FieldName the Name of the PhysicsInterface to search for
     159* @param fieldName the Name of the PhysicsInterface to search for
    160160  @returns the Field if found, or NULL if not
    161161 */
    162 Field* PhysicsEngine::getFieldByName(const char* FieldName) const
     162Field* PhysicsEngine::getFieldByName(const std::string& fieldName) const
    163163{
    164164  list<Field*>::const_iterator field;
    165165  for (field = this->fields.begin(); field != this->fields.end(); field++)
    166     if (!strcmp(FieldName, (*field)->getName()))
     166    if (fieldName == (*field)->getName())
    167167      return (*field);
    168168  return NULL;
     
    197197  @returns the PhysicsConnection if found, or NULL if not
    198198 */
    199 PhysicsConnection* PhysicsEngine::getPhysicsConnectionByName(const char* physicsConnectionName) const
     199PhysicsConnection* PhysicsEngine::getPhysicsConnectionByName(const std::string& physicsConnectionName) const
    200200{
    201201  list<PhysicsConnection*>::const_iterator pc;
    202202  for (pc = this->connections.begin(); pc != this->connections.end(); pc++)
    203     if (!strcmp(physicsConnectionName, (*pc)->getName()))
     203    if (physicsConnectionName == (*pc)->getName())
    204204      delete (*pc);
    205205  return NULL;
  • trunk/src/lib/physics/physics_engine.h

    r6512 r7221  
    3131  void loadConnections(const TiXmlElement* root);
    3232
    33   PhysicsInterface*      getPhysicsInterfaceByName(const char* physicsInterfaceName) const;
     33  PhysicsInterface*      getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const;
    3434
    3535  void                   addField(Field* field);
    3636  void                   removeField(Field* field);
    37   Field*                 getFieldByName(const char* FieldName) const;
     37  Field*                 getFieldByName(const std::string& fieldName) const;
    3838
    3939  void                   addConnection(PhysicsConnection* connection);
    4040  void                   removeConnection(PhysicsConnection* connection);
    41   PhysicsConnection*     getPhysicsConnectionByName(const char* physicsConnectionName) const;
     41  PhysicsConnection*     getPhysicsConnectionByName(const std::string& physicsConnectionName) const;
    4242
    4343
  • trunk/src/lib/shell/shell.cc

    r7198 r7221  
    8585  this->lineSpacing = 0;
    8686  this->bActive = true;
    87   this->fontFile = new char[strlen(SHELL_DEFAULT_FONT)+1];
    88   strcpy(this->fontFile, SHELL_DEFAULT_FONT);
     87  this->fontFile = SHELL_DEFAULT_FONT;
    8988
    9089
     
    110109    delete this->bufferText[i];
    111110  delete[] this->bufferText;
    112   delete[] this->fontFile;
    113111  // delete the inputLine
    114112  delete this->shellInput;
     
    139137    if (!top)
    140138    {
    141       this->bufferText[i]->setText((*textLine), true);
     139      this->bufferText[i]->setText((*textLine));
    142140    if (textLine != ShellBuffer::getInstance()->getBuffer()->begin())
    143141      top = true;
     
    167165    if (textLine != ShellBuffer::getInstance()->getBuffer()->begin())
    168166    {
    169       this->bufferText[i]->setText((*textLine), false);
     167      this->bufferText[i]->setText((*textLine));
    170168      textLine--;
    171169    }
     
    181179 * (be aware that within orxonox fontFile is relative to the Data-Dir)
    182180 */
    183 void Shell::setFont(const char* fontFile)
     181void Shell::setFont(const std::string& fontFile)
    184182{
    185183//   if (!ResourceManager::isInDataDir(fontFile))
    186184//     return false;
    187185
    188   if (this->fontFile != NULL)
    189     delete[] this->fontFile;
    190 
    191   this->fontFile = new char[strlen(fontFile)+1];
    192   strcpy(this->fontFile, fontFile);
     186  this->fontFile = fontFile;
    193187
    194188  this->rebuildText();
     
    245239 * @param fileName the filename of the Image to load
    246240 */
    247 void Shell::setBackgroundImage(const char* fileName)
     241void Shell::setBackgroundImage(const std::string& fileName)
    248242{
    249243  this->backgroundMaterial->setDiffuseMap(fileName);
     
    340334    for (int i = 0; i < this->bufferDisplaySize; i++)
    341335    {
    342       this->bufferText[i]->setText(NULL, true);
     336      this->bufferText[i]->setText("");
    343337    }
    344338
     
    351345 * @param text the text to output.
    352346 */
    353 void Shell::printToDisplayBuffer(const char* text)
     347void Shell::printToDisplayBuffer(const std::string& text)
    354348{
    355349  if(likely(bufferText != NULL))
     
    382376    this->bufferText[0] = lastText;
    383377
    384     this->bufferText[0]->setText(text, true);
     378    this->bufferText[0]->setText(text);
    385379  }
    386380}
     
    427421  for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    428422  {
    429     this->bufferText[i]->setText((*it), false);
     423    this->bufferText[i]->setText((*it));
    430424    it--;
    431425  }
  • trunk/src/lib/shell/shell.h

    r5784 r7221  
    5353    inline bool isActive() const { return this->bActive; };
    5454
    55     void setFont(const char* fontFile);
     55    void setFont(const std::string& fontFile);
    5656    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
    5757    void setTextColor(float r, float g, float b, float a);
    5858    void setBackgroundColor(float r, float g, float b, float a);
    59     void setBackgroundImage(const char* fileName);
     59    void setBackgroundImage(const std::string& fileName);
    6060
    6161    void resetValues();
     
    6464    // BUFFERS
    6565    void setBufferDisplaySize(unsigned int bufferDisplaySize);
    66     void printToDisplayBuffer(const char* text);
     66    void printToDisplayBuffer(const std::string& text);
    6767    void moveDisplayBuffer(int lineCount);
    6868
     
    8383
    8484    //     void testI (int i);
    85     //     void testS (const char* s);
     85    //     void testS (const std::string& s);
    8686    //     void testB (bool b);
    8787    //     void testF (float f);
    88     //     void testSF (const char* s, float f);
     88    //     void testSF (const std::string& s, float f);
    8989
    9090  private:
     
    9595    unsigned int                textSize;               //!< The size of the text.
    9696    float                       textColor[4];           //!< The text's color [r,g,b,a].
    97     char*                       fontFile;               //!< The file containing the font.
     97    std::string                 fontFile;               //!< The file containing the font.
    9898    Material*                   backgroundMaterial;     //!< A material for the background.
    9999
  • trunk/src/lib/shell/shell_command.cc

    r7201 r7221  
    4141  PRINTF(5)("create shellcommand %s %s\n", commandName, className);
    4242  this->setName(commandName);
    43   this->description = NULL;
    44   this->alias = NULL;
    4543  this->executor = executor.clone();
    4644  this->executor->setName(commandName);
     
    153151 * @return true on success, false otherwise.
    154152 */
    155 bool ShellCommand::execute(const char* executionString)
     153bool ShellCommand::execute(const std::string& executionString)
    156154{
    157155  if (ShellCommandClass::commandClassList == NULL)
     
    177175      for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ )
    178176      {
    179         if ((*alias)->getName() != NULL && !strcmp((*alias)->getName(), inputSplits.getString(0)) && (*alias)->getCommand() != NULL &&
     177        if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL &&
    180178            (*alias)->getCommand()->shellClass != NULL )
    181179        {
     
    184182          {
    185183            if (inputSplits.getCount() > 1)
    186               (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1));
     184            {
     185
     186              (*alias)->getCommand()->executor->execute(objectList->front(), executionString.substr(inputSplits.getOffset(1))); /// TODO CHECK IF OK
     187            }
    187188            else
    188189              (*alias)->getCommand()->executor->execute(objectList->front(), "");
     
    198199      for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++)
    199200      {
    200         if ((*commandClassIT)->getName() && !strcasecmp(inputSplits.getString(0), (*commandClassIT)->getName()))
     201        if ((*commandClassIT)->getName() && inputSplits.getString(0) == (*commandClassIT)->getName())
    201202        {
    202203          //elemCL->getName();
     
    217218        for (object = objectList->begin(); object != objectList->end(); object++)
    218219        {
    219           if ((*object)->getName() != NULL && !strcasecmp((*object)->getName(), inputSplits.getString(1)))
     220          if ((*object)->getName() != NULL && inputSplits.getString(1) == (*object)->getName() )
    220221          {
    221222            objectPointer = (*object);
     
    235236        for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++)
    236237        {
    237           if (!strcmp((*cmdIT)->getName(), inputSplits.getString(fktPos)))
     238          if (inputSplits.getString(fktPos) == (*cmdIT)->getName())
    238239          {
    239240            if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective)
    240241              return false;
    241242            if (inputSplits.getCount() > fktPos+1)
    242               (*cmdIT)->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));
     243              (*cmdIT)->executor->execute(objectPointer, executionString.substr(inputSplits.getOffset(fktPos +1))); /// TODO CHECK IF OK
    243244            else
    244245              (*cmdIT)->executor->execute(objectPointer, "");
     
    255256 * @param description the description of the Given command
    256257 */
    257 ShellCommand* ShellCommand::describe(const char* description)
     258ShellCommand* ShellCommand::describe(const std::string& description)
    258259{
    259260  if (this == NULL)
     
    326327  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    327328  {
    328     PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     329    PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    329330
    330331    list<ShellCommand*>::iterator cmdIT;
     
    335336      /*      for (unsigned int i = 0; i< elem->paramCount; i++)
    336337       printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    337       if ((*cmdIT)->description != NULL)
    338        printf("- %s", (*cmdIT)->description);
     338      if (!(*cmdIT)->description.empty())
     339        printf("- %s", (*cmdIT)->description.c_str());
    339340      printf("\n");
    340341
  • trunk/src/lib/shell/shell_command.h

    r7201 r7221  
    6161  friend class ShellCommandClass;
    6262  public:
    63     static bool execute (const char* executionString);
     63    static bool execute (const std::string& executionString);
    6464
    65     ShellCommand* describe(const char* description);
     65    ShellCommand* describe(const std::string& description);
    6666    ShellCommand* setAlias(const char* alias);
    6767    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
     
    8989    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
    9090
    91     const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
     91    std::string                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
    9292    Executor*                        executor;                             //!< The Executor, that really executes the Function.
    9393
     
    100100  public:
    101101    /** @returns the Name of the Alias. */
    102     const char* getName() const { return this->aliasName; };
     102    const std::string& getName() const { return this->aliasName; };
    103103    /** @returns the Command, this Alias is asociated with */
    104104    ShellCommand* getCommand() const { return this->command; };
     
    106106  private:
    107107    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    108     ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
     108    ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
    109109
    110110  private:
    111     const char*     aliasName;       //!< the name of the Alias
     111    std::string     aliasName;       //!< the name of the Alias
    112112    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
    113113};
  • trunk/src/lib/shell/shell_command_class.cc

    r5780 r7221  
    3636 * @param className the Name of the command-class to create
    3737 */
    38 ShellCommandClass::ShellCommandClass(const char* className)
     38ShellCommandClass::ShellCommandClass(const std::string& className)
     39  : className(className)
    3940{
    4041  this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");
    4142  this->setName(className);
    4243
    43   this->className = className;
    4444  this->classID = CL_NULL;
    4545
     
    6565 * @returns true on success, false otherwise
    6666 */
    67 bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList)
    68 {
    69   if (stringList == NULL || className == NULL)
     67bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>* stringList)
     68{
     69  if (stringList == NULL)
    7070    return false;
    7171
     
    7373  for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
    7474  {
    75     if (!strcmp ((*elem)->getName(), className))
     75    if (className == (*elem)->getName())
    7676    {
    7777      list<ShellCommand*>::iterator command;
     
    8888 * @returns true on success, false otherwise
    8989 */
    90 bool ShellCommandClass::getCommandListOfAlias(std::list<const char*>* stringList)
     90bool ShellCommandClass::getCommandListOfAlias(std::list<std::string>* stringList)
    9191{
    9292  if (stringList == NULL || ShellCommandClass::aliasList == NULL)
     
    130130 * @returns the CommandClass if found, NULL otherwise
    131131 */
    132 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     132const ShellCommandClass* ShellCommandClass::isRegistered(const std::string& className)
    133133{
    134134  if (ShellCommandClass::commandClassList == NULL)
     
    138138  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    139139  {
    140     if (!strcmp(className, (*classIT)->className))
     140    if (className == (*classIT)->className)
    141141    {
    142142      if ((*classIT)->classID == CL_NULL)
     
    154154 * @returns the CommandClass if found, or a new CommandClass if not
    155155 */
    156 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
     156ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    157157{
    158158  if (ShellCommandClass::commandClassList == NULL)
     
    162162  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    163163  {
    164     if (!strcmp(className, (*classIT)->className))
     164    if (className == (*classIT)->className)
    165165    {
    166166      return (*classIT);
     
    186186 * @param className: the Class of Commands to show help about
    187187 */
    188 void ShellCommandClass::help(const char* className)
    189 {
    190   if (className == NULL)
    191     return;
     188void ShellCommandClass::help(const std::string& className)
     189{
    192190  if (likely(ShellCommandClass::commandClassList != NULL))
    193191  {
     
    195193    for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    196194    {
    197       if ((*classIT)->className && !strcasecmp(className, (*classIT)->className))
     195      if (className == (*classIT)->className)
    198196      {
    199         PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     197        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    200198        list<ShellCommand*>::const_iterator cmdIT;
    201199        for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
     
    205203          /*          for (unsigned int i = 0; i< elem->paramCount; i++)
    206204            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    207           if ((*cmdIT)->description != NULL)
    208             PRINT(0)("- %s", (*cmdIT)->description);
     205          if (!(*cmdIT)->description.empty())
     206            PRINT(0)("- %s", (*cmdIT)->description.c_str());
    209207          PRINT(0)("\n");
    210208        }
     
    212210      }
    213211    }
    214     PRINTF(3)("Class %s not found in Command's classes\n", className);
     212    PRINTF(3)("Class %s not found in Command's classes\n", className.c_str());
    215213  }
    216214  else
  • trunk/src/lib/shell/shell_command_class.h

    r6981 r7221  
    2727    /** @returns the CommandClassList */
    2828    static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; };
    29     static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList);
    30     static bool getCommandListOfAlias(std::list<const char*>* aliasList);
     29    static bool getCommandListOfClass(const std::string& className, std::list<std::string>* stringList);
     30    static bool getCommandListOfAlias(std::list<std::string>* aliasList);
    3131
    32     static ShellCommandClass* getCommandClass(const char* className);
     32    static ShellCommandClass* getCommandClass(const std::string& className);
    3333    static void unregisterAllCommands();
    3434
    35     static void help (const char* className);
     35    static void help (const std::string& className);
    3636
    3737  private:
    38     ShellCommandClass(const char* className);
     38    ShellCommandClass(const std::string& className);
    3939    virtual ~ShellCommandClass();
    4040
    41     static const ShellCommandClass* isRegistered(const char* className);
     41    static const ShellCommandClass* isRegistered(const std::string& className);
    4242    static void initCommandClassList();
    4343
    4444  private:
    45     const char*                            className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
     45    const std::string                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    4646    long                                   classID;                   //!< The classID of this Class
    4747    std::list<ShellCommand*>               commandList;               //!< A list of Commands from this Class
  • trunk/src/lib/shell/shell_completion.cc

    r5885 r7221  
    7676
    7777  // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object
    78   if (this->input->getInput() != NULL &&
    79       strrchr(this->input->getInput(), ' ') >= this->input->getInput() + strlen(this->input->getInput())-1)
     78  if (this->input->getInput()[this->input->getInput().size()-1] == ' ')
    8079  {
    8180    emptyComplete = true;
     
    8382
    8483  // CREATE INPUTS
    85   if (this->input->getInput() == NULL)
    86     completionLine = "";
    87   else
    88     completionLine = this->input->getInput() + strspn(this->input->getInput(), " \t\n");
    89   SubString inputSplits(completionLine, " \t\n,");
     84  SubString inputSplits(this->input->getInput(), " \t\n,");
    9085
    9186  // What String will be completed
     
    9388    completeString = "";
    9489  else
    95     completeString = inputSplits.getString(inputSplits.getCount()-1);
     90    completeString = inputSplits.getString(inputSplits.getCount()-1).c_str();
    9691
    9792  // CLASS COMPLETION
     
    111106            (inputSplits.getCount() == 2 && emptyComplete == false))
    112107  {
    113     classID = ClassList::StringToID(inputSplits.getString(0));
     108    classID = ClassList::StringToID(inputSplits.getString(0).c_str()); //FIXME
    114109    objectList = ClassList::getList((ClassID)classID);
    115110    if (classID != CL_NULL)
     
    121116            (inputSplits.getCount() == 3 && emptyComplete == false))
    122117  {
    123     classID = ClassList::StringToID(inputSplits.getString(0));
     118    classID = ClassList::StringToID(inputSplits.getString(0) .c_str()); // FIXME
    124119    if (classID == CL_NULL)
    125120      return false;
     
    133128    this->objectComplete(completeString, classID);
    134129  if (completeType & SHELLC_FUNCTION)
    135     this->functionComplete(completeString, inputSplits.getString(0));
     130    this->functionComplete(completeString, inputSplits.getString(0).c_str()); // FIXME
    136131  if (completeType & SHELLC_ALIAS)
    137132    this->aliasComplete(completeString);
     
    151146  if (unlikely(classBegin == NULL))
    152147    return false;
    153   const std::list<const char*>* clList = ClassList::getClassNames();
     148  const std::list<std::string>* clList = ClassList::getClassNames();
    154149  if (clList != NULL)
    155150  {
     
    195190  if (unlikely(functionBegin == NULL))
    196191    return false;
    197   std::list<const char*> fktList;
     192  std::list<std::string> fktList;
    198193  ShellCommandClass::getCommandListOfClass(className, &fktList);
    199194  //printf("%s\n", boList->firstElement()->getName());
     
    212207  if (unlikely(aliasBegin == NULL))
    213208    return false;
    214   std::list<const char*> aliasList;
     209  std::list<std::string> aliasList;
    215210  ShellCommandClass::getCommandListOfAlias(&aliasList);
    216211  //printf("%s\n", boList->firstElement()->getName());
     
    295290 * !! The strings MUST NOT be deleted !!
    296291 */
    297 bool ShellCompletion::addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type)
     292bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type)
    298293{
    299294  if (inputList == NULL || completionBegin == NULL)
     
    301296  unsigned int searchLength = strlen(completionBegin);
    302297
    303   list<const char*>::const_iterator string;
     298  list<std::string>::const_iterator string;
    304299  for (string = inputList->begin(); string != inputList->end(); string++)
    305300  {
    306     if (strlen(*string) >= searchLength &&
    307         !strncasecmp(*string, completionBegin, searchLength))
     301    if ((*string).size() >= searchLength &&
     302          !strncasecmp((*string).c_str(), completionBegin, searchLength))
    308303    {
    309304      ShellC_Element newElem;
    310       newElem.name = *string;
     305      newElem.name = (*string).c_str();
    311306      newElem.type = type;
    312307      this->completionList.push_back(newElem);
  • trunk/src/lib/shell/shell_completion.h

    r5784 r7221  
    5252  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    5353
    54   bool addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type);
     54  bool addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5555  bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5656  void emptyCompletionList();
  • trunk/src/lib/shell/shell_input.cc

    r6222 r7221  
    4141 * this also generates a ShellCompletion automatically.
    4242*/
    43 ShellInput::ShellInput () : Text ((const char*)NULL)
     43ShellInput::ShellInput () : Text ("")
    4444{
    4545  this->pressedKey = SDLK_FIRST;
    4646  this->setClassID(CL_SHELL_INPUT, "ShellInput");
    4747
    48   this->inputLine = new char[1];
    49   this->inputLine[0] = '\0';
     48  this->inputLine = "";
    5049  this->historyIT = this->history.begin();
    5150  this->setHistoryLength(50);
     
    7069{
    7170  // delete what has to be deleted here
    72   delete[] this->inputLine;
    7371  delete this->completion;
    7472
    7573  while (!this->history.empty())
    7674  {
    77     delete[] this->history.front();
    7875    this->history.pop_front();
    7976  }
     
    9693void ShellInput::flush()
    9794{
    98   if (likely(this->inputLine != NULL))
    99   {
    100     delete[] this->inputLine;
    101   }
    102   this->inputLine = new char[1];
    103   *this->inputLine = '\0';
    104   this->setText(this->inputLine, true);
     95  this->inputLine.clear();
     96  this->setText(this->inputLine);
    10597}
    10698
     
    109101 * @param text the new Text to set as InputLine
    110102 */
    111 void ShellInput::setInputText(const char* text)
    112 {
    113   delete[] this->inputLine;
    114   if (text == NULL)
    115   {
    116     this->inputLine = new char[1];
    117     this->inputLine[0] = '\0';
    118   }
    119   else
    120   {
    121     this->inputLine = new char[strlen(text)+1];
    122     strcpy(this->inputLine, text);
    123   }
    124   this->setText(this->inputLine, true);
     103void ShellInput::setInputText(const std::string& text)
     104{
     105  this->inputLine = text;
     106  this->setText(this->inputLine);
    125107}
    126108
     
    134116  if (this->historyScrolling)
    135117  {
    136     delete[] this->history.back();
    137118    this->history.pop_back();
    138119    this->historyScrolling = false;
    139120  }
    140121
    141   char* addCharLine = new char[strlen(this->inputLine)+2];
    142 
    143   sprintf(addCharLine, "%s%c", this->inputLine, character);
    144   delete[] this->inputLine;
    145   this->inputLine = addCharLine;
    146   this->setText(this->inputLine, true);
     122  this->inputLine += character;
     123  this->setText(this->inputLine);
    147124}
    148125
     
    151128 * @param characters a \\0 terminated char-array to add to the InputLine
    152129 */
    153 void ShellInput::addCharacters(const char* characters)
     130void ShellInput::addCharacters(const std::string& characters)
    154131{
    155132  if (this->historyScrolling)
    156133  {
    157     delete[] this->history.back();
    158134    this->history.pop_back();
    159135    this->historyScrolling = false;
    160136  }
    161137
    162   char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1];
    163 
    164   sprintf(addCharLine, "%s%s", this->inputLine, characters);
    165   delete[] this->inputLine;
    166   this->inputLine = addCharLine;
    167   this->setText(this->inputLine, true);
     138  this->inputLine += characters;
     139  this->setText(this->inputLine);
    168140}
    169141
     
    176148  if (this->historyScrolling)
    177149  {
    178     delete[] this->history.back();
    179150    this->history.pop_back();
    180151    this->historyScrolling = false;
    181152  }
    182 
    183   if (strlen(this->inputLine) == 0)
    184     return;
    185 
    186   if (characterCount > strlen(this->inputLine))
    187     characterCount = strlen(this->inputLine);
    188 
    189   char* removeCharLine = new char[strlen(this->inputLine)-characterCount+1];
    190 
    191   strncpy(removeCharLine, this->inputLine, strlen(this->inputLine)-characterCount);
    192   removeCharLine[strlen(this->inputLine)-characterCount] = '\0';
    193   delete[] this->inputLine;
    194   this->inputLine = removeCharLine;
    195   this->setText(this->inputLine, true);
     153  if (this->inputLine.size() < characterCount)
     154    characterCount = this->inputLine.size();
     155
     156  this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size());
     157  this->setText(this->inputLine);
    196158}
    197159
     
    202164bool ShellInput::executeCommand()
    203165{
    204   ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
    205 
    206   if (strlen(this->inputLine) == 0)
     166  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
     167
     168  if (this->inputLine.empty())
    207169    return false;
    208170
    209   char* newCommand = new char[strlen(this->inputLine)+1];
    210   strcpy(newCommand, this->inputLine);
    211 
    212   ShellCommand::execute(newCommand);
     171  ShellCommand::execute(this->inputLine);
    213172
    214173  // removing the eventually added Entry (from scrolling) to the List
    215174  if (this->historyScrolling)
    216175  {
    217     delete[] this->history.back();
    218176    this->history.pop_back();
    219177    this->historyScrolling = false;
     
    221179
    222180  // adding the new Command to the History
    223   this->history.push_back(newCommand);
     181  this->history.push_back(this->inputLine);
    224182  if (this->history.size() > this->historyLength)
    225183  {
    226     delete[] this->history.front();
    227184    this->history.pop_front();
    228185  }
     
    241198  if (!this->historyScrolling)
    242199  {
    243     char* currentText = new char[strlen(this->inputLine)+1];
    244     strcpy(currentText, this->inputLine);
    245     this->history.push_back(currentText);
     200    this->history.push_back(this->inputLine);
    246201    this->historyScrolling = true;
    247202    this->historyIT = --this->history.end();
     
    250205  if(this->historyIT != this->history.begin())
    251206  {
    252     char* prevElem = *(--this->historyIT);
    253     if (prevElem == NULL)
     207    std::string prevElem = *(--this->historyIT);
     208    /*if (prevElem == NULL) /// TODO STD
    254209      return;
    255     else
     210    else */
    256211    {
    257212      this->flush();
     
    270225  if (this->historyIT != this->history.end())
    271226  {
    272     char* nextElem = *(++this->historyIT);
    273     if (nextElem == NULL)
     227    std::string nextElem = *(++this->historyIT);
     228    /*    if (nextElem == NULL) /// TODO FIX STD
    274229      return;
    275     else
     230    else */
    276231    {
    277232      this->flush();
     
    285240 * prints out some nice help about the Shell
    286241 */
    287 void ShellInput::help(const char* className, const char* functionName)
    288 {
    289   printf("%s::%s\n", className, functionName);
    290 
    291   if (strlen(className) == 0)
     242void ShellInput::help(const std::string& className, const std::string& functionName)
     243{
     244  printf("%s::%s\n", className.c_str(), functionName.c_str());
     245
     246  if (className.empty())
    292247  {
    293248    PRINT(0)("Help for the most important Shell-commands\n");
     
    298253    PRINT(0)("- Also try 'help className'");
    299254  }
    300   else if (strlen (className) > 0 && strlen (functionName) == 0)
     255  else if (!className.empty() && functionName.empty())
    301256  {
    302257    ShellCommandClass::help(className);
  • trunk/src/lib/shell/shell_input.h

    r5786 r7221  
    3131
    3232  /** @returns the inputLine */
    33   const char* getInput() const { return this->inputLine; };
     33  const std::string& getInput() const { return this->inputLine; };
    3434
    3535  // InputLine
    3636  void flush();
    37   void setInputText(const char* text);
     37  void setInputText(const std::string& text);
    3838  void addCharacter(char character);
    39   void addCharacters(const char* characters);
     39  void addCharacters(const std::string& characters);
    4040  void removeCharacters(unsigned int characterCount = 1);
    4141  void setRepeatDelay(float repeatDelay, float repeatRate);
     
    4747  void historyMoveDown();
    4848
    49   void help(const char* className = "", const char* function = "");
     49  void help(const std::string& className = "", const std::string& function = "");
    5050
    5151  virtual void tick(float dt);
     
    5454 private:
    5555    // HANDLING TEXT INPUT
    56    ShellCompletion*            completion;             //!< The Completion Interface.
     56   ShellCompletion*                  completion;       //!< The Completion Interface.
    5757
    58    char*                       inputLine;              //!< the Char-Array of the Buffer
    59    float                       repeatRate;             //!< The Repeat-Delay.
    60    float                       repeatDelay;            //!< The delay of the first Character of a given Character.
    61    float                       delayed;                //!< how much of the delay is remaining.
    62    Uint16                      pressedKey;             //!< the pressed key that will be repeated.
     58   std::string                       inputLine;        //!< the Char-Array of the Buffer
     59   float                             repeatRate;       //!< The Repeat-Delay.
     60   float                             repeatDelay;      //!< The delay of the first Character of a given Character.
     61   float                             delayed;          //!< how much of the delay is remaining.
     62   Uint16                            pressedKey;       //!< the pressed key that will be repeated.
    6363
    64    std::list<char*>            history;                //!< The history of given commands.
    65    std::list<char*>::iterator  historyIT;
    66    unsigned int                historyLength;          //!< The maximum length of the InputHistory.
    67    bool                        historyScrolling;      //!< true if we are scrolling through the history.
     64   std::list<std::string>            history;          //!< The history of given commands.
     65   std::list<std::string>::iterator  historyIT;        //!< The locator that tells us, where we are in the history.
     66   unsigned int                      historyLength;    //!< The maximum length of the InputHistory.
     67   bool                              historyScrolling; //!< true if we are scrolling through the history.
    6868};
    6969
  • trunk/src/lib/sound/ogg_player.cc

    r6987 r7221  
    3131 * @param fileName the file to load
    3232 */
    33 OggPlayer::OggPlayer(const char* fileName)
     33OggPlayer::OggPlayer(const std::string& fileName)
    3434{
    3535  this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer");
     
    4040  this->buffers[1] = 0;
    4141
    42   if (fileName != NULL)
     42  if (!fileName.empty())
    4343  {
    4444    if (this->open(fileName))
     
    5656 * @param fileName the file to open
    5757 */
    58 bool OggPlayer::open(const char* fileName)
     58bool OggPlayer::open(const std::string& fileName)
    5959{
    6060  if (this->buffers[0] == 0)
     
    7272  int result;
    7373
    74   if(!(oggFile = fopen(fileName, "rb")))
     74  if(!(oggFile = fopen(fileName.c_str(), "rb")))
    7575  {
    7676    PRINTF(2)("Could not open Ogg file.");
  • trunk/src/lib/sound/ogg_player.h

    r7054 r7221  
    2727{
    2828public:
    29   OggPlayer(const char* fileName = NULL);
     29  OggPlayer(const std::string& fileName = "");
    3030  virtual ~OggPlayer();
    3131
    32   bool open(const char* fileName);
     32  bool open(const std::string& fileName);
    3333  void release();
    3434  void debug();
  • trunk/src/lib/sound/sound_buffer.cc

    r6836 r7221  
    3232 * @param fileName The name of the File
    3333 */
    34 SoundBuffer::SoundBuffer(const char* fileName)
     34SoundBuffer::SoundBuffer(const std::string& fileName)
    3535{
    3636  this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
     
    5454 * @returns true on success.
    5555 */
    56 bool SoundBuffer::loadWAV(const char* fileName)
     56bool SoundBuffer::loadWAV(const std::string& fileName)
    5757{
    5858  SDL_AudioSpec wavSpec;
     
    6161
    6262  /* Load the WAV */
    63   if( SDL_LoadWAV(fileName, &wavSpec, &wavBuffer, &wavLength) == NULL)
     63  if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL)
    6464  {
    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());
    6666    return false;
    6767  }
  • trunk/src/lib/sound/sound_buffer.h

    r6981 r7221  
    1717{
    1818  public:
    19     SoundBuffer(const char* fileName);
     19    SoundBuffer(const std::string& fileName);
    2020    virtual ~SoundBuffer();
    2121
    22     bool loadWAV(const char* fileName);
     22    bool loadWAV(const std::string& fileName);
    2323
    2424    /** @returns the ID of the buffer used in this SoundBuffer */
  • trunk/src/lib/sound/sound_engine.cc

    r7193 r7221  
    9999void SoundEngine::loadSettings(IniParser* iniParser)
    100100{
    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;
    109109}
    110110
     
    117117   acctualy this is nothing more than a wrapper around the ResourceManager.
    118118*/
    119 SoundSource* SoundEngine::createSource(const char* fileName, PNode* sourceNode)
     119SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode)
    120120{
    121121  return new SoundSource(sourceNode, (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL));
  • trunk/src/lib/sound/sound_engine.h

    r6849 r7221  
    3333    void loadSettings(IniParser* iniParser);
    3434
    35     SoundSource* createSource(const char* fileName, PNode* sourceNode = NULL);
     35    SoundSource* createSource(const std::string& fileName, PNode* sourceNode = NULL);
    3636
    3737    /** @param listener the listener in the scene */
  • trunk/src/lib/util/executor/executor.cc

    r7201 r7221  
    105105  value[4] = &value4;
    106106
    107   printf("%s ::: paramCount: %d\n", this->getName(), this->paramCount);
    108107  for (unsigned int i = 0; i < this->paramCount; i++)
    109108  {
    110109    if (*value[i] != MT_NULL)
    111110    {
    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]);
    119112    }
    120113  }
  • trunk/src/lib/util/executor/executor.h

    r7200 r7221  
    1616//! an enumerator for the definition of the Type.
    1717typedef enum {
    18   Executor_Objective         = 0x00000001,
    19   Executor_Static            = 0x00000002,
    20 
    21   Executor_NoLoadString      = 0x00000010,
     18  Executor_Objective         = 1,
     19  Executor_Static            = 2,
     20
     21  Executor_NoLoadString      = 8,
    2222} Executor_Type;
    2323
     
    4848
    4949    /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    50     virtual void execute (BaseObject* object, const void* parameters = NULL) = 0;
     50    virtual void execute (BaseObject* object, const std::string& parameters = "") = 0;
    5151
    5252    /** @returns the Type of this Function (either static or objective) */
     
    8787#define   l_FLOAT_DEFGRAB(i)        this->defaultValue[i].getFloat()
    8888//! 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
    8991#define   l_CSTRING_DEFGRAB(i)      this->defaultValue[i].getCString()
    9092
     
    190192#define ExecutorExecute1(t1) \
    191193   else if (this->paramCount == 1 && this->defaultValue[0] == t1##_PARAM) \
    192     EXECUTOREXECUTER(_1_##t1)(t1##_FUNC((const char*)parameters, t1##_DEFGRAB(0)))
     194    EXECUTOREXECUTER(_1_##t1)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)))
    193195
    194196//! execute-macro for functions with two parameters
    195197#define ExecutorExecute2(t1,t2) \
    196198   else if (this->paramCount == 2 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM) \
    197     EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))
     199    EXECUTOREXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)))
    198200
    199201//! execute-macro for functions with three parameters
    200202#define ExecutorExecute3(t1,t2,t3) \
    201203   else if (this->paramCount == 3 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM) \
    202     EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)))
     204    EXECUTOREXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)))
    203205
    204206//! execute-macro for functions with four parameters
    205207#define ExecutorExecute4(t1,t2,t3,t4) \
    206208   else if (this->paramCount == 4 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM) \
    207     EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) \
     209    EXECUTOREXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3))) \
    208210
    209211
     
    211213#define ExecutorExecute5(t1,t2,t3,t4,t5) \
    212214   else if (this->paramCount == 5 && this->defaultValue[0] == t1##_PARAM && this->defaultValue[1] == t2##_PARAM && this->defaultValue[2] == t3##_PARAM && this->defaultValue[3] == t4##_PARAM && this->defaultValue[4] == t5##_PARAM) \
    213     EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4)))
     215    EXECUTOREXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub[0], t1##_DEFGRAB(0)), t2##_FUNC(sub[1], t2##_DEFGRAB(1)), t3##_FUNC(sub[2], t3##_DEFGRAB(2)), t4##_FUNC(sub[3], t4##_DEFGRAB(3)), t5##_FUNC(sub[4], t5##_DEFGRAB(4)))
    214216
    215217
     
    240242#define EXECUTORTYPE                   Executor_Objective
    241243//! keeps information about a Executor
    242 template<class T> class ExecutorObjective : public Executor
     244template<class T> class EXECUTOR : public Executor
    243245{
    244246  public:
    245     ExecutorObjective() : Executor() { };
     247    EXECUTOR() : Executor() { };
    246248    // COPY constuctor (virtual version)
    247249    virtual Executor* clone () const
    248250    {
    249       ExecutorObjective<T>* executor = new ExecutorObjective<T>();
     251      EXECUTOR<T>* executor = new EXECUTOR<T>();
    250252      this->cloning(executor);
    251253      executor->fp = this->fp;
     
    266268    } fp;
    267269
    268     virtual void execute (BaseObject* object, const void* parameters = NULL)
     270    virtual void execute (BaseObject* object, const std::string& parameters = "")
    269271    {
    270       SubString sub((const char*) parameters, " \n\t,", '\\');
    271       printf("%s :: %s\n", this->getName(), (const char*) parameters);
     272      SubString sub;
     273      sub.split(parameters, " \n\t,", '\\');
    272274//! FUNCTOR_LIST is the List of Executive Functions
    273275#define FUNCTOR_LIST(x) ExecutorExecute ## x
     
    305307{
    306308  public:
    307     ExecutorStatic() : Executor() { };
     309    EXECUTOR() : Executor() { };
    308310    // COPY constuctor
    309311    virtual Executor* clone () const
    310312    {
    311       ExecutorStatic<T>* executor = new ExecutorStatic<T>();
     313      EXECUTOR<T>* executor = new EXECUTOR<T>();
    312314      this->cloning(executor);
    313315      executor->fp = this->fp;
     
    329331
    330332
    331     virtual void execute (BaseObject* object, const void* parameters = NULL)
     333    virtual void execute (BaseObject* object, const std::string& parameters = "")
    332334    {
    333   SubString sub((const char*)parameters, " \n\t,");
     335      SubString sub;
     336      sub.split(parameters, " \n\t,", '\\');
    334337//! FUNCTOR_LIST is the List of Executive Functions
    335338#define FUNCTOR_LIST(x) ExecutorExecute ## x
  • trunk/src/lib/util/executor/executor_specials.h

    r7197 r7221  
    6060     * @param loadString ignored in this case
    6161     */
    62     virtual void execute(BaseObject* object, const void* parameters = NULL)
     62    virtual void execute(BaseObject* object, const std::string& = "")
    6363    {
    6464      if (object != NULL && this->element != NULL)
  • trunk/src/lib/util/executor/functor_list.h

    r7199 r7221  
    2121   l_SHORT:     short
    2222   l_FLOAT:     float
    23    l_CSTRING:    const char*
     23   l_STRING:    const std::string&
    2424   l_XML_ELEM:  TiXmlElement*
    2525 */
     
    7474//#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
    7575
    76 #define l_CSTRING_TYPE     const char*          //!< The type of a STRING
    77 #define l_CSTRING_FUNC     isString             //!< The function to parse a STRING
    78 #define l_CSTRING_NAME     "string"             //!< The name of a STRING
    79 #define l_CSTRING_PARAM    MT_STRING            //!< the type of the parameter STRING
    80 #define l_CSTRING_DEFAULT  ""                   //!< a default Value for an STRING
    81 
    8276#define l_STRING_TYPE      const std::string&   //!< The type of a STRING
    8377#define l_STRING_FUNC      isString             //!< The function to parse a STRING
    8478#define l_STRING_NAME      "string"             //!< The name of a STRING
    85 #define l_STRING_PARAM     MT_STRING            //!< the type of the parameter STRING
     79#define l_STRING_PARAM     MT_STRING           //!< the type of the parameter STRING
    8680#define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
    8781
     
    9993  FUNCTOR_LIST(0)();
    10094  //! makes functions with one string
    101   FUNCTOR_LIST(1)(l_CSTRING);
     95  FUNCTOR_LIST(1)(l_STRING);
    10296  //! makes functions with two strings
    103   FUNCTOR_LIST(2)(l_CSTRING, l_CSTRING);
     97  FUNCTOR_LIST(2)(l_STRING, l_STRING);
    10498  //! makes functions with three strings
    105   FUNCTOR_LIST(3)(l_CSTRING, l_CSTRING, l_CSTRING);
     99  FUNCTOR_LIST(3)(l_STRING, l_STRING, l_STRING);
    106100  //! makes functions with four strings
    107   FUNCTOR_LIST(4)(l_CSTRING, l_CSTRING, l_CSTRING, l_CSTRING);
     101  FUNCTOR_LIST(4)(l_STRING, l_STRING, l_STRING, l_STRING);
     102
    108103
    109104  //! makes functions with one bool
     
    141136
    142137  //! mixed values:
    143   FUNCTOR_LIST(2)(l_CSTRING, l_FLOAT);
     138  FUNCTOR_LIST(2)(l_STRING, l_FLOAT);
    144139  FUNCTOR_LIST(2)(l_UINT, l_LONG);
    145   FUNCTOR_LIST(2)(l_CSTRING, l_UINT);
     140  FUNCTOR_LIST(2)(l_STRING, l_UINT);
    146141
    147   FUNCTOR_LIST(3)(l_CSTRING, l_FLOAT, l_UINT);
     142  FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT);
    148143
    149144
  • trunk/src/lib/util/helper_functions.cc

    r5331 r7221  
    2222
    2323/**
    24  * checks if the input was a bool
     24 * @brief checks if the input was a bool
    2525 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false(case-insensitive)
    2626 * @param defaultValue a default value that is set, if BOOL is corrupt
    2727 * @return returns the bool, if BOOL was correct otherwise defaultValue
    2828 */
    29 bool isBool(const char* BOOL, bool defaultValue)
     29bool isBool(const std::string& BOOL, bool defaultValue)
    3030{
    31   if (BOOL == NULL)
     31  if (BOOL.empty())
    3232    return defaultValue;
    33   if(!strcmp(BOOL, "1") || !strcasecmp( BOOL, "true") )
     33  if(BOOL[0] == '1' || BOOL == "true" )
    3434    return true;
    35   else if (!strcmp(BOOL, "0") || !strcasecmp( BOOL, "false"))
     35  else if (BOOL[0] == '0' || BOOL == "false")
    3636    return false;
    3737  else
    3838    return defaultValue;
    39 
    4039}
    4140
    4241
    4342/**
    44  * checks if the input was a int
     43 * @brief checks if the input was a int
    4544 * @param INT a String that holds an int.
    4645 * @param defaultValue a default value that is set, if INT is corrupt
    4746 * @return returns the contained int, if INT was correct otherwise defaultValue
    4847 */
    49 int isInt(const char* INT, int defaultValue)
     48int isInt(const std::string& INT, int defaultValue)
    5049{
    51   if (INT == NULL)
     50  if (INT.empty())
    5251    return defaultValue;
    5352  char* endPtr = NULL;
    5453
    55   int result = strtol(INT, &endPtr, 10);
     54  int result = strtol(INT.c_str(), &endPtr, 10);
    5655
    57   if ( endPtr >= INT && endPtr < INT + strlen(INT))
     56  if ( endPtr >= INT.c_str() && endPtr < INT.c_str()+ INT.size())
    5857    return defaultValue;
    5958  else
     
    6362
    6463/**
    65  * checks if the input was a float
     64 * @brief checks if the input was a float
    6665 * @param FLOAT a String that holds an float.
    6766 * @param defaultValue a default value that is set, if FLOAT is corrupt
    6867 * @return returns the contained float, if FLOAT was correct otherwise defaultValue
    6968 */
    70 float isFloat(const char* FLOAT, float defaultValue)
     69float isFloat(const std::string& FLOAT, float defaultValue)
    7170{
    72   if (FLOAT == NULL)
     71  if (FLOAT.empty())
    7372    return defaultValue;
    7473  char* endPtr = NULL;
    75   double result = strtod(FLOAT, &endPtr);
     74  double result = strtod(FLOAT.c_str(), &endPtr);
    7675
    77   if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
     76  if ( endPtr >= FLOAT.c_str() && endPtr < FLOAT.c_str() + FLOAT.size())
    7877    return defaultValue;
    7978  else
     
    8382
    8483/**
    85  * checks if the input was a string
     84 * @brief checks if the input was a string
    8685 * @param STING a String(char-array) that holds an string.
    8786 * @param defaultValue a default value that is set, if STRING is corrupt
    8887 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
    8988 */
    90 const char* isString(const char* STRING, const char* defaultValue)
     89const char* isCString(const std::string& STRING, const char* defaultValue)
    9190{
    92   if (STRING != NULL && strlen(STRING) > 0)
     91  if (STRING.size() > 0)
     92    return STRING.c_str();
     93  else
     94    return defaultValue;
     95}
     96
     97/**
     98 * @brief checks if the input was a string
     99 * @param STING a String(char-array) that holds an string.
     100 * @param defaultValue a default value that is set, if STRING is corrupt
     101 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
     102 */
     103std::string isString(const std::string& STRING, const std::string& defaultValue)
     104{
     105  if (STRING.size() > 0)
    93106    return STRING;
    94107  else
    95108    return defaultValue;
    96109}
     110
     111
     112/**
     113 * @brief compares two strings without ignoring the case
     114 * @param s1 first string
     115 * @param s2 second string
     116 */
     117int nocase_cmp(const std::string& s1, const std::string& s2)
     118{
     119  std::string::const_iterator it1=s1.begin();
     120  std::string::const_iterator it2=s2.begin();
     121
     122  //stop when either string's end has been reached
     123  while ( (it1!=s1.end()) && (it2!=s2.end()) )
     124  {
     125    if(::toupper(*it1) != ::toupper(*it2)) //letters differ?
     126     // return -1 to indicate smaller than, 1 otherwise
     127      return (::toupper(*it1)  < ::toupper(*it2)) ? -1 : 1;
     128    //proceed to the next character in each string
     129    ++it1;
     130    ++it2;
     131  }
     132  size_t size1=s1.size(), size2=s2.size();// cache lengths
     133   //return -1,0 or 1 according to strings' lengths
     134  if (size1==size2)
     135    return 0;
     136  return (size1<size2) ? -1 : 1;
     137}
     138
  • trunk/src/lib/util/helper_functions.h

    r5141 r7221  
    77#define _HELPER_FUNCTIONS_H
    88
     9#include <string>
     10
    911// FORWARD DECLARATION
    1012
     
    1214*** HELPER FUNCTIONS ***
    1315***********************/
    14 bool          isBool(const char* BOOL, bool defaultValue);
    15 int           isInt(const char* INT, int defaultValue);
    16 float         isFloat(const char* FLOAT, float defaultValue);
    17 const char*   isString(const char* STRING, const char* defaultValue);
     16bool          isBool(const std::string& BOOL, bool defaultValue);
     17int           isInt(const std::string& INT, int defaultValue);
     18float         isFloat(const std::string& FLOAT, float defaultValue);
     19const char*   isCString(const std::string& STRING, const char* defaultValue);
     20std::string   isString(const std::string& STRING, const std::string& defaultValue);
     21
     22
     23int           nocase_cmp(const std::string& s1, const std::string& s2);
     24
    1825
    1926#endif /* _HELPER_FUNCTIONS_H */
  • trunk/src/lib/util/loading/factory.cc

    r7193 r7221  
    2323//SHELL_COMMAND(create, Factory, fabricate);
    2424
    25 
    26 /*  --------------------------------------------------
    27  *               Factory
    28  *   --------------------------------------------------
     25/**
     26 * @brief constructor
     27 *
     28 * set everything to zero and define factoryName
    2929 */
    30 
    31 /**
    32  *  constructor
    33 
    34    set everything to zero and define factoryName
    35 */
    36 Factory::Factory (const char* factoryName, ClassID classID)
     30Factory::Factory (const std::string& factoryName, ClassID classID)
     31  : className(factoryName), classID(classID)
    3732{
    3833  this->setClassID(CL_FACTORY, "Factory");
    3934  this->setName(factoryName);
    40 
    41   this->classID = classID;
    42   this->className = factoryName;
    4335
    4436  if( Factory::factoryList == NULL)
     
    4840}
    4941
    50 /** a reference to the First Factory */
     42/** @brief a reference to the First Factory */
    5143std::list<Factory*>* Factory::factoryList = NULL;
    5244
    5345/**
    54  *  destructor
    55  *
    56  * clear the Q
     46 * @brief destructor
    5747 */
    5848Factory::~Factory ()
     
    6454
    6555/**
    66  * deletes all the Factories. (cleanup)
     56 * @brief deletes all the Factories. (cleanup)
    6757 */
    6858void Factory::deleteFactories()
     
    9080
    9181/**
    92  * Compares the Factories Name against a given ClassName
     82 * @brief Compares the Factories Name against a given ClassName
    9383 * @param className the Name of the Class to Query
    9484 * @returns true on match, false otherwise.
     
    9686bool Factory::operator==(const char* className) const
    9787{
    98   return(className != NULL && !strcmp(className, this->className));
     88  return(className != NULL && this->className == className);
     89}
     90
     91/**
     92 * @brief Compares the Factories Name against a given ClassName
     93 * @param className the Name of the Class to Query
     94 * @returns true on match, false otherwise.
     95 */
     96bool Factory::operator==(const std::string& className) const
     97{
     98  return(this->className == className);
    9999}
    100100
    101101
    102102/**
    103  * Creates a new Object of type root->Value() (name)
     103 * @brief Creates a new Object of type root->Value() (name)
    104104 * @param root the XML-Root to match for the newly created Object
    105105 * @returns a new Object of Type root->Value() on match, NULL otherwise
     
    133133 * @returns a new Object of Type className on match, NULL otherwise
    134134 */
    135  BaseObject* Factory::fabricate(const char* className)
     135 BaseObject* Factory::fabricate(const std::string& className)
    136136{
    137   if (className == NULL || Factory::factoryList == NULL)
     137  if (Factory::factoryList == NULL)
    138138    return NULL;
    139139
     
    178178  else
    179179  {
    180     PRINTF(2)("Could not Fabricate an Object of ClassID '%h'\n", classID);
     180    PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID);
    181181    return NULL;
    182182  }
  • trunk/src/lib/util/loading/factory.h

    r7167 r7221  
    2727#include "parser/tinyxml/tinyxml.h"
    2828#include "base_object.h"
    29 #include "debug.h"
    3029#include <vector>
    3130#include <list>
     
    3433 * Creates a factory to a Loadable Class.
    3534 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    36 */
     35 */
    3736#define CREATE_FACTORY(CLASS_NAME, CLASS_ID) \
    3837    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)
     
    4948  static void deleteFactories();
    5049
    51   static  BaseObject* fabricate(const char* className);
     50  static  BaseObject* fabricate(const std::string& className);
    5251  static  BaseObject* fabricate(ClassID classID);
    5352  static  BaseObject* fabricate(const TiXmlElement* root = NULL);
     
    5655  bool operator==(ClassID classID) const;
    5756  bool operator==(const char* className) const;
     57  bool operator==(const std::string& className) const;
    5858
    5959  protected:
    60     Factory (const char* factoryName, ClassID classID);
     60    Factory (const std::string& factoryName, ClassID classID);
    6161    virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
    6262
    6363  protected:
    64     ClassID                       classID;              //!< The Class-Identifyer of the Factory.
    65     const char*                   className;            //!< The name of the Class.
     64    const ClassID                 classID;              //!< The Class-Identifyer of the Factory.
     65    const std::string             className;            //!< The name of the Class.
    6666    static std::list<Factory*>*   factoryList;          //!< List of Registered Factories
    6767};
    6868
    6969/**
    70  *  a factory that is able to load any kind of Object
     70 *  @brief a factory that is able to load any kind of Object
    7171 * (this is a Functor)
    7272 */
     
    7575 public:
    7676 /**
    77   * creates a new type Factory to enable the loading of T
     77  * @brief creates a new type Factory to enable the loading of T
    7878  * @param factoryName the Name of the Factory to load.
    7979  * @param classID the ID of the Class to be created.
     
    8585  private:
    8686   /**
    87     * fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
     87    * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*)
    8888    * @param root the TiXmlElement T should load parameters from.
    8989    * @return the newly fabricated T.
  • trunk/src/lib/util/loading/game_loader.cc

    r7193 r7221  
    8686 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    8787 */
    88 ErrorMessage GameLoader::loadCampaign(const char* fileName)
     88ErrorMessage GameLoader::loadCampaign(const std::string& fileName)
    8989{
    9090  ErrorMessage errorCode;
    91   char* campaignName = ResourceManager::getFullName(fileName);
    92   if (campaignName)
     91  std::string campaignName = ResourceManager::getFullName(fileName);
     92  if (!campaignName.empty())
    9393    {
    9494      this->currentCampaign = this->fileToCampaign(campaignName);
    95       delete[] campaignName;
    9695    }
    9796}
     
    105104 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    106105 */
    107 ErrorMessage GameLoader::loadNetworkCampaign(const char* fileName)
     106ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName)
    108107{
    109108  ErrorMessage errorCode;
    110   char* campaignName = ResourceManager::getFullName(fileName);
    111   if (campaignName)
     109  std::string campaignName = ResourceManager::getFullName(fileName);
     110  if (!campaignName.empty())
    112111  {
    113112    this->currentCampaign = this->fileToCampaign(campaignName);
    114     delete[] campaignName;
    115113  }
    116114}
     
    220218 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    221219 */
    222 Campaign* GameLoader::fileToCampaign(const char* fileName)
     220Campaign* GameLoader::fileToCampaign(const std::string& fileName)
    223221{
    224222  /* do not entirely load the campaign. just the current world
     
    227225  */
    228226
    229   if( fileName == NULL)
     227  if( fileName.empty())
    230228    {
    231229      PRINTF(2)("No filename specified for loading");
     
    233231    }
    234232
    235   TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
     233  TiXmlDocument XMLDoc(fileName);
    236234  // load the campaign document
    237   if( !XMLDoc->LoadFile())
     235  if( !XMLDoc.LoadFile(fileName))
    238236    {
    239237      // 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());
    242239      return NULL;
    243240    }
    244241
    245242  // check basic validity
    246   TiXmlElement* root = XMLDoc->RootElement();
     243  TiXmlElement* root = XMLDoc.RootElement();
    247244  assert( root != NULL);
    248245
     
    251248      // report an error
    252249      PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    253       delete XMLDoc;
    254250      return NULL;
    255251    }
    256252
    257253  // 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);
    264255}
    265256
  • trunk/src/lib/util/loading/game_loader.h

    r6981 r7221  
    4444  static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; }
    4545
    46   ErrorMessage loadCampaign(const char* name);
     46  ErrorMessage loadCampaign(const std::string& name);
    4747  ErrorMessage loadDebugCampaign(Uint32 campaignID);
    48   ErrorMessage loadNetworkCampaign(const char* fileName);
     48  ErrorMessage loadNetworkCampaign(const std::string& fileName);
    4949
    5050  ErrorMessage init();
     
    6262  GameLoader ();
    6363
    64   Campaign* fileToCampaign(const char* name);
     64  Campaign* fileToCampaign(const std::string& name);
    6565
    6666
  • trunk/src/lib/util/loading/load_param.cc

    r7201 r7221  
    2828 * @param executor the Executor, that executes the loading procedure.
    2929 */
    30 CLoadParam::CLoadParam(const TiXmlElement* root, const char* paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)
    31 {
    32   this->paramName = paramName;
     30CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)
     31  :  paramName(paramName), object(object)
     32{
    3333  this->object = object;
    3434  this->inLoadCycle = inLoadCycle;
     
    3737  if (likely(!inLoadCycle))
    3838    this->loadElem = grabParameterElement(root, paramName);
    39   //this->loadString = grabParameter(root, paramName);
    40   else if (!strcmp(root->Value(), paramName))
     39  else if (paramName == root->Value())
    4140    this->loadElem = (TiXmlElement*)root->FirstChild();
    4241  else
     
    4645  this->executor = executor.clone();
    4746
    48   if (this->executor)
    49     this->executor->setName(paramName);
     47  //if (this->executor)
     48  //  this->executor->setName(paramName);
    5049}
    5150
     
    6059  if (likely(this->executor != NULL))
    6160  {
     61    std::string loadString = "";
    6262    if (this->loadElem != NULL &&  this->loadElem->ToText())
    63       this->loadString = this->loadElem->Value();
    64     else
    65       this->loadString = NULL;
     63      loadString = this->loadElem->Value();
    6664    if (likely(this->object != NULL) &&
    67         ( this->loadString != NULL ||
     65        ( !loadString.empty() ||
    6866          ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString)))
    6967    {
    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 value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassName(), this->object->getName());
     69      this->executor->execute(this->object, loadString);
    7270    }
    7371    delete this->executor;
     
    9997 * @returns a pointer to itself.
    10098*/
    101 CLoadParam& CLoadParam::describe(const char* descriptionText)
    102 {
    103   if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
     99CLoadParam& CLoadParam::describe(const std::string& descriptionText)
     100{
     101  if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty())
    104102  {
    105103    this->paramDesc->setDescription(descriptionText);
     
    230228 * @returns the Value of the parameter if found, NULL otherwise
    231229*/
    232 const char* grabParameter(const TiXmlElement* root, const char* parameterName)
     230std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)
    233231{
    234232  const TiXmlElement* element;
    235233  const TiXmlNode* node;
    236234
    237   if (root == NULL || parameterName == NULL)
    238     return NULL;
    239   assert( parameterName != NULL);
     235  if (root == NULL)
     236    return "";
    240237
    241238  element = root->FirstChildElement( parameterName);
    242   if( element == NULL) return NULL;
     239  if( element == NULL) return "";
    243240
    244241  node = element->FirstChild();
     
    248245    node = node->NextSibling();
    249246  }
    250   return NULL;
     247  return "";
    251248}
    252249
     
    256253 * @returns the Element of the parameter if found, NULL otherwise
    257254 */
    258 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char* parameterName)
     255const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)
    259256{
    260257  const TiXmlElement* element;
    261258  const TiXmlNode* node;
    262259
    263   if (root == NULL || parameterName == NULL)
     260  if (root == NULL)
    264261    return NULL;
    265   assert( parameterName != NULL);
    266262
    267263  element = root->FirstChildElement( parameterName);
  • trunk/src/lib/util/loading/load_param.h

    r7198 r7221  
    8787{
    8888  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);
    9090    virtual ~CLoadParam();
    9191
    92     CLoadParam& describe(const char* descriptionText);
     92    CLoadParam& describe(const std::string& descriptionText);
    9393    CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
    9494                              const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
    9595                              const MultiType& value4 = MT_NULL);
    96     CLoadParam& attribute(const char* attributeName, const Executor& executor);
     96    CLoadParam& attribute(const std::string& attributeName, const Executor& executor);
    9797
    9898
     
    101101    Executor*                executor;
    102102    BaseObject*              object;
    103     const char*              paramName;
     103    const std::string        paramName;
    104104
    105105    LoadClassDescription*    classDesc;            //!< The LoadClassDescription of this CLoadParameter
    106106    LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
    107107    const TiXmlElement*      loadElem;             //!< The Element to load.
    108     const char*              loadString;           //!< The string loaded by this LoadParam
    109108    const void*              pointerToParam;       //!< A Pointer to a Parameter.
    110109
     
    114113// helper function
    115114
    116 const char* grabParameter(const TiXmlElement* root, const char* parameterName);
    117 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char* parameterName);
     115std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
     116const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
    118117
    119118#endif /* _LOAD_PARAM_H */
  • trunk/src/lib/util/loading/load_param_description.cc

    r7130 r7221  
    2222 * @param paramName the name of the parameter to load
    2323 */
    24 LoadParamDescription::LoadParamDescription(const char* paramName)
     24LoadParamDescription::LoadParamDescription(const std::string& paramName)
    2525{
    2626  this->types = NULL;
    27   this->description = NULL;
    2827  this->defaultValues = NULL;
    29   this->paramName = new char[strlen(paramName)+1];
    30   strcpy(this->paramName, paramName);
     28  this->paramName = paramName;
    3129}
    3230
     
    4644  delete[] this->types;
    4745  delete[] this->defaultValues;
    48   delete[] this->paramName;
    49   delete[] this->description;
    5046}
    5147
     
    5349 * @param descriptionText The text to set as a description for this Parameter
    5450 */
    55 void LoadParamDescription::setDescription(const char* descriptionText)
    56 {
    57   this->description = new char[strlen(descriptionText)+1];
    58   strcpy(this->description, descriptionText);
     51void LoadParamDescription::setDescription(const std::string& descriptionText)
     52{
     53  this->description = descriptionText;
    5954}
    6055
     
    6459void LoadParamDescription::print() const
    6560{
    66   PRINT(3)(" <%s>", this->paramName);
     61  PRINT(3)(" <%s>", this->paramName.c_str());
    6762  for (int i = 0; i < this->paramCount; i++)
    6863  {
     
    10196//     }
    10297  }
    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());
    106101  // default values
    107102  if (this->paramCount > 0)
     
    139134 * @param className the name of the class to be loadable
    140135 */
    141 LoadClassDescription::LoadClassDescription(const char* className)
    142 {
    143   this->className = new char[strlen(className)+1];
    144   strcpy(this->className, className);
     136LoadClassDescription::LoadClassDescription(const std::string& className)
     137{
     138  this->className = className;
    145139
    146140  if (LoadClassDescription::classList == NULL)
     
    161155    this->paramList.pop_front();
    162156  }
    163 
    164   delete[] this->className;
    165157}
    166158
     
    187179   Otherwise it returns a new classDescription
    188180 */
    189 LoadClassDescription* LoadClassDescription::addClass(const char* className)
     181LoadClassDescription* LoadClassDescription::addClass(const std::string& className)
    190182{
    191183  if (LoadClassDescription::classList != NULL)
     
    194186    while (it != LoadClassDescription::classList->end())
    195187    {
    196       if (!strcmp((*it)->className, className))
     188      if ((*it)->className == className)
    197189      {
    198190        return (*it);
     
    205197
    206198/**
    207  *  does the same as addClass(const char* className), but with params
     199 *  does the same as addClass(const std::string& className), but with params
    208200 * @param paramName the name of the parameter to add.
    209201 */
    210 LoadParamDescription* LoadClassDescription::addParam(const char* paramName)
     202LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName)
    211203{
    212204  std::list<LoadParamDescription*>::iterator it = this->paramList.begin();
    213205  while (it != this->paramList.end())
    214206  {
    215     if (!strcmp((*it)->paramName, paramName))
     207    if ((*it)->paramName == paramName)
    216208    {
    217209      return NULL;
     
    231223 * @todo implement it
    232224 */
    233 void LoadClassDescription::printAll(const char* fileName)
     225void LoadClassDescription::printAll(const std::string& fileName)
    234226{
    235227  PRINT(3)("===============================================================\n");
     
    240232    while (classDesc != LoadClassDescription::classList->end())
    241233    {
    242       PRINT(3)("<%s>\n", (*classDesc)->className);
     234      PRINT(3)("<%s>\n", (*classDesc)->className.c_str());
    243235      std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin();
    244236      while (param != (*classDesc)->paramList.end())
     
    247239        param++;
    248240      }
    249       PRINT(3)("</%s>\n\n", (*classDesc)->className);
     241      PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str());
    250242      classDesc++;
    251243    }
     
    262254 * !! The strings MUST NOT be deleted !!
    263255 */
    264 std::list<const char*> LoadClassDescription::searchClassWithShort(const char* classNameBegin)
     256std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin)
    265257{
    266258  /// FIXME
    267259  // NOT USED
    268260/*  unsigned int searchLength = strlen(classNameBegin);
    269   std::list<const char*> retVal;
     261  std::list<const std::string&> retVal;
    270262
    271263  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
  • trunk/src/lib/util/loading/load_param_description.h

    r7130 r7221  
    3636  friend class LoadParam;
    3737  friend class LoadClassDescription;
    38  public:
    39   LoadParamDescription(const char* paramName);
     38public:
     39  LoadParamDescription(const std::string& paramName);
    4040  ~LoadParamDescription();
    4141
    42   void setDescription(const char* descriptionText);
     42  void setDescription(const std::string& descriptionText);
    4343  /** @returns the descriptionString */
    44   const char* getDescription() { return this->description; };
     44  const std::string& getDescription() { return this->description; };
    4545
    4646  void print() const;
    4747
    48  private:
    49   char*         paramName;             //!< The name of the parameter.
     48private:
     49  std::string   paramName;             //!< The name of the parameter.
    5050  int           paramCount;            //!< The count of parameters.
    5151  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.
    5353  char**        defaultValues;         //!< The 'Default Values'. @TODO MAKE THIS A MULTITYPE
    5454};
     
    5858{
    5959  friend class CLoadParam;
    60  public:
    61   LoadClassDescription(const char* className);
     60public:
     61  LoadClassDescription(const std::string& className);
    6262  ~LoadClassDescription();
    6363
    64   static LoadClassDescription* addClass(const char* className);
    65   LoadParamDescription* addParam(const char* paramName);
     64  static LoadClassDescription* addClass(const std::string& className);
     65  LoadParamDescription* addParam(const std::string& paramName);
    6666
    6767  static void deleteAllDescriptions();
    6868
    69   static void printAll(const char* fileName = NULL);
    70   static std::list<const char*> searchClassWithShort(const char* classNameBegin);
    71 //  static const LoadParamDescription* getClass(const char* className);
     69  static void printAll(const std::string& fileName = "");
     70  static std::list<std::string> searchClassWithShort(const std::string& classNameBegin);
     71  //  static const LoadParamDescription* getClass(const std::string& className);
    7272
    73  private:
     73private:
    7474  static bool                              parametersDescription;  //!< if parameter-description should be enabled.
    7575  static std::list<LoadClassDescription*>* classList;              //!< a list, that stores all the loadable classes. (after one instance has been loaded)
    76   char*                                    className;              //!< name of the class
     76  std::string                              className;              //!< name of the class
    7777
    7878  std::list<LoadParamDescription*>         paramList;              //!< List of parameters this class knows.
  • trunk/src/lib/util/loading/resource_manager.cc

    r7199 r7221  
    5959  this->setName("ResourceManager");
    6060
    61   this->dataDir = new char[3];
    62   strcpy(this->dataDir, "./");
     61  this->dataDir = "./";
     62  this->_cwd = "";
    6363  this->tryDataDir("./data");
    64 
    65   this->_cwd = NULL;
    6664}
    6765
     
    8078    PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
    8179
    82   // deleting the Directorie Lists
    83   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;
    9280  ResourceManager::singletonRef = NULL;
    9381}
     
    9785 * @param dataDir the DataDirectory.
    9886 */
    99 bool ResourceManager::setDataDir(const char* dataDir)
    100 {
    101   char* realDir = ResourceManager::homeDirCheck(dataDir);
     87bool ResourceManager::setDataDir(const std::string& dataDir)
     88{
     89  std::string realDir = ResourceManager::homeDirCheck(dataDir);
    10290  if (isDir(realDir))
    10391  {
    104     delete[] this->dataDir;
    105     if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
     92    if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\')
    10693    {
    107       this->dataDir = new char[strlen(realDir)+1];
    108       strcpy(this->dataDir, realDir);
     94      this->dataDir = realDir;
    10995    }
    11096    else
    11197    {
    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 += '/';
    116100    }
    117     delete[] realDir;
    118101    return true;
    119102  }
    120103  else
    121104  {
    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());
    124106    return false;
    125107  }
     
    132114 * this is essentially the same as setDataDir, but it ommits the error-message
    133115 */
    134 bool ResourceManager::tryDataDir(const char* dataDir)
    135 {
    136   char* realDir = ResourceManager::homeDirCheck(dataDir);
     116bool ResourceManager::tryDataDir(const std::string& dataDir)
     117{
     118  std::string realDir = ResourceManager::homeDirCheck(dataDir);
    137119  if (isDir(realDir))
    138120  {
    139     delete[] this->dataDir;
    140     if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
     121    if (dataDir[dataDir.size()-1] == '/' || dataDir[dataDir.size()-1] == '\\')
    141122    {
    142       this->dataDir = new char[strlen(realDir)+1];
    143       strcpy(this->dataDir, realDir);
     123      this->dataDir = realDir;
    144124    }
    145125    else
    146126    {
    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 += '/';
    151129    }
    152     delete[] realDir;
    153130    return true;
    154131  }
    155   delete[] realDir;
    156132  return false;
    157133}
     
    162138 * @param fileInside is iniside of the given directory.
    163139*/
    164 bool ResourceManager::verifyDataDir(const char* fileInside)
     140bool ResourceManager::verifyDataDir(const std::string& fileInside)
    165141{
    166142  bool retVal;
    167143  if (!isDir(this->dataDir))
    168144  {
    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;
    175150  retVal = isFile(testFile);
    176   delete[] testFile;
    177151  return retVal;
    178152}
     
    185159   false otherwise
    186160*/
    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';
     161bool 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 += '/';
    204172  }
    205173  // check if the param is a Directory
     
    207175  {
    208176    // check if the Directory has been added before
    209     std::vector<char*>::const_iterator imageDir;
     177    std::vector<std::string>::const_iterator imageDir;
    210178    for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    211179    {
    212       if (!strcmp(*imageDir, newDir))
     180      if (*imageDir == newDir)
    213181      {
    214         PRINTF(3)("Path %s already loaded\n", newDir);
    215         delete[] newDir;
     182        PRINTF(3)("Path %s already loaded\n", newDir.c_str());
    216183        return true;
    217184      }
     
    223190  else
    224191  {
    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());
    227193    return false;
    228194  }
     
    239205 * @returns a pointer to a desired Resource.
    240206*/
    241 BaseObject* ResourceManager::load(const char* fileName, ResourcePriority prio,
     207BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio,
    242208                                  const MultiType& param0, const MultiType& param1, const MultiType& param2)
    243209{
    244   if (fileName == NULL)
    245     return NULL;
    246210  ResourceType tmpType;
    247211#ifndef NO_MODEL
    248212#define __IF_OK
    249   if (!strncasecmp(fileName+(strlen(fileName)-4), ".obj", 4))
     213  if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4))
    250214    tmpType = OBJ;
    251   else if (!strncmp(fileName+(strlen(fileName)-4), ".md2", 4))
     215  else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4))
    252216    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"))
    258222    tmpType = PRIM;
    259223#endif /* NO_MODEL */
     
    263227#endif
    264228#define __IF_OK
    265     if (!strncasecmp(fileName+(strlen(fileName)-4), ".wav", 4))
     229    if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4))
    266230      tmpType = WAV;
    267     else if (!strncasecmp(fileName+(strlen(fileName)-4), ".mp3", 4))
     231    else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4))
    268232      tmpType = MP3;
    269     else if (!strncasecmp(fileName+(strlen(fileName)-4), ".ogg", 4))
     233    else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4))
    270234      tmpType = OGG;
    271235#endif /* NO_AUDIO */
     
    275239#endif
    276240#define __IF_OK
    277       if (!strncasecmp(fileName+(strlen(fileName)-4), ".ttf", 4))
     241      if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4))
    278242        tmpType = TTF;
    279243#endif /* NO_TEXT */
     
    283247#endif
    284248#define __IF_OK
    285         if (!strncasecmp(fileName+(strlen(fileName)-5), ".vert", 5))
     249        if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5))
    286250          tmpType = SHADER;
    287251#endif /* NO_SHADERS */
     
    308272 * during the initialisation instead of at Runtime.
    309273 */
    310 bool ResourceManager::cache(const char* fileName, ResourceType type, ResourcePriority prio,
     274bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio,
    311275                            const MultiType& param0, const MultiType& param1, const MultiType& param2)
    312276{
    313   assert(fileName != NULL);
    314 
    315277  // searching if the resource was loaded before.
    316278  Resource* tmpResource;
     
    359321 * @returns a pointer to a desired Resource.
    360322*/
    361 BaseObject* ResourceManager::load(const char* fileName, ResourceType type, ResourcePriority prio,
     323BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio,
    362324                                  const MultiType& param0, const MultiType& param1, const MultiType& param2)
    363325{
    364   assert(fileName != NULL);
    365326
    366327  // searching if the resource was loaded before.
     
    397358 * @returns a pointer to a desired Resource.
    398359 */
    399 Resource* ResourceManager::loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
     360Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
    400361                                        const MultiType& param0, const MultiType& param1, const MultiType& param2)
    401362{
     
    406367  tmpResource->prio = prio;
    407368  tmpResource->pointer = NULL;
    408   tmpResource->name = new char[strlen(fileName)+1];
    409   strcpy(tmpResource->name, fileName);
     369  tmpResource->name = fileName;
    410370
    411371  // creating the full name. (directoryName + FileName)
    412   char* fullName = ResourceManager::getFullName(fileName);
     372  std::string fullName = ResourceManager::getFullName(fileName);
    413373  // Checking for the type of resource \see ResourceType
    414374  switch(type)
     
    425385      else
    426386      {
    427         PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir);
     387        PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str());
    428388        tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());
    429389      }
     
    435395        tmpResource->param[0] = 1.0f;
    436396
    437       if (!strcmp(tmpResource->name, "cube"))
     397      if (tmpResource->name == "cube")
    438398        tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());
    439       else if (!strcmp(tmpResource->name, "sphere"))
     399      else if (tmpResource->name == "sphere")
    440400        tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());
    441       else if (!strcmp(tmpResource->name, "plane"))
     401      else if (tmpResource->name == "plane")
    442402        tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());
    443       else if (!strcmp(tmpResource->name, "cylinder"))
     403      else if (tmpResource->name == "cylinder")
    444404        tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());
    445       else if (!strcmp(tmpResource->name, "cone"))
     405      else if (tmpResource->name == "cone")
    446406        tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());
    447407      break;
     
    468428        tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
    469429      else
    470         PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir);
     430        PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str());
    471431      break;
    472432#endif /* NO_TEXT */
     
    494454      else
    495455      {
    496         std::vector<char*>::iterator imageDir;
     456        std::vector<std::string>::iterator imageDir;
    497457        for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    498458        {
    499           char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1];
    500           sprintf(imgName, "%s%s", *imageDir, fileName);
     459          std::string imgName = *imageDir + fileName;
    501460          if(isFile(imgName))
    502461          {
    503462            PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
    504463            tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());
    505             delete[] imgName;
    506464            break;
    507465          }
    508           delete[] imgName;
    509466        }
    510467      }
    511468      if(!tmpResource)
    512         PRINTF(2)("!!Image %s not Found!!\n", fileName);
     469        PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str());
    513470      break;
    514471#endif /* NO_TEXTURES */
     
    520477        {
    521478          MultiType param = param0; /// HACK
    522           char* secFullName = ResourceManager::getFullName(param.getCString());
     479          std::string secFullName = ResourceManager::getFullName(param.getCString());
    523480          if (ResourceManager::isFile(secFullName))
    524481          {
     
    526483            tmpResource->pointer = new Shader(fullName, secFullName);
    527484          }
    528           delete[] secFullName;
    529485        }
    530486        else
    531487        {
    532488          tmpResource->param[0] = param0;
    533           tmpResource->pointer = new Shader(fullName, NULL);
     489          tmpResource->pointer = new Shader(fullName, "");
    534490        }
    535491      }
     
    538494    default:
    539495      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);
     496      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());
    541497      break;
    542498  }
    543499  if (tmpResource->pointer != NULL)
    544500    this->resourceList.push_back(tmpResource);
    545   delete[] fullName;
    546 
    547501
    548502  if (tmpResource->pointer != NULL)
     
    550504  else
    551505  {
    552     PRINTF(2)("Resource %s could not be loaded\n", fileName);
    553     delete[] tmpResource->name;
     506    PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str());
    554507    delete tmpResource;
    555508    return NULL;
     
    597550      delete resource->pointer;
    598551      // deleting the List Entry:
    599       PRINTF(4)("Resource %s safely removed.\n", resource->name);
    600       delete[] resource->name;
     552      PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str());
    601553      std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
    602554      this->resourceList.erase(resourceIT);
     
    604556    }
    605557    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);
     558      PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count);
     559  }
     560  else
     561    PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str());
    610562  return true;
    611563}
     
    633585          if (round == 3)
    634586            PRINTF(2)("unable to unload %s because there are still %d references to it\n",
    635                       this->resourceList[index]->name, this->resourceList[index]->count);
     587                      this->resourceList[index]->name.c_str(), this->resourceList[index]->count);
    636588          removeCount++;
    637589        }
     
    653605 * @returns a Pointer to the Resource if found, NULL otherwise.
    654606*/
    655 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
     607Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type,
    656608    const MultiType& param0, const MultiType& param1, const MultiType& param2) const
    657609{
     
    659611  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    660612  {
    661     if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))
     613    if ((*resource)->type == type && fileName == (*resource)->name)
    662614    {
    663615      bool match = false;
     
    743695}
    744696
    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);
     697std::string ResourceManager::toResourcableString(unsigned int i)
     698{
     699/*  int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     700  len += this->resourceList[i]->name.size();
    749701  if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1;
    750702  if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1;
    751703  if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1;
    752704  len += 10;
    753   char* tmp = new char[len];
     705  std::string tmp = new char[len];
    754706  tmp[0] = '\0';
    755   strcat( tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     707  strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
    756708  strcat(tmp,",");
    757709  strcat (tmp, this->resourceList[i]->name);
     
    771723    strcat( tmp, this->resourceList[i]->param[2].getCString());
    772724  }
    773   return tmp;
     725  return tmp;*/
    774726}
    775727
     
    778730 * @param resourceableString the String to cache the resource from.
    779731 */
    780 bool ResourceManager::fromResourceableString(const char* resourceableString)
    781 {
    782   SubString splits(resourceableString, ',');
     732bool ResourceManager::fromResourceableString(const std::string& resourceableString)
     733{
     734/*  SubString splits(resourceableString, ',');
    783735  splits.debug();
    784736  if (splits.getCount() == 2)
     
    793745  else if (splits.getCount() == 5)
    794746    return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    795                 RP_LEVEL, splits[2], splits[3], splits[4]);
     747                RP_LEVEL, splits[2], splits[3], splits[4]);*/
    796748}
    797749
     
    802754 * @returns true if it is a directory/symlink false otherwise
    803755*/
    804 bool ResourceManager::isDir(const char* directoryName)
    805 {
    806   if (directoryName == NULL)
    807     return false;
    808 
    809   char* tmpDirName = NULL;
     756bool ResourceManager::isDir(const std::string& directoryName)
     757{
     758  std::string tmpDirName = directoryName;
    810759  struct stat status;
    811760
    812761  // 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))
     762  if (directoryName[directoryName.size()-1] == '/' ||
     763      directoryName[directoryName.size()-1] == '\\')
     764  {
     765    tmpDirName.erase(tmpDirName.size()-1);
     766  }
     767
     768  if(!stat(tmpDirName.c_str(), &status))
    827769  {
    828770    if (status.st_mode & (S_IFDIR
     
    832774                         ))
    833775    {
    834       delete[] tmpDirName;
    835776      return true;
    836777    }
    837778    else
    838     {
    839       delete[] tmpDirName;
    840779      return false;
    841     }
    842   }
    843   else
    844   {
    845     delete[] tmpDirName;
    846     return false;
    847   }
     780  }
     781  else
     782    return false;
    848783}
    849784
     
    853788 * @returns true if it is a regular file/symlink, false otherwise
    854789*/
    855 bool ResourceManager::isFile(const char* fileName)
    856 {
    857   if (fileName == NULL)
    858     return false;
    859   char* tmpFileName = ResourceManager::homeDirCheck(fileName);
     790bool ResourceManager::isFile(const std::string& fileName)
     791{
     792  if (fileName.empty())
     793    return false;
     794  std::string tmpFileName = ResourceManager::homeDirCheck(fileName);
    860795  // actually checks the File
    861796  struct stat status;
    862   if (!stat(tmpFileName, &status))
     797  if (!stat(tmpFileName.c_str(), &status))
    863798  {
    864799    if (status.st_mode & (S_IFREG
     
    868803                         ))
    869804    {
    870       delete[] tmpFileName;
    871805      return true;
    872806    }
    873807    else
    874     {
    875       delete[] tmpFileName;
    876808      return false;
    877     }
    878   }
    879   else
    880   {
    881     delete[] tmpFileName;
    882     return false;
    883   }
     809  }
     810  else
     811    return false;
    884812}
    885813
     
    888816 * @param fileName The file to touch
    889817*/
    890 bool ResourceManager::touchFile(const char* fileName)
    891 {
    892   char* tmpName = ResourceManager::homeDirCheck(fileName);
    893   if (tmpName == NULL)
     818bool ResourceManager::touchFile(const std::string& fileName)
     819{
     820  std::string tmpName = ResourceManager::homeDirCheck(fileName);
     821  if (tmpName.empty())
    894822    return false;
    895823  FILE* stream;
    896   if( (stream = fopen (tmpName, "w")) == NULL)
    897   {
    898     PRINTF(1)("could not open %s fro writing\n", fileName);
    899     delete[] tmpName;
     824  if( (stream = fopen (tmpName.c_str(), "w")) == NULL)
     825  {
     826    PRINTF(1)("could not open %s fro writing\n", fileName.c_str());
    900827    return false;
    901828  }
    902829  fclose(stream);
    903 
    904   delete[] tmpName;
    905830}
    906831
     
    909834 * @param fileName the File to delete
    910835*/
    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;
     836bool ResourceManager::deleteFile(const std::string& fileName)
     837{
     838  std::string tmpName = ResourceManager::homeDirCheck(fileName);
     839  unlink(tmpName.c_str());
    918840}
    919841
     
    921843 * @param name the Name of the file to check
    922844 * @returns The name of the file, including the HomeDir
    923  * IMPORTANT: this has to be deleted from the outside
    924  */
    925 char* ResourceManager::homeDirCheck(const char* name)
    926 {
    927   if (name == NULL)
    928     return NULL;
    929   char* retName;
    930   if (!strncmp(name, "~/", 2))
    931   {
    932     char tmpFileName[500];
     845 */
     846std::string ResourceManager::homeDirCheck(const std::string& name)
     847{
     848  if (name.size() >= 2 && name[0] == '~' && name[1] == '/')
     849  {
     850    std::string homeDir;
     851    std::string newName = name.substr(1);
    933852#ifdef __WIN32__
    934     strcpy(tmpFileName, getenv("USERPROFILE"));
     853    homeDir = getenv("USERPROFILE");
    935854#else
    936     strcpy(tmpFileName, getenv("HOME"));
    937 #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);
    945   }
    946   return retName;
     855    homeDir = getenv("HOME");
     856#endif
     857    return homeDir + newName;
     858  }
     859  else
     860    return name;
    947861}
    948862
    949863/**
    950864 * @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);
     865 * @returns a new std::string with the name in abs-dir-format
     866 */
     867std::string ResourceManager::getAbsDir(const std::string& name)
     868{
     869  if (name.empty())
     870    return "";
     871  std::string retName = name;
     872  if (strncmp(name.c_str(), "/", 1))
     873  {
     874    if (name[0] == '.' && name[1] != '.')
     875      retName.erase(0);
     876    const std::string& absDir = ResourceManager::cwd();
     877    retName = absDir + retName;
    970878  }
    971879  return retName;
     
    978886 * !!IMPORTANT: this has to be deleted from the outside!!
    979887*/
    980 char* ResourceManager::getFullName(const char* fileName)
    981 {
    982   if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
    983     return NULL;
    984 
    985   char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
    986                            + strlen(fileName) + 1];
    987   sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     888std::string ResourceManager::getFullName(const std::string& fileName)
     889{
     890  if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
     891    return "";
     892
     893  std::string retName = ResourceManager::getInstance()->getDataDir() +fileName;
    988894  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
    989895    return retName;
    990896  else
    991   {
    992     delete[] retName;
    993     return NULL;
    994   }
     897    return "";
    995898}
    996899
     
    1005908 * @returns the Current Woring Directory
    1006909 */
    1007 const char* ResourceManager::cwd()
    1008 {
    1009   if (ResourceManager::getInstance()->_cwd == NULL)
     910const std::string& ResourceManager::cwd()
     911{
     912  if (ResourceManager::getInstance()->_cwd.empty())
    1010913  {
    1011914    char cwd[1024];
    1012915    char* errorCode = getcwd(cwd, 1024);
    1013916    if (errorCode == 0)
    1014       return NULL;
    1015 
    1016     ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1];
    1017     strcpy(ResourceManager::getInstance()->_cwd, cwd);
     917      return ResourceManager::getInstance()->_cwd;
     918
     919    ResourceManager::getInstance()->_cwd = cwd;
    1018920  }
    1019921  return ResourceManager::getInstance()->_cwd;
     
    1026928 * @returns true if the file exists, false otherwise
    1027929 */
    1028 bool ResourceManager::isInDataDir(const char* fileName)
    1029 {
    1030   if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
     930bool ResourceManager::isInDataDir(const std::string& fileName)
     931{
     932  if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
    1031933    return false;
    1032934
    1033935  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);
     936  std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName;
    1037937
    1038938  if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile))
     
    1040940  else
    1041941    retVal = false;
    1042   delete[] checkFile;
    1043942  return retVal;
    1044943}
     
    1055954  // if it is not initialized
    1056955  PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
    1057   PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
     956  PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str());
    1058957  PRINT(0)(" List of Image-Directories: ");
    1059   std::vector<char*>::const_iterator imageDir;
     958  std::vector<std::string>::const_iterator imageDir;
    1060959  for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    1061     PRINT(0)("%s ", (*imageDir));
     960    PRINT(0)("%s ", (*imageDir).c_str());
    1062961  PRINT(0)("\n");
    1063962
     
    1068967  {
    1069968    PRINT(0)("-----------------------------------------\n");
    1070     PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
     969    PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
    1071970
    1072971    PRINT(0)("gets deleted at ");
  • trunk/src/lib/util/loading/resource_manager.h

    r7196 r7221  
    7171  unsigned int      count;             //!< How many times this Resource has been loaded.
    7272
    73   char*             name;              //!< Name of the Resource.
     73  std::string       name;              //!< Name of the Resource.
    7474  ResourceType      type;              //!< ResourceType of this Resource.
    7575  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
     
    9696  inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
    9797
    98   bool setDataDir(const char* dataDir);
     98  bool setDataDir(const std::string& dataDir);
    9999  /** @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; };
    101101
    102102
    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);
    106106
    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,
    108108             const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    109109  BaseObject* copy(BaseObject* resourcePointer);
    110110
    111   BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
     111  BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO,
    112112                   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,
    114114                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
    115115  bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO);
     
    117117  bool unloadAllByPriority(ResourcePriority prio);
    118118
    119   Resource* locateResourceByInfo(const char* fileName, ResourceType type,
     119  Resource* locateResourceByInfo(const std::string& fileName, ResourceType type,
    120120                                 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const;
    121121  Resource* locateResourceByPointer(const void* pointer) const;
    122122
    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);
    125125  /** @returns the Count of Resources the ResourceManager handles */
    126126  unsigned int resourceCount() const { return this->resourceList.size(); }
     
    130130
    131131  // 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();
    141141
    142142  static const char* ResourceTypeToChar(ResourceType type);
     
    145145 private:
    146146  ResourceManager();
    147   Resource* loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
     147  Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
    148148                         const MultiType& param0, const MultiType& param1, const MultiType& param2);
    149149
    150150 private:
    151   static ResourceManager*  singletonRef;       //!< singleton Reference
     151  static ResourceManager*    singletonRef;       //!< singleton Reference
    152152
    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.
    156156
    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.
    158158
    159   static const char*       resourceNames[RESOURCE_TYPE_SIZE];
     159  static const char*         resourceNames[RESOURCE_TYPE_SIZE];
    160160};
    161161
  • trunk/src/lib/util/multi_type.cc

    r7201 r7221  
    3939  switch (this->type)
    4040  {
     41    default:
     42      this->value.Float = 0.0f;
     43      break;
    4144    case MT_BOOL:
    4245      this->value.Bool = false;
     
    9093{
    9194  this->setChar(value);
    92 }
    93 
    94 /**
    95  * @brief creates a multiType out of a C-String
    96  * @param value the Value of this MulitType
    97  */
    98 MultiType::MultiType(const char* value)
    99 {
    100   this->setString(value);
    10195}
    10296
     
    482476 * @returns: the Type as MT_Type
    483477 */
    484 MT_Type MultiType::StringToMultiType(const char* type)
    485 {
    486   if (!strncmp(type, "bool", 4))
     478MT_Type MultiType::StringToMultiType(const std::string& type)
     479{
     480  if (type == "bool")
    487481    return MT_BOOL;
    488   if (!strncmp(type, "int", 3))
     482  if (type == "int")
    489483    return MT_INT;
    490   if (!strncmp(type, "float", 5))
     484  if (type, "float")
    491485    return MT_FLOAT;
    492   if (!strncmp(type, "char", 4))
     486  if (type == "char")
    493487    return MT_CHAR;
    494   if (!strncmp(type, "string", 6))
     488  if (type == "string")
    495489    return MT_STRING;
    496490
  • trunk/src/lib/util/multi_type.h

    r7200 r7221  
    3939    MultiType(double value);
    4040    MultiType(char value);
    41     MultiType(const char* value);
    4241    MultiType(const std::string& value);
    4342    MultiType(const MultiType& multiType);
     
    9594
    9695    static const char* MultiTypeToString(MT_Type type);
    97     static MT_Type StringToMultiType(const char* type);
     96    static MT_Type StringToMultiType(const std::string& type);
    9897
    9998  private:
     
    106105//      std::string*      String;
    107106    }                   value;
    108 
     107    std::string         storedString;
    109108    MT_Type             type;
    110 
    111     std::string         storedString;
    112109};
    113110
  • trunk/src/lib/util/substring.cc

    r5656 r7221  
    1414
    1515   2005-06-10: some naming conventions
     16
     17//
     18//  splitLine
     19//  STL string tokenizer
     20//
     21//  Created by Clemens Wacha.
     22//  Version 1.0
     23//  Copyright (c) 2005 Clemens Wacha. All rights reserved.
     24//
     25
    1626*/
    1727
     
    2434#include "substring.h"
    2535
    26 #include "debug.h"
    2736#include <string.h>
    28 #include <assert.h>
    29 
    30 SubString::SubString( const char* string, char splitter)
    31 {
    32   this->splittersCount = 0;
    33   if (string == NULL)
    34   {
    35     this->strings = NULL;
    36     this->offsets = NULL;
    37     return;
    38   }
    39 
    40   for( int i = 0; i < strlen(string); i++)
    41     if( string[i] == splitter)
    42       this->splittersCount++;
    43 
    44   this->splittersCount += 1;
    45 
    46   this->strings = new char*[this->splittersCount];
    47   this->offsets = new unsigned int[this->splittersCount];
    48   assert (this->strings != NULL && this->offsets != NULL);
    49 
    50   int i = 0;
    51   int l = 0;
    52 
    53   if( this->splittersCount > 1)
    54   {
    55     const char* offset = string;
    56     const char* end = strchr( string, splitter);
    57     while( end != NULL)
    58     {
    59       assert( i < this->splittersCount);
    60       l = end - offset;
    61       this->strings[i] = new char[l + 1];
    62       assert( strings[i] != NULL);
    63       strncpy( strings[i], offset, l);
    64       strings[i][l] = '\0';
    65       this->offsets[i] = offset - string;
    66       i++;
    67       end++;
    68       offset = end;
    69       end = strchr( offset, splitter);
    70     }
    71 
    72     l = strlen( offset);
    73     strings[i] = new char[l + 1];
    74     strncpy( strings[i], offset, l);
    75     strings[i][l] = '\0';
    76     this->offsets[i] = offset - string;
    77   }
    78   else
    79   {
    80     this->strings[0] = new char[strlen(string)+1];
    81     strcpy(this->strings[0], string);
    82     this->offsets[0] = 0;
    83   }
    84 }
    85 
     37#include <cassert>
     38
     39SubString::SubString(const std::string& string, char splitter)
     40{
     41  char split[2];
     42  split[0] = splitter;
     43  split[1] = '\0';
     44  SubString::splitLine(this->strings, this->offsets,
     45                       string, split);
     46}
    8647
    8748/**
     
    9152 *
    9253 */
    93 SubString::SubString(const char* string, bool whiteSpaces)
    94 {
    95   this->splittersCount = 0;
    96   if (string == NULL || whiteSpaces == false)
     54SubString::SubString(const std::string& string, bool whiteSpaces)
     55{
     56  SubString::splitLine(this->strings, this->offsets,
     57                      string);
     58}
     59SubString::SubString(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char)
     60{
     61  SubString::splitLine(this->strings, this->offsets,
     62                       string, splitters, escapeChar, safemode_char);
     63}
     64
     65/**
     66 * An empty String
     67 */
     68const std::string SubString::emptyString = "";
     69
     70
     71
     72unsigned int SubString::split(const std::string& string, char splitter)
     73{
     74  this->offsets.clear();
     75  this->strings.clear();
     76  char split[2];
     77  split[0] = splitter;
     78  split[1] = '\0';
     79  SubString::splitLine(this->strings, this->offsets, string, split);
     80  return strings.size();
     81}
     82
     83
     84/**
     85 * Splits a String into a Substring removing all whiteSpaces
     86 * @param string the String to Split
     87 * @param whiteSpaces MUST BE __TRUE__
     88 *
     89 */
     90unsigned int SubString::split(const std::string& string, bool whiteSpaces)
     91{
     92  this->offsets.clear();
     93  this->strings.clear();
     94  SubString::splitLine(this->strings, this->offsets, string);
     95  return strings.size();
     96}
     97
     98unsigned int SubString::split(const std::string& string, const std::string& splitters, char escapeChar,char safemode_char, char comment_char)
     99{
     100  this->offsets.clear();
     101  this->strings.clear();
     102  SubString::splitLine(this->strings, this->offsets,
     103                       string, splitters, escapeChar, safemode_char);
     104  return strings.size();
     105}
     106
     107
     108/**
     109 * @brief splits line into tokens and stores them in ret.
     110 * @param ret the Array, where the Splitted strings will be stored in
     111 * @param offsets an Array of Offsets, here the distance from the inputstring
     112 * to the beginning of the current token is stored
     113 * @param line the inputLine to split
     114 * @param delimiters a String of Delimiters (here the input will be splitted)
     115 * @param escape_char: Escape carater (escapes splitters)
     116 * @param safemode_char: the beginning of the safemode is marked with this
     117 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
     118 * @param start_state: the Initial state on how to parse the String.
     119 * @returns SPLIT_LINE_STATE the parser was in when returning
     120 *
     121 * Supports delimiters, escape characters,
     122 * ignores special  characters between safemode_char and between comment_char and linend '\n'.
     123 *
     124 */
     125SPLIT_LINE_STATE SubString::splitLine(std::vector<std::string>& ret, std::vector<unsigned int>& offsets,
     126                                      const std::string& line, const std::string& delimiters,
     127                                      char escape_char, char safemode_char, char comment_char,
     128                                      SPLIT_LINE_STATE start_state)
     129{
     130  SPLIT_LINE_STATE state = start_state;
     131  unsigned int i = 0;
     132  std::string token;
     133
     134  if(start_state != SL_NORMAL && ret.size() > 0)
    97135  {
    98     this->strings = NULL;
    99     this->offsets = NULL;
    100     return;
     136    token = ret[ret.size()-1];
     137    ret.pop_back();
    101138  }
    102139
    103   // chop the input to the beginning of something usefull
    104   if (strlen(string) > 0)
    105     string = string + strspn(string, " \t\n");
    106 
    107   // count the Splitters
    108   bool lastWasWhiteSpace = false;
    109   for(unsigned int i = 0; i < strlen(string); i++)
    110     if( string[i] == ' ' || string[i] == '\t' || string[i] == '\n' )
    111       lastWasWhiteSpace = true;
    112     else
     140  while(i < line.size())
     141  {
     142    switch(state)
    113143    {
    114       if (lastWasWhiteSpace)
    115         this->splittersCount ++;
    116       lastWasWhiteSpace = false;
     144    case SL_NORMAL:
     145      if(line[i] == escape_char)
     146      {
     147        state = SL_ESCAPE;
     148      }
     149      else if(line[i] == safemode_char)
     150      {
     151        state = SL_SAFEMODE;
     152      }
     153      else if(line[i] == comment_char)
     154      {
     155        /// FINISH
     156        if(token.size() > 0)
     157        {
     158          ret.push_back(token);
     159          offsets.push_back(i);
     160          token.clear();
     161        }
     162        token += line[i];       // EAT
     163        state = SL_COMMENT;
     164      }
     165      else if(delimiters.find(line[i]) != std::string::npos)
     166      {
     167        // line[i] is a delimiter
     168        /// FINISH
     169        if(token.size() > 0)
     170        {
     171          ret.push_back(token);
     172          offsets.push_back(i);
     173          token.clear();
     174        }
     175      }
     176      else
     177      {
     178        token += line[i];       // EAT
     179      }
     180      break;
     181    case SL_ESCAPE:
     182      if(line[i] == 'n') token += '\n';
     183      else if(line[i] == 't') token += '\t';
     184      else if(line[i] == 'v') token += '\v';
     185      else if(line[i] == 'b') token += '\b';
     186      else if(line[i] == 'r') token += '\r';
     187      else if(line[i] == 'f') token += '\f';
     188      else if(line[i] == 'a') token += '\a';
     189      else if(line[i] == '?') token += '\?';
     190      else token += line[i];  // EAT
     191      state = SL_NORMAL;
     192      break;
     193    case SL_SAFEMODE:
     194      if(line[i] == safemode_char)
     195      {
     196        state = SL_NORMAL;
     197      }
     198      else if(line[i] == escape_char)
     199      {
     200        state = SL_SAFEESCAPE;
     201      }
     202      else
     203      {
     204        token += line[i];       // EAT
     205      }
     206      break;
     207    case SL_SAFEESCAPE:
     208      if(line[i] == 'n') token += '\n';
     209      else if(line[i] == 't') token += '\t';
     210      else if(line[i] == 'v') token += '\v';
     211      else if(line[i] == 'b') token += '\b';
     212      else if(line[i] == 'r') token += '\r';
     213      else if(line[i] == 'f') token += '\f';
     214      else if(line[i] == 'a') token += '\a';
     215      else if(line[i] == '?') token += '\?';
     216      else token += line[i];  // EAT
     217      state = SL_SAFEMODE;
     218      break;
     219    case SL_COMMENT:
     220      if(line[i] == '\n')
     221      {
     222        /// FINISH
     223        if(token.size() > 0)
     224        {
     225          ret.push_back(token);
     226          offsets.push_back(i);
     227          token.clear();
     228        }
     229        state = SL_NORMAL;
     230      }
     231      else
     232      {
     233        token += line[i];       // EAT
     234      }
     235      break;
     236    default:
     237      // nothing
     238      break;
    117239    }
    118   this->splittersCount += 1;
    119 
    120   // allocate memory
    121   this->strings = new char*[this->splittersCount];
    122   this->offsets = new unsigned int[this->splittersCount];
    123   assert (this->strings != NULL && this->offsets != NULL);
    124 
    125 
    126   // split the String into substrings
    127   int l = 0;
    128   unsigned int i = 0;
    129   if( this->splittersCount > 1)
     240    i++;
     241  }
     242
     243  /// FINISH
     244  if(token.size() > 0)
    130245  {
    131     const char* offset = string;
    132     const char* end = offset + strcspn(offset, " \t\n");
    133     for (i = 0; i < this->splittersCount; i++)
    134     {
    135       assert( i < this->splittersCount);
    136       l = end - offset;
    137       this->strings[i] = new char[l + 1];
    138       assert( strings[i] != NULL);
    139       strncpy( strings[i], offset, l);
    140       strings[i][l] = '\0';
    141       this->offsets[i] = offset - string;
    142       end += strspn(end, " \t\n");
    143       offset = end;
    144       end = offset + strcspn(offset, " \t\n");
    145     }
     246    ret.push_back(token);
     247    offsets.push_back(i);
     248    token.clear();
    146249  }
    147   else
    148   {
    149     unsigned int length = strcspn(string, " \t\n");
    150     this->strings[0] = new char[length+1];
    151     strncpy(this->strings[0], string, length);
    152     this->strings[0][length] = '\0';
    153     offsets[0] = 0;
    154   }
    155 }
    156 
    157 SubString::SubString(const char* string, const char* splitters, char escapeChar)
    158 {
    159   this->splittersCount = 0;
    160   if (string == NULL || splitters == NULL)
    161   {
    162     this->strings = NULL;
    163     this->offsets = NULL;
    164     return;
    165   }
    166 
    167   // chop the input to the beginning of something usefull
    168   if (strlen(string) > 0)
    169     string = string + strspn(string, splitters);
    170 
    171   // count the Splitters
    172   bool lastWasSplitter = false;
    173   for(unsigned int i = 0; i < strlen(string); i++)
    174   {
    175 
    176     if( strchr(splitters, string[i] ))
    177       lastWasSplitter = true;
    178     else
    179     {
    180       if (lastWasSplitter)
    181       {
    182         this->splittersCount ++;
    183         lastWasSplitter = false;
    184       }
    185     }
    186   }
    187   this->splittersCount += 1;
    188 
    189   // allocate memory
    190   this->strings = new char*[this->splittersCount];
    191   this->offsets = new unsigned int[this->splittersCount];
    192   assert (this->strings != NULL && this->offsets != NULL);
    193 
    194 
    195   // split the String into substrings
    196   int l = 0;
    197   unsigned int i = 0;
    198   if( this->splittersCount > 1)
    199   {
    200     const char* offset = string;
    201     const char* end = offset + strcspn(offset, splitters);
    202     for (i = 0; i < this->splittersCount; i++)
    203     {
    204       assert( i < this->splittersCount);
    205       l = end - offset;
    206       this->strings[i] = new char[l + 1];
    207       assert( strings[i] != NULL);
    208       strncpy( strings[i], offset, l);
    209       strings[i][l] = '\0';
    210       this->offsets[i] = offset - string;
    211       end += strspn(end, splitters);
    212       offset = end;
    213       end = offset + strcspn(offset, splitters);
    214     }
    215   }
    216   else
    217   {
    218     unsigned int length = strcspn(string, splitters);
    219     this->strings[0] = new char[length+1];
    220     strncpy(this->strings[0], string, length);
    221     this->strings[0][length] = '\0';
    222     offsets[0] = 0;
    223   }
    224 }
    225 
     250  return(state);
     251}
    226252
    227253/**
     
    229255*/
    230256SubString::~SubString()
    231 {
    232   if (this->strings)
    233   {
    234     for(unsigned int i = 0; i < this->splittersCount; i++)
    235       delete[] this->strings[i];
    236     delete[] this->strings;
    237   }
    238   delete[] this->offsets;
    239 }
    240 
    241 /**
    242  *  get a particular substring
    243  * @param i the ID of the substring to return
    244  * @returns the designated substring or NULL if an invalid ID was given
    245 */
    246 const char* SubString::getString(unsigned int i)
    247 {
    248   if( i < this->splittersCount && i >= 0)
    249     return this->strings[i];
    250   else
    251     return NULL;
    252 }
     257{ }
    253258
    254259/**
     
    259264unsigned int SubString::getOffset(unsigned int i)
    260265{
    261   if( i < this->splittersCount && i >= 0)
     266  if( i < this->offsets.size() && i >= 0)
    262267    return this->offsets[i];
    263268  else
     
    270275void SubString::debug() const
    271276{
    272   PRINT(0)("Substring-information::count=%d ::", this->splittersCount);
    273   if (this->strings != NULL)
    274     for (unsigned int i = 0; i < this->splittersCount; i++)
    275      PRINT(0)("s%d='%s'::", i, this->strings[i]);
    276   PRINT(0)("\n");
    277 }
     277  printf("Substring-information::count=%d ::", this->strings.size());
     278  for (unsigned int i = 0; i < this->strings.size(); i++)
     279    printf("s%d='%s'::", i, this->strings[i].c_str());
     280  printf("\n");
     281}
  • trunk/src/lib/util/substring.h

    r6648 r7221  
    77#define _SUBSTRING_H
    88
     9#include <vector>
     10#include <string>
     11
     12  typedef enum {
     13    SL_NORMAL,
     14    SL_ESCAPE,
     15    SL_SAFEMODE,
     16    SL_SAFEESCAPE,
     17    SL_COMMENT,
     18  } SPLIT_LINE_STATE;
     19
    920//! A class that can load one string and split it in multipe ones
    1021class SubString
    1122{
    1223 public:
    13   SubString(const char* string, char splitter = ',');
    14   SubString(const char* string, bool whiteSpaces);
    15   SubString(const char* string, const char* splitters, char escapeChar ='\\');
     24  SubString(const std::string& string = "", char splitter = ',');
     25  SubString(const std::string& string, bool whiteSpaces);
     26  SubString(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
    1627  ~SubString();
    1728
    18   const char* operator[](unsigned int i) { return this->getString(i); };
     29  unsigned int split(const std::string& string = "", char splitter = ',');
     30  unsigned int split(const std::string& string, bool whiteSpaces);
     31  unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
    1932
    20   inline unsigned int getCount() { return this->splittersCount; };
    21   const char* getString(unsigned int i);
     33
     34  const std::string& operator[](unsigned int i) { return this->getString(i); };
     35
     36  inline unsigned int getCount() { return this->strings.size(); };
     37  const std::string& getString(unsigned int i) { return (i < this->strings.size()) ? this->strings[i] : emptyString; };
    2238  unsigned int getOffset(unsigned int i);
     39
     40  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets,
     41                                    const std::string& line, const std::string& delimiters = " \t\r\n",
     42                                    char escape_char = '\\', char safemode_char = '"', char comment_char = '\0',
     43                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
    2344
    2445  void debug() const;
    2546
    2647 private:
    27   char**          strings;                      //!< strings produced from a single string splitted in multiple strings
    28   unsigned int*   offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
    29   unsigned int    splittersCount;               //!< how many splitted parts
     48   std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     49   std::vector<unsigned int> offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
     50
     51   static const std::string emptyString;
    3052};
    3153
Note: See TracChangeset for help on using the changeset viewer.