Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2006, 5:28:10 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: compiles again, BUT well…. i do not expect it to run anymore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/lib/util/loading/resource_manager.cc

    r7199 r7203  
    6060
    6161  this->dataDir = new char[3];
    62   strcpy(this->dataDir, "./");
     62  this->dataDir = "./";
    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);
    365 
    366326  // searching if the resource was loaded before.
    367327  Resource* tmpResource;
     
    397357 * @returns a pointer to a desired Resource.
    398358 */
    399 Resource* ResourceManager::loadResource(const char* fileName, ResourceType type, ResourcePriority prio,
     359Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
    400360                                        const MultiType& param0, const MultiType& param1, const MultiType& param2)
    401361{
     
    406366  tmpResource->prio = prio;
    407367  tmpResource->pointer = NULL;
    408   tmpResource->name = new char[strlen(fileName)+1];
    409   strcpy(tmpResource->name, fileName);
     368  tmpResource->name = fileName;
    410369
    411370  // creating the full name. (directoryName + FileName)
    412   char* fullName = ResourceManager::getFullName(fileName);
     371  std::string fullName = ResourceManager::getFullName(fileName);
    413372  // Checking for the type of resource \see ResourceType
    414373  switch(type)
     
    425384      else
    426385      {
    427         PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName, dataDir);
     386        PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str());
    428387        tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());
    429388      }
     
    435394        tmpResource->param[0] = 1.0f;
    436395
    437       if (!strcmp(tmpResource->name, "cube"))
     396      if (tmpResource->name == "cube")
    438397        tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());
    439       else if (!strcmp(tmpResource->name, "sphere"))
     398      else if (tmpResource->name == "sphere")
    440399        tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());
    441       else if (!strcmp(tmpResource->name, "plane"))
     400      else if (tmpResource->name == "plane")
    442401        tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());
    443       else if (!strcmp(tmpResource->name, "cylinder"))
     402      else if (tmpResource->name == "cylinder")
    444403        tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());
    445       else if (!strcmp(tmpResource->name, "cone"))
     404      else if (tmpResource->name == "cone")
    446405        tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());
    447406      break;
     
    468427        tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());
    469428      else
    470         PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName, this->dataDir);
     429        PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str());
    471430      break;
    472431#endif /* NO_TEXT */
     
    494453      else
    495454      {
    496         std::vector<char*>::iterator imageDir;
     455        std::vector<std::string>::iterator imageDir;
    497456        for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    498457        {
    499           char* imgName = new char[strlen(*imageDir)+strlen(fileName)+1];
    500           sprintf(imgName, "%s%s", *imageDir, fileName);
     458          std::string imgName = *imageDir + fileName;
    501459          if(isFile(imgName))
    502460          {
    503461            PRINTF(4)("Image %s resides to %s\n", fileName, imgName);
    504462            tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());
    505             delete[] imgName;
    506463            break;
    507464          }
    508           delete[] imgName;
    509465        }
    510466      }
    511467      if(!tmpResource)
    512         PRINTF(2)("!!Image %s not Found!!\n", fileName);
     468        PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str());
    513469      break;
    514470#endif /* NO_TEXTURES */
     
    520476        {
    521477          MultiType param = param0; /// HACK
    522           char* secFullName = ResourceManager::getFullName(param.getCString());
     478          std::string secFullName = ResourceManager::getFullName(param.getCString());
    523479          if (ResourceManager::isFile(secFullName))
    524480          {
     
    526482            tmpResource->pointer = new Shader(fullName, secFullName);
    527483          }
    528           delete[] secFullName;
    529484        }
    530485        else
     
    538493    default:
    539494      tmpResource->pointer = NULL;
    540       PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name);
     495      PRINTF(1)("No type found for %s.\n   !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str());
    541496      break;
    542497  }
    543498  if (tmpResource->pointer != NULL)
    544499    this->resourceList.push_back(tmpResource);
    545   delete[] fullName;
    546 
    547500
    548501  if (tmpResource->pointer != NULL)
     
    550503  else
    551504  {
    552     PRINTF(2)("Resource %s could not be loaded\n", fileName);
    553     delete[] tmpResource->name;
     505    PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str());
    554506    delete tmpResource;
    555507    return NULL;
     
    597549      delete resource->pointer;
    598550      // deleting the List Entry:
    599       PRINTF(4)("Resource %s safely removed.\n", resource->name);
    600       delete[] resource->name;
     551      PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str());
    601552      std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);
    602553      this->resourceList.erase(resourceIT);
     
    604555    }
    605556    else
    606       PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name, resource->count);
    607   }
    608   else
    609     PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name);
     557      PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count);
     558  }
     559  else
     560    PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str());
    610561  return true;
    611562}
     
    633584          if (round == 3)
    634585            PRINTF(2)("unable to unload %s because there are still %d references to it\n",
    635                       this->resourceList[index]->name, this->resourceList[index]->count);
     586                      this->resourceList[index]->name.c_str(), this->resourceList[index]->count);
    636587          removeCount++;
    637588        }
     
    653604 * @returns a Pointer to the Resource if found, NULL otherwise.
    654605*/
    655 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
     606Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type,
    656607    const MultiType& param0, const MultiType& param1, const MultiType& param2) const
    657608{
     
    659610  for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)
    660611  {
    661     if ((*resource)->type == type && !strcmp(fileName, (*resource)->name))
     612    if ((*resource)->type == type && fileName == (*resource)->name)
    662613    {
    663614      bool match = false;
     
    743694}
    744695
    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);
     696std::string ResourceManager::toResourcableString(unsigned int i)
     697{
     698/*  int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     699  len += this->resourceList[i]->name.size();
    749700  if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1;
    750701  if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1;
    751702  if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1;
    752703  len += 10;
    753   char* tmp = new char[len];
     704  std::string tmp = new char[len];
    754705  tmp[0] = '\0';
    755   strcat( tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
     706  strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));
    756707  strcat(tmp,",");
    757708  strcat (tmp, this->resourceList[i]->name);
     
    771722    strcat( tmp, this->resourceList[i]->param[2].getCString());
    772723  }
    773   return tmp;
     724  return tmp;*/
    774725}
    775726
     
    778729 * @param resourceableString the String to cache the resource from.
    779730 */
    780 bool ResourceManager::fromResourceableString(const char* resourceableString)
    781 {
    782   SubString splits(resourceableString, ',');
     731bool ResourceManager::fromResourceableString(const std::string& resourceableString)
     732{
     733/*  SubString splits(resourceableString, ',');
    783734  splits.debug();
    784735  if (splits.getCount() == 2)
     
    793744  else if (splits.getCount() == 5)
    794745    return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),
    795                 RP_LEVEL, splits[2], splits[3], splits[4]);
     746                RP_LEVEL, splits[2], splits[3], splits[4]);*/
    796747}
    797748
     
    802753 * @returns true if it is a directory/symlink false otherwise
    803754*/
    804 bool ResourceManager::isDir(const char* directoryName)
    805 {
    806   if (directoryName == NULL)
    807     return false;
    808 
    809   char* tmpDirName = NULL;
     755bool ResourceManager::isDir(const std::string& directoryName)
     756{
     757  std::string tmpDirName = directoryName;
    810758  struct stat status;
    811759
    812760  // checking for the termination of the string given. If there is a "/" at the end cut it away
    813   if (directoryName[strlen(directoryName)-1] == '/' ||
    814       directoryName[strlen(directoryName)-1] == '\\')
    815   {
    816     tmpDirName = new char[strlen(directoryName)];
    817     strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
    818     tmpDirName[strlen(directoryName)-1] = '\0';
    819   }
    820   else
    821   {
    822     tmpDirName = new char[strlen(directoryName)+1];
    823     strcpy(tmpDirName, directoryName);
    824   }
    825 
    826   if(!stat(tmpDirName, &status))
     761  if (directoryName[directoryName.size()-1] == '/' ||
     762      directoryName[directoryName.size()-1] == '\\')
     763  {
     764    tmpDirName.erase(tmpDirName.size()-1);
     765  }
     766
     767  if(!stat(tmpDirName.c_str(), &status))
    827768  {
    828769    if (status.st_mode & (S_IFDIR
     
    832773                         ))
    833774    {
    834       delete[] tmpDirName;
    835775      return true;
    836776    }
    837777    else
    838     {
    839       delete[] tmpDirName;
    840778      return false;
    841     }
    842   }
    843   else
    844   {
    845     delete[] tmpDirName;
    846     return false;
    847   }
     779  }
     780  else
     781    return false;
    848782}
    849783
     
    853787 * @returns true if it is a regular file/symlink, false otherwise
    854788*/
    855 bool ResourceManager::isFile(const char* fileName)
    856 {
    857   if (fileName == NULL)
    858     return false;
    859   char* tmpFileName = ResourceManager::homeDirCheck(fileName);
     789bool ResourceManager::isFile(const std::string& fileName)
     790{
     791  std::string tmpFileName = ResourceManager::homeDirCheck(fileName);
    860792  // actually checks the File
    861793  struct stat status;
    862   if (!stat(tmpFileName, &status))
     794  if (!stat(tmpFileName.c_str(), &status))
    863795  {
    864796    if (status.st_mode & (S_IFREG
     
    868800                         ))
    869801    {
    870       delete[] tmpFileName;
    871802      return true;
    872803    }
    873804    else
    874     {
    875       delete[] tmpFileName;
    876805      return false;
    877     }
    878   }
    879   else
    880   {
    881     delete[] tmpFileName;
    882     return false;
    883   }
     806  }
     807  else
     808    return false;
    884809}
    885810
     
    888813 * @param fileName The file to touch
    889814*/
    890 bool ResourceManager::touchFile(const char* fileName)
    891 {
    892   char* tmpName = ResourceManager::homeDirCheck(fileName);
    893   if (tmpName == NULL)
     815bool ResourceManager::touchFile(const std::string& fileName)
     816{
     817  std::string tmpName = ResourceManager::homeDirCheck(fileName);
     818  if (tmpName.empty())
    894819    return false;
    895820  FILE* stream;
    896   if( (stream = fopen (tmpName, "w")) == NULL)
    897   {
    898     PRINTF(1)("could not open %s fro writing\n", fileName);
    899     delete[] tmpName;
     821  if( (stream = fopen (tmpName.c_str(), "w")) == NULL)
     822  {
     823    PRINTF(1)("could not open %s fro writing\n", fileName.c_str());
    900824    return false;
    901825  }
    902826  fclose(stream);
    903 
    904   delete[] tmpName;
    905827}
    906828
     
    909831 * @param fileName the File to delete
    910832*/
    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;
     833bool ResourceManager::deleteFile(const std::string& fileName)
     834{
     835  std::string tmpName = ResourceManager::homeDirCheck(fileName);
     836  unlink(tmpName.c_str());
    918837}
    919838
     
    923842 * IMPORTANT: this has to be deleted from the outside
    924843 */
    925 char* ResourceManager::homeDirCheck(const char* name)
    926 {
    927   if (name == NULL)
    928     return NULL;
    929   char* retName;
    930   if (!strncmp(name, "~/", 2))
     844std::string ResourceManager::homeDirCheck(const std::string& name)
     845{
     846  std::string retName;
     847  if (!strncmp(name.c_str(), "~/", 2))
    931848  {
    932849    char tmpFileName[500];
     
    936853    strcpy(tmpFileName, getenv("HOME"));
    937854#endif
    938     retName = new char[strlen(tmpFileName)+strlen(name)];
    939     sprintf(retName, "%s%s", tmpFileName, name+1);
    940   }
    941   else
    942   {
    943     retName = new char[strlen(name)+1];
    944     strcpy(retName, name);
     855    retName = tmpFileName + name;
     856  }
     857  else
     858  {
     859    retName = name;
    945860  }
    946861  return retName;
     
    949864/**
    950865 * @param name the relative name of the File/Directory.
    951  * @returns a new char* with the name in abs-dir-format
    952  */
    953 char* ResourceManager::getAbsDir(const char* name)
    954 {
    955   if (name == NULL)
    956     return NULL;
    957   char* retName;
    958   if (strncmp(name, "/", 1))
    959   {
    960     if (*name == '.' && *(name+1) != '.')
    961       name++;
    962     const char* absDir = ResourceManager::cwd();
    963     retName = new char[strlen(absDir)+strlen(name)+1];
    964     sprintf(retName, "%s%s", absDir, name);
    965   }
    966   else
    967   {
    968     retName = new char[strlen(name)+1];
    969     strcpy(retName, name);
     866 * @returns a new std::string with the name in abs-dir-format
     867 */
     868std::string ResourceManager::getAbsDir(const std::string& name)
     869{
     870  if (name.empty())
     871    return "";
     872  std::string retName = name;
     873  if (strncmp(name.c_str(), "/", 1))
     874  {
     875    if (name[0] == '.' && name[1] != '.')
     876      retName.erase(0);
     877    const std::string& absDir = ResourceManager::cwd();
     878    retName = absDir + retName;
    970879  }
    971880  return retName;
     
    978887 * !!IMPORTANT: this has to be deleted from the outside!!
    979888*/
    980 char* ResourceManager::getFullName(const char* fileName)
    981 {
    982   if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
     889std::string ResourceManager::getFullName(const std::string& fileName)
     890{
     891  if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
    983892    return NULL;
    984893
    985   char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
    986                            + strlen(fileName) + 1];
    987   sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     894  std::string retName = ResourceManager::getInstance()->getDataDir() +fileName;
    988895  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
    989896    return retName;
    990897  else
    991   {
    992     delete[] retName;
    993898    return NULL;
    994   }
    995899}
    996900
     
    1005909 * @returns the Current Woring Directory
    1006910 */
    1007 const char* ResourceManager::cwd()
    1008 {
    1009   if (ResourceManager::getInstance()->_cwd == NULL)
     911const std::string& ResourceManager::cwd()
     912{
     913  if (ResourceManager::getInstance()->_cwd.empty())
    1010914  {
    1011915    char cwd[1024];
    1012916    char* errorCode = getcwd(cwd, 1024);
    1013917    if (errorCode == 0)
    1014       return NULL;
    1015 
    1016     ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1];
    1017     strcpy(ResourceManager::getInstance()->_cwd, cwd);
     918      return ResourceManager::getInstance()->_cwd;
     919
     920    ResourceManager::getInstance()->_cwd = cwd;
    1018921  }
    1019922  return ResourceManager::getInstance()->_cwd;
     
    1026929 * @returns true if the file exists, false otherwise
    1027930 */
    1028 bool ResourceManager::isInDataDir(const char* fileName)
    1029 {
    1030   if (fileName == NULL || ResourceManager::getInstance()->getDataDir() == NULL)
     931bool ResourceManager::isInDataDir(const std::string& fileName)
     932{
     933  if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())
    1031934    return false;
    1032935
    1033936  bool retVal = false;
    1034   char* checkFile = new char[strlen(ResourceManager::getInstance()->getDataDir())
    1035                              + strlen(fileName) + 1];
    1036   sprintf(checkFile, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     937  std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName;
    1037938
    1038939  if (ResourceManager::isFile(checkFile) || ResourceManager::isDir(checkFile))
     
    1040941  else
    1041942    retVal = false;
    1042   delete[] checkFile;
    1043943  return retVal;
    1044944}
     
    1055955  // if it is not initialized
    1056956  PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);
    1057   PRINT(0)(" Data-Directory is: %s\n", this->dataDir);
     957  PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str());
    1058958  PRINT(0)(" List of Image-Directories: ");
    1059   std::vector<char*>::const_iterator imageDir;
     959  std::vector<std::string>::const_iterator imageDir;
    1060960  for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)
    1061     PRINT(0)("%s ", (*imageDir));
     961    PRINT(0)("%s ", (*imageDir).c_str());
    1062962  PRINT(0)("\n");
    1063963
     
    1068968  {
    1069969    PRINT(0)("-----------------------------------------\n");
    1070     PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name, (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
     970    PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));
    1071971
    1072972    PRINT(0)("gets deleted at ");
Note: See TracChangeset for help on using the changeset viewer.