Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

Location:
orxonox/trunk/src/lib/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/ini_parser.cc

    r4381 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2828IniParser::IniParser (const char* filename)
    2929{
     30  this->setClassID(CL_INI_PARSER, "IniParser");
     31
    3032  stream = NULL;
    3133  bInSection = false;
     
    5052  char* tmpName = ResourceManager::homeDirCheck(filename);
    5153  if( filename == NULL) return -1;
    52   if( stream != NULL)   fclose (stream);
     54  if( stream != NULL)   fclose (stream);
    5355  if( (stream = fopen (tmpName, "r")) == NULL)
    5456    {
     
    7173  bInSection = false;
    7274  if( stream == NULL) return -1;
    73  
     75
    7476  char linebuffer[PARSELINELENGHT];
    7577  char secbuffer[PARSELINELENGHT];
    7678  char* ptr;
    77  
     79
    7880  rewind (stream);
    7981  while( !feof( stream))
     
    8587      // check for section identifyer
    8688      if( sscanf (linebuffer, "[%s", secbuffer) == 1)
    87         {
    88           if( (ptr = strchr( secbuffer, ']')) != NULL)
    89             {
    90               *ptr = 0;
    91               if( !strcmp( secbuffer, section))
    92                 {
    93                   bInSection = true;
    94                   return 0;
    95                 }
    96             }
    97         }
     89        {
     90          if( (ptr = strchr( secbuffer, ']')) != NULL)
     91            {
     92              *ptr = 0;
     93              if( !strcmp( secbuffer, section))
     94                {
     95                  bInSection = true;
     96                  return 0;
     97                }
     98            }
     99        }
    98100    }
    99101  return -1;
     
    114116    }
    115117  if( !bInSection) return -1;
    116  
     118
    117119  char linebuffer[PARSELINELENGHT];
    118120  char* ptr;
    119  
     121
    120122  while( !feof( stream))
    121123    {
     
    125127      if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0;
    126128      if( linebuffer[0] == '[')
    127         {
    128           bInSection = false;
    129           return -1;
    130         }
     129        {
     130          bInSection = false;
     131          return -1;
     132        }
    131133      sscanf(linebuffer, "%s = %s", name, value);
    132134      return 0;
    133135      /*
    134         if( (ptr = strchr( tmpBuffer, '=')) != NULL)
    135         {
    136         if( ptr == linebuffer) continue;
    137         strcpy (value, &ptr[1]);
    138         strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
    139         printf ("%s, %s\n", value, name);
    140         return 0;
    141         }
     136        if( (ptr = strchr( tmpBuffer, '=')) != NULL)
     137        {
     138        if( ptr == linebuffer) continue;
     139        strcpy (value, &ptr[1]);
     140        strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
     141        printf ("%s, %s\n", value, name);
     142        return 0;
     143        }
    142144      */
    143145    }
    144   return -1;   
     146  return -1;
    145147}
    146148
     
    151153   \param defvalue: what should be returned in case the entry cannot be found
    152154   \return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found
    153    
     155
    154156   The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
    155157   lead to unwanted behaviour.
     
    159161  strcpy (internbuf, defvalue);
    160162  if( getSection (section) == -1) return internbuf;
    161  
     163
    162164  char namebuf[PARSELINELENGHT];
    163165  char valuebuf[PARSELINELENGHT];
    164  
     166
    165167  while( nextVar (namebuf, valuebuf) != -1)
    166168    {
    167169      if( !strcmp (name, namebuf))
    168         {
    169           strcpy (internbuf, valuebuf);
    170           return internbuf;
    171         }
     170        {
     171          strcpy (internbuf, valuebuf);
     172          return internbuf;
     173        }
    172174    }
    173175  return internbuf;
  • orxonox/trunk/src/lib/util/ini_parser.h

    r4482 r4597  
    22    \file ini_parser.h
    33    \brief A small ini file parser
    4    
     4
    55    Can be used to find a defined [Section] in an ini file and get the VarName=Value entries
    66*/
     
    1212#include <string.h>
    1313#include <stdlib.h>
     14#include "base_object.h"
    1415
    1516#define PARSELINELENGHT     512       //!< how many chars to read at once
     
    1718//! ini-file parser
    1819/**
    19         This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
     20        This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
    2021*/
    21 class IniParser {
     22class IniParser : public BaseObject
     23{
    2224 public:
    2325  IniParser (const char* filename);
    2426  ~IniParser ();
    25  
     27
    2628  char* getVar(const char* name, char* section, char* defvalue);
    2729  int openFile(const char* name);
     
    3335  bool          bInSection;                   //!< if the requested parameter is in the section.
    3436  char          internbuf[PARSELINELENGHT];   //!< a buffer
    35        
     37
    3638
    3739};
  • orxonox/trunk/src/lib/util/substring.cc

    r4220 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1111   ### File Specific:
    1212   main-programmer: Christian Meyer
    13    co-programmer: ...
     13   co-programmer: Benjamin Grauer
     14
     15   2005-06-10: some naming conventions
    1416*/
    1517
     
    2830{
    2931  n = 0;
    30        
     32
    3133  assert( string != NULL);
    32        
     34
    3335  for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++;
    3436
    3537  n += 1;
    36        
     38
    3739  strings = new char*[n];
    3840
    3941  assert (strings != NULL);
    40        
     42
    4143  int i = 0;
    4244  int l = 0;
    43        
     45
    4446  const char* offset = string;
    4547  char* end = strchr( string, ',');
     
    5759      end = strchr( offset, ',');
    5860    }
    59        
     61
    6062  strings[i] = new char[l + 1];
    6163  l = strlen( offset);
     
    7375      delete strings[i];
    7476    }
    75        
     77
    7678  delete strings;
    7779}
  • orxonox/trunk/src/lib/util/substring.h

    r4482 r4597  
    1 /*! 
     1/*!
    22  \file substring.h
    33  \brief a small class to get the parts of a string separated by commas
     
    1313  SubString(const char* string);
    1414  ~SubString();
    15                
     15
    1616  int getCount();
    1717  const char* getString( int i);
    18                
     18
    1919 private:
    2020  char**     strings;         //!< strings produced from a single string splitted in multiple strings
Note: See TracChangeset for help on using the changeset viewer.