Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::Rsrc Class Reference

#include <arsrsrc.h>


Public Member Functions

 Rsrc (const string &aFilename="")
 ~Rsrc (void)
FormLoad (const string &aSection, const int aId)
void SetAddr (Form *f)
const bool Free (const int id)
icstring FindCombination (const icstring &aSection)

Static Public Member Functions

FormGetAddr (const int id)
icstring GetId (icstring &aStr)
icstring FindCrdOf (icstring aStr, const icstring &car)
icstring GetList (icstring &aStr)
int GetInt (icstring &aStr, const int aDefault=-1)
double GetDbl (icstring &aStr, const double aDefault=0.0)
string GetStr (icstring &aStr, const std::string aDefault=string(""))
RGBColor GetColor (icstring &aStr, const RGBColor &defaultColor)
int GetMnemo (icstring &aStr, map< icstring, unsigned long > &aMnemo=ArsApplication::Mnemo_f, const int aDefault=0)

Private Attributes

char * buffer


Constructor & Destructor Documentation

Ars::Rsrc::Rsrc const string &  aFilename = ""  ) 
 

Definition at line 27 of file arsrsrc.cpp.

References buffer, and Cfg::GetCfg().

00028 : buffer( 0 )
00029 {
00030         string  fname = aFilename.empty() ? Cfg::GetCfg().GetCfgString( "Paths" , string( "Dlg-" ) + ArsApplication::GetCoordStr() ) : aFilename;
00031         if( fname[0] == '@' )
00032                 fname = Cfg::GetCfg( aFilename ).GetFilename();
00033 
00034         FILE    *fd = fopen( fname.c_str() , "r" );
00035         if( fd )
00036         {
00037                 fseek( fd , 0 , SEEK_END );
00038                 long    flen = ftell( fd );
00039                 fseek( fd , 0 , SEEK_SET );
00040 
00041                 if( flen )
00042                 {
00043                         buffer = new char[ flen + 1];
00044                         memset( buffer , 0 , flen + 1 );
00045                         fread( buffer , flen , sizeof( char ) , fd );
00046                 }
00047                 fclose( fd );
00048         }
00049 }

Ars::Rsrc::~Rsrc void   ) 
 

Definition at line 51 of file arsrsrc.cpp.

References buffer.

00052 {
00053         if( buffer )
00054                 delete buffer;
00055         buffer = 0;
00056 }


Member Function Documentation

icstring Ars::Rsrc::FindCombination const icstring aSection  ) 
 

Definition at line 143 of file arsrsrc.cpp.

References buffer, and icstring.

Referenced by Load(), and Ars::Preload().

00144 {
00145         char    *s = buffer , *s2 = 0;
00146         bool found = false;
00147         while( !found && s && *s )
00148         {
00149                 while( *s && *s != '(' )        
00150                 {
00151                         if( *s == ';' || (*s == '/' && s[1] == '/') )
00152                                 while( *s && *s != '\n' )
00153                                         s++;
00154                         s++;
00155                 }
00156                 int     cnt = 1;
00157                 s2 = ++s;
00158                 while( *s2 && cnt )
00159                 {
00160                         if( *s2 == '(' )
00161                                 cnt += 1;
00162                         else if( *s2 == '\"' )
00163                                 while( *++s2 != '\"' )  ;
00164                         else if( *s2 == ')' )
00165                                 cnt -= 1;
00166                         s2 += 1;
00167                 }
00168 
00169                 s2 -= 2;
00170                 if( aSection == icstring( s , aSection.length() ) )
00171                         found = true;
00172                 else
00173                         s = s2 + 2;
00174         }
00175         
00176         if( found && s < s2 )
00177         {
00178                 while( *s && *s != '(' )        s++;
00179 
00180                 if( s < s2 )
00181                         return icstring( s , s2 - s );
00182         }
00183 
00184         return "";
00185 }

icstring Ars::Rsrc::FindCrdOf icstring  aStr,
const icstring car
[static]
 

Definition at line 189 of file arsrsrc.cpp.

References GetId(), GetList(), icstring, Ars::rsrcMutex, and Ars::strip().

00190 {
00191         SDL_mutexP( rsrcMutex );
00192         icstring        ans = GetList( aStr );
00193         while( !ans.empty() )
00194                 if( GetId( ans ) == car )
00195                         break;
00196                 else
00197                         ans = GetList( aStr );
00198 
00199         ans = strip( ans );
00200         SDL_mutexV( rsrcMutex );
00201 
00202         return ans;
00203 }

const bool Ars::Rsrc::Free const int  id  ) 
 

Definition at line 126 of file arsrsrc.cpp.

References Stack.

00127 {
00128         if( !Stack.empty() )
00129         {
00130                 deque<Form *>::iterator at = find_if( Stack.begin() , Stack.end() , bind2nd( mem_fun( &Form::HasId ) , &id ) );
00131                 if( at != Stack.end() )
00132                 {
00133                         Form    *f = *at;
00134                         Stack.erase( at );
00135 
00136                         delete f;
00137                         return true;
00138                 }
00139         }
00140         return false;
00141 }

Form * Ars::Rsrc::GetAddr const int  id  )  [static]
 

Definition at line 112 of file arsrsrc.cpp.

References Stack.

Referenced by Load().

00113 {
00114         deque<Form *>::iterator at = find_if( Stack.begin() , Stack.end() , bind2nd( mem_fun( &Form::HasId ) , &id ) );
00115         if( at != Stack.end() )
00116                 return *at;
00117 
00118         return 0;
00119 }

RGBColor Ars::Rsrc::GetColor icstring aStr,
const RGBColor defaultColor
[static]
 

Definition at line 341 of file arsrsrc.cpp.

References Ars::RGBColor::alpha, Ars::RGBColor::blue, GetInt(), Ars::RGBColor::green, Ars::RGBColor::red, and Ars::rsrcMutex.

00342 {
00343         SDL_mutexP( rsrcMutex );
00344         int     c = GetInt( aStr ,  (defaultColor.alpha << 24 | defaultColor.red << 16 | defaultColor.green << 8 | defaultColor.blue) );
00345         SDL_mutexV( rsrcMutex );
00346         return RGBColor( (unsigned char)( (c >> 16) & 0xff ) , (unsigned char)( (c >> 8) & 0xff ) , (unsigned char)( c & 0xff ) , (unsigned char)( c & 0xff000000 ? (c >> 24) & 0xff : 0xff ) );
00347 }

double Ars::Rsrc::GetDbl icstring aStr,
const double  aDefault = 0.0
[static]
 

Definition at line 241 of file arsrsrc.cpp.

References Ars::rsrcMutex.

00242 {
00243         SDL_mutexP( rsrcMutex );
00244         int     i = 0;
00245         while( aStr[i] && !(isdigit( aStr[i] ) || aStr[i] == '-') )     i += 1;
00246 
00247         double  ans = aDefault;
00248         sscanf( aStr.substr( i ).c_str () , "%lf" , &ans );
00249         
00250         while( aStr[i] && (isdigit( aStr[i] ) || aStr[i] == '-' || aStr[i] == '.') )    i += 1;
00251         aStr = aStr.substr( i );
00252         SDL_mutexV( rsrcMutex );
00253 
00254         return ans;
00255 }

icstring Ars::Rsrc::GetId icstring aStr  )  [static]
 

Definition at line 205 of file arsrsrc.cpp.

References icstring, and Ars::rsrcMutex.

Referenced by FindCrdOf(), and Load().

00206 {
00207         SDL_mutexP( rsrcMutex );
00208         int     i = 0;
00209         while( aStr[i] && !isalnum( aStr[i] ) ) i += 1;
00210         icstring        ans;
00211 
00212         if( aStr[i] )
00213         {
00214                 while( aStr[i] && (isalnum( aStr[i] ) || aStr[i] == '_') )
00215                         ans += aStr[i++];
00216         }
00217         aStr = aStr.substr( i );
00218         SDL_mutexV( rsrcMutex );
00219         return ans;
00220 }

int Ars::Rsrc::GetInt icstring aStr,
const int  aDefault = -1
[static]
 

Definition at line 222 of file arsrsrc.cpp.

References Ars::rsrcMutex.

Referenced by GetColor(), and GetMnemo().

00223 {
00224         SDL_mutexP( rsrcMutex );
00225         int     i = 0;
00226         while( aStr[i] && !(isdigit( aStr[i] ) || aStr[i] == '-') )     i += 1;
00227 
00228         int     ans = aDefault;
00229         if( aStr.substr( i , 2 ) == "0x" || aStr.substr( i , 2 ) == "0X" )
00230                 sscanf( aStr.substr( i + 2 ).c_str () , "%x" , &ans );
00231         else
00232                 sscanf( aStr.substr( i ).c_str () , "%d" , &ans );
00233         
00234         while( aStr[i] && (isxdigit( aStr[i] ) || aStr[i] == '-') )     i += 1;
00235         aStr = aStr.substr( i );
00236         SDL_mutexV( rsrcMutex );
00237 
00238         return ans;
00239 }

icstring Ars::Rsrc::GetList icstring aStr  )  [static]
 

Definition at line 313 of file arsrsrc.cpp.

References icstring, Ars::rsrcMutex, and Ars::strip().

Referenced by FindCrdOf(), and Load().

00314 {
00315         SDL_mutexP( rsrcMutex );
00316         icstring::size_type     idx = aStr.find( "(" );
00317         icstring        ans;
00318         if( idx != string::npos && aStr[idx] == '(' )
00319         {
00320                 aStr = aStr.substr( idx + 1 );
00321                 int     cnt = 1 , i = -1;
00322                 while( cnt && aStr[++i] )
00323                 {
00324                         if( aStr[i] == '\"' )
00325                         {
00326                                 i += 1;
00327                                 while( aStr[i] && aStr[i] != '\"' )             i++;
00328                         }
00329                         else if( aStr[i] == ')' )
00330                                 cnt -= 1;
00331                         else if( aStr[i] == '(' )
00332                                 cnt += 1;
00333                 }
00334                 ans = aStr.substr( 0 , i++ );
00335                 aStr = aStr.substr( i );
00336         }
00337         SDL_mutexV( rsrcMutex );
00338         return strip( ans );
00339 }

int Ars::Rsrc::GetMnemo icstring aStr,
map< icstring, unsigned long > &  aMnemo = ArsApplication::Mnemo_f,
const int  aDefault = 0
[static]
 

Definition at line 349 of file arsrsrc.cpp.

References GetInt(), icstring, Ars::rsrcMutex, and Ars::strip().

00350 {
00351         SDL_mutexP( rsrcMutex );
00352         string::size_type       idx = 0;
00353         
00354         while( aStr[idx] && !isalpha( aStr[idx] ) )     idx++;
00355         icstring        ans = aStr.substr( idx );
00356         aStr = aStr.substr( idx );
00357 
00358         int     val = aDefault;
00359 
00360         while( (idx = ans.find( "|" )) != string::npos )
00361         {
00362                 icstring        s = ans.substr( 0 , idx );
00363                 if( aMnemo.find( s ) != aMnemo.end() )
00364                         val |= aMnemo[strip( s )];
00365                 else
00366                         val |= GetInt( s );
00367                 ans = ans.substr( idx + 1 );
00368         }
00369         if( aMnemo.find( ans ) != aMnemo.end() )
00370                 val |= aMnemo[strip( ans )];
00371         else if( aMnemo.find( ans ) != aMnemo.end() )
00372                 val |= GetInt( ans );
00373 
00374         SDL_mutexV( rsrcMutex );
00375 
00376         return val;
00377 }

string Ars::Rsrc::GetStr icstring aStr,
const std::string  aDefault = string("")
[static]
 

Definition at line 257 of file arsrsrc.cpp.

References Ars::rsrcMutex.

00258 {
00259         SDL_mutexP( rsrcMutex );
00260         string::size_type       idx = 0;
00261         while( aStr[idx] && aStr[idx] != '\"' ) idx++;
00262         
00263         if( aStr[idx] == '\"' )
00264         {
00265                 string  ans;
00266 
00267                 aStr = aStr.substr( idx + 1 );
00268                 idx = 0;
00269                 while( aStr[idx] && aStr[idx] != '\"' )
00270                         if( aStr[idx] == '\\' )
00271                                 idx += 2;
00272                         else
00273                                 idx += 1;
00274                 ans = aStr.substr( 0 , idx ).c_str();
00275                 aStr = aStr.substr( idx + 1 );
00276 
00277                 if( !ans.empty() )
00278                 {
00279                         while( (idx = ans.find( "\\n" )) != string::npos )
00280                         {
00281                                 string  rslt = ans.substr( 0 , idx);
00282                                 rslt += "\n";
00283                                 rslt += ans.substr( idx + 2 );
00284                                 ans = rslt;
00285                         }
00286                         while( (idx = ans.find( "\\t" )) != string::npos )
00287                         {
00288                                 string  rslt = ans.substr( 0 , idx );
00289                                 rslt += "\t";
00290                                 rslt += ans.substr( idx + 2 );
00291                                 ans = rslt;
00292                         }
00293                         while( (idx = ans.find( "\\\"" )) != string::npos )
00294                         {
00295                                 string  rslt = ans.substr( 0 , idx);
00296                                 rslt += "\"";
00297                                 rslt += ans.substr( idx + 2 );
00298                                 ans = rslt;
00299                         }
00300                 }
00301                 else
00302                 {
00303                         SDL_mutexV( rsrcMutex );
00304                         return aDefault;
00305                 }
00306                 SDL_mutexV( rsrcMutex );
00307                 return ans;
00308         }
00309         SDL_mutexV( rsrcMutex );
00310         return aDefault;
00311 }

Form * Ars::Rsrc::Load const string &  aSection,
const int  aId
 

Initialize a resource in memory. Scan each line in the cfg file and assign the resource 'Form' the id provided. Each line of command must begin with the following: , x , y , w , h, ...

Definition at line 79 of file arsrsrc.cpp.

References FindCombination(), GetAddr(), GetId(), GetList(), icstring, Ars::Window::Init(), Stack, and Ars::strip().

00080 {
00081         Form    *f = GetAddr( aId );
00082         if( f )
00083                 return f;
00084         icstring        tmp = aSection.c_str();
00085         tmp = FindCombination( tmp );
00086         icstring        DlgStr = strip( tmp );
00087         f = new Form( aId );
00088 
00089         while( !DlgStr.empty() )
00090         {
00091                 icstring        obdef = GetList( DlgStr );
00092                 if( !obdef.empty() )
00093                 {
00094                         icstring        sid = GetId( obdef );
00095                         Window  *wnd = 0;
00096                         //      Call the window create....
00097                         for( vector<cbObjCreateType>::iterator it = ArsApplication::objCreate.begin() ; it != ArsApplication::objCreate.end() ; ++it )
00098                                 if( (wnd = (*it)( sid )) != 0 )
00099                                         break;
00100                         if( wnd == 0 )
00101                                 wnd = new Window();
00102 
00103                         wnd->Init( obdef );
00104                         f->push_back( wnd );
00105                 }
00106         }
00107         Stack.push_back( f );
00108 
00109         return f;
00110 }

void Ars::Rsrc::SetAddr Form f  ) 
 

Definition at line 121 of file arsrsrc.cpp.

References Stack.

00122 {
00123         Stack.push_back( f );
00124 }


Field Documentation

char* Ars::Rsrc::buffer [private]
 

Definition at line 14 of file arsrsrc.h.

Referenced by FindCombination(), Rsrc(), and ~Rsrc().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:48 2003 for Borqueror by doxygen 1.3.3