Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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/util
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified 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  }
  • TabularUnified 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
  • TabularUnified 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)
  • TabularUnified 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
  • TabularUnified 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
  • TabularUnified 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 */
  • TabularUnified 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  }
  • TabularUnified 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.
  • TabularUnified 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
  • TabularUnified 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
  • TabularUnified 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);
  • TabularUnified 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 */
  • TabularUnified 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();
  • TabularUnified 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.
  • TabularUnified 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 ");
  • TabularUnified 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
  • TabularUnified 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
  • TabularUnified 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
  • TabularUnified 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}
  • TabularUnified 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.