tConfItemBase Class Reference

#include <tConfiguration.h>

Inheritance diagram for tConfItemBase:

Inheritance graph
[legend]
Collaboration diagram for tConfItemBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

typedef void callbackFunc (void)
 tConfItemBase (const char *title, const tOutput &help, callbackFunc *cb=0)
 tConfItemBase (const char *title, callbackFunc *cb=0)
virtual ~tConfItemBase ()
tString const & GetTitle () const
virtual void ReadVal (std::istream &s)=0
virtual void WriteVal (std::ostream &s)=0
virtual void WasChanged ()
virtual bool Writable ()
virtual bool Save ()

Static Public Member Functions

static int EatWhitespace (std::istream &s)
static void SaveAll (std::ostream &s)
static void LoadAll (std::istream &s)
static void LoadLine (std::istream &s)
 loads configuration from file
static bool LoadPlayback (bool print=false)
 loads one configuration line
static void DocAll (std::ostream &s)
 loads configuration from playback
static std::deque< tStringGetCommands (void)
static tConfItemBaseFindConfigItem (tString const &name)

Static Public Attributes

static bool printChange = true
 if set, setting changes are printed to the console and, if printErrors is set as well, suggestions of typo fixes are given.
static bool printErrors = true
 if set, unknown settings are pointed out.

Protected Types

typedef std::map< tString,
tConfItemBase * > 
tConfItemMap

Protected Member Functions

void ExecuteCallback ()

Static Protected Member Functions

static tConfItemMapConfItemMap ()

Protected Attributes

const tString title
const tOutput help
bool changed
tAccessLevel requiredLevel

Private Attributes

int id
callbackFunc * callback

Friends

class tCheckedPTRBase
class tConfItemLevel
class tAccessLevelSetter


Detailed Description

Definition at line 102 of file tConfiguration.h.


Member Typedef Documentation

typedef std::map< tString, tConfItemBase * > tConfItemBase::tConfItemMap [protected]

Definition at line 115 of file tConfiguration.h.


Constructor & Destructor Documentation

tConfItemBase::tConfItemBase ( const char *  title,
const tOutput help,
callbackFunc *  cb = 0 
)

Definition at line 286 of file tConfiguration.cpp.

References ConfItemMap(), requiredLevel, tAccessLevel_Admin, tERR_ERROR_INT, and title.

00287         :id(-1),title(t), help(h),
00288 changed(false),callback(cb){
00289 
00290     tConfItemMap & confmap = ConfItemMap();
00291     if ( confmap.find( title ) != confmap.end() )
00292         tERR_ERROR_INT("Two tConfItems with the same name " << t << "!");
00293 
00294     confmap[title] = this;
00295 
00296     requiredLevel = tAccessLevel_Admin;
00297 }

Here is the call graph for this function:

tConfItemBase::tConfItemBase ( const char *  title,
callbackFunc *  cb = 0 
)

Definition at line 266 of file tConfiguration.cpp.

References ConfItemMap(), help, requiredLevel, tAccessLevel_Admin, tERR_ERROR_INT, title, and tToLower().

00267         :id(-1),title(t),
00268 changed(false),callback(cb){
00269 
00270     tConfItemMap & confmap = ConfItemMap();
00271     if ( confmap.find( title ) != confmap.end() )
00272         tERR_ERROR_INT("Two tConfItems with the same name " << t << "!");
00273 
00274     // compose help name
00275     tString helpname;
00276     helpname << title << "_help";
00277     tToLower( helpname );
00278 
00279     const_cast<tOutput&>(help).AddLocale(helpname);
00280 
00281     confmap[title] = this;
00282 
00283     requiredLevel = tAccessLevel_Admin;
00284 }

Here is the call graph for this function:

tConfItemBase::~tConfItemBase (  )  [virtual]

Definition at line 299 of file tConfiguration.cpp.

References ConfItemMap(), st_confMap, and title.

00300 {
00301     tConfItemMap & confmap = ConfItemMap();
00302     confmap.erase(title);
00303     if ( confmap.size() == 0 )
00304     {
00305         delete st_confMap;
00306         st_confMap = 0;
00307     }
00308 }

Here is the call graph for this function:


Member Function Documentation

tConfItemBase::tConfItemMap & tConfItemBase::ConfItemMap (  )  [static, protected]

Definition at line 107 of file tConfiguration.cpp.

References st_confMap, and tNEW.

Referenced by DocAll(), FindConfigItem(), GetCommands(), LoadLine(), nConfItemBase::s_GetConfigMessage(), nConfItemBase::s_RevertToDefaults(), nConfItemBase::s_RevertToSavedValues(), nConfItemBase::s_SaveValues(), nConfItemBase::s_SendConfig(), SaveAll(), tConfItemBase(), and ~tConfItemBase().

00108 {
00109     if (!st_confMap)
00110         st_confMap = tNEW( tConfItemMap );
00111     return *st_confMap;
00112 }

Here is the caller graph for this function:

typedef void tConfItemBase::callbackFunc ( void   ) 

Referenced by _wrap_new_TConfItemBase__SWIG_0().

Here is the caller graph for this function:

void tConfItemBase::ExecuteCallback (  )  [inline, protected]

Definition at line 123 of file tConfiguration.h.

References callback.

Referenced by nConfItem< tString >::NetReadVal(), tConfItem< nConfigItemBehavior >::ReadVal(), tConfItemLine::ReadVal(), and nConfItemLine::ReadVal().

00123 {if (callback != 0) (*callback)(); }

Here is the caller graph for this function:

tString const& tConfItemBase::GetTitle (  )  const [inline]

Definition at line 135 of file tConfiguration.h.

References title.

Referenced by nConfItemVersionWatcher::FillTemplateParameters().

00135                                      {
00136         return title;
00137     }

Here is the caller graph for this function:

int tConfItemBase::EatWhitespace ( std::istream &  s  )  [static]

Definition at line 323 of file tConfiguration.cpp.

References c, and isblank().

Referenced by tConfItem< nConfigItemBehavior >::ReadVal().

00323                                              {
00324     int c=' ';
00325 
00326     while(isblank(c) &&
00327             c!='\n'    &&
00328             s.good()  &&
00329             !s.eof())
00330         c=s.get();
00331 
00332     s.putback(c);
00333 
00334     return c;
00335 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tConfItemBase::SaveAll ( std::ostream &  s  )  [static]

Definition at line 310 of file tConfiguration.cpp.

References ConfItemMap(), Save(), title, and WriteVal().

Referenced by st_SaveConfig().

00310                                         {
00311     tConfItemMap & confmap = ConfItemMap();
00312     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00313     {
00314         tConfItemBase * ci = (*iter).second;
00315         if (ci->Save()){
00316             s << std::setw(28) << ci->title << " ";
00317             ci->WriteVal(s);
00318             s << '\n';
00319         }
00320     }
00321 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tConfItemBase::LoadAll ( std::istream &  s  )  [static]

concatenate lines ending in a backslash

Definition at line 571 of file tConfiguration.cpp.

References con, tException::GetDescription(), tRecorderBase::IsPlayingBack(), tString::Len(), LoadLine(), tString::ReadLine(), tRecorder::Record(), s_VetoPlayback(), s_VetoRecording(), tString::Size(), tString::StartsWith(), and tString::SubStr().

Referenced by _wrap_TConfItemBase_load_all(), zEffectorSetting::effect(), gMemuItemConsole::Event(), Load(), gParser::parseSetting(), RInclude(), sr_Read_stdin(), gGame::StateUpdate(), and tConfItemBase_LoadString().

00571                                         {
00572     tCurrentAccessLevel levelResetter;
00573 
00574     try{
00575 
00576     while(!s.eof() && s.good())
00577     {
00578         tString line;
00579 
00580         // read line from stream
00581         line.ReadLine( s );
00582 
00584         while ( line.Size() > 0 && line[line.Size()-1] == '\\' && s.good() && !s.eof() )
00585         {
00586             line = line.SubStr( 0, line.Size()-1 );
00587 
00588             // unless it is a double backslash
00589             if ( line.Size() > 0 && line[line.Size()-1] == '\\' )
00590             {
00591                 break;
00592             }
00593 
00594             tString rest;
00595             rest.ReadLine( s );
00596             line << rest;
00597         }
00598 
00599         if ( line.Len() <= 1 )
00600             continue;
00601 
00602         // write line to recording
00603         if ( !s_VetoRecording( line ) )
00604         {
00605             // don't record supid admins' instant chat logins
00606             static tString instantChat("INSTANT_CHAT_STRING");
00607             if ( line.StartsWith( instantChat ) && strstr( line, "/login" ) )
00608             {
00609                 tString newLine = line.SubStr( 0, strstr( line, "/login" ) - (char const *)line );
00610                 newLine += "/login NONE";
00611                 if ( line[strlen(line)-1] == '\\' )
00612                     newLine += '\\';
00613                 tRecorder::Record( recordingSection, newLine );
00614             }
00615             else
00616                 tRecorder::Record( recordingSection, line );
00617         }
00618 
00619         //        std::cout << line << '\n';
00620 
00621         // process line
00622         // line << '\n';
00623         if ( !tRecorder::IsPlayingBack() || s_VetoPlayback( line ) )
00624         {
00625             std::stringstream str(static_cast< char const * >( line ) );
00626             tConfItemBase::LoadLine(str);
00627             // std::cout << line << '\n';
00628         }
00629     }
00630     }
00631     catch( tAbortLoading const & e )
00632     {
00633         // loading was aborted
00634         con << e.GetDescription() << "\n";
00635     }
00636 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tConfItemBase::LoadLine ( std::istream &  s  )  [static]

loads configuration from file

Definition at line 337 of file tConfiguration.cpp.

References c, changed, con, ConfItemMap(), tCurrentAccessLevel::GetAccessLevel(), tCurrentAccessLevel::GetName(), help, printChange, printErrors, tString::ReadLine(), ReadVal(), requiredLevel, tString::SetPos(), tOutput::SetTemplateParameter(), title, tToUpper(), and WasChanged().

Referenced by _wrap_TConfItemBase_load_line(), LoadAll(), and LoadPlayback().

00337                                          {
00338     if(!s.eof() && s.good()){
00339         tString name;
00340         s >> name;
00341 
00342         // make name uppercase:
00343         tToUpper( name );
00344 
00345         bool found=false;
00346 
00347         if (name.Size()==0) // ignore empty lines
00348             found=true;
00349         else if (name[0]=='#'){ // comment. ignore rest of line
00350             char c=' ';
00351             while(c!='\n' && s.good() && !s.eof()) c=s.get();
00352             found=true;
00353         }
00354 
00355         tConfItemMap & confmap = ConfItemMap();
00356         tConfItemMap::iterator iter = confmap.find( name );
00357         if ( iter != confmap.end() )
00358         {
00359             tConfItemBase * ci = (*iter).second;
00360 
00361             bool cb=ci->changed;
00362             ci->changed=false;
00363 
00364             if ( ci->requiredLevel >= tCurrentAccessLevel::GetAccessLevel() )
00365             {
00366                 ci->ReadVal(s);
00367                 if (ci->changed)
00368                     ci->WasChanged();
00369                 else
00370                     ci->changed=cb;
00371             }
00372             else
00373             {
00374                 tString discard;
00375                 discard.ReadLine(s);
00376                 
00377                 con << tOutput( "$access_level_error",
00378                                 name,  
00379                                 tCurrentAccessLevel::GetName( ci->requiredLevel ),
00380                                 tCurrentAccessLevel::GetName( tCurrentAccessLevel::GetAccessLevel() )
00381                     );
00382                 return;
00383             }
00384 
00385             found=true;
00386         }
00387 
00388         if (!found){
00389             // eat rest of input line
00390             tString rest;
00391             rest.ReadLine( s );
00392 #ifdef MACOSX
00393             printErrors = false;
00394 #endif
00395             if (printErrors)
00396             {
00397                 tOutput o;
00398                 o.SetTemplateParameter(1, name);
00399                 o << "$config_command_unknown";
00400                 con << o;
00401 
00402                 if (printChange)
00403                 {
00404                     int sim_maxlen=-1;
00405 
00406                     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00407                     {
00408                         tConfItemBase * ci = (*iter).second;
00409                         if (strstr(ci->title,name) &&
00410                                 static_cast<int>(strlen(ci->title)) > sim_maxlen)
00411                             sim_maxlen=strlen(ci->title);
00412                     }
00413 
00414                     if (sim_maxlen>0 && printChange ){
00415                         int len = name.Len()-1;
00416                         int printMax = 1 + 3 * len * len * len;
00417                         con << tOutput("$config_command_other");
00418                         for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00419                         {
00420                             tConfItemBase * ci = (*iter).second;
00421                             if (strstr(ci->title,name))
00422                             {
00423                                 tString help ( ci->help );
00424                                 if ( --printMax > 0 )
00425                                 {
00426                                     tString mess;
00427                                     mess << ci->title;
00428                                     mess.SetPos( sim_maxlen+2, false );
00429                                     mess << "(";
00430                                     mess << help;
00431                                     mess << ")\n";
00432                                     con << mess;
00433                                 }
00434                             }
00435                         }
00436                         if (printMax <= 0 )
00437                             con << tOutput("$config_command_more");
00438                     }
00439                 }
00440                 else
00441                 {
00442                     con << '\n';
00443                 }
00444             }
00445         }
00446     }
00447 
00448     //  std::cout << line << " lines read.\n";
00449 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tConfItemBase::LoadPlayback ( bool  print = false  )  [static]

loads one configuration line

Definition at line 702 of file tConfiguration.cpp.

References con, tRecorderBase::IsPlayingBack(), LoadLine(), tRecorder::Playback(), tRecorder::Record(), and s_VetoPlayback().

Referenced by gMemuItemConsole::Event(), gParser::parseSetting(), sr_Read_stdin(), st_LoadConfig(), and gGame::StateUpdate().

00703 {
00704     if ( !tRecorder::IsPlayingBack() )
00705         return false;
00706 
00707     // read line from recording
00708     tString line;
00709     while ( tRecorder::Playback( recordingSection, line ) )
00710     {
00711         tRecorder::Record( recordingSection, line );
00712         if ( !s_VetoPlayback( line ) )
00713         {
00714             // process line
00715             if ( print ) con << "Playback input : " << line << '\n';
00716             std::stringstream str(static_cast< char const * >( line ) );
00717             tConfItemBase::LoadLine(str);
00718         }
00719     }
00720 
00721     return true;
00722 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tConfItemBase::DocAll ( std::ostream &  s  )  [static]

loads configuration from playback

Definition at line 638 of file tConfiguration.cpp.

References ConfItemMap(), help, tString::SetPos(), and title.

Referenced by tCommandLineData::Execute().

00638                                        {
00639     tConfItemMap & confmap = ConfItemMap();
00640     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00641     {
00642         tConfItemBase * ci = (*iter).second;
00643 
00644         tString help ( ci->help );
00645         if ( help != "UNDOCUMENTED" )
00646         {
00647             tString line;
00648             line << ci->title;
00649             line.SetPos( 30, false );
00650             line << help;
00651             s << line << '\n';
00652         }
00653     }
00654 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::deque< tString > tConfItemBase::GetCommands ( void   )  [static]

Definition at line 656 of file tConfiguration.cpp.

References ConfItemMap(), title, and tString::ToLower().

Referenced by do_con().

00656                                             {
00657     std::deque<tString> ret;
00658     tConfItemMap & confmap = ConfItemMap();
00659     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00660     {
00661         tConfItemBase * ci = (*iter).second;
00662 
00663         ret.push_back(ci->title.ToLower());
00664     }
00665     return ret;
00666 }

Here is the call graph for this function:

Here is the caller graph for this function:

tConfItemBase * tConfItemBase::FindConfigItem ( tString const &  name  )  [static]

Definition at line 667 of file tConfiguration.cpp.

References ConfItemMap(), and tString::ToUpper().

Referenced by _wrap_TConfItemBase_find_config_item(), and gAutoCompleterConsole::Complete().

00667                                                                 {
00668     tConfItemMap & confmap = ConfItemMap();
00669     tConfItemMap::iterator iter = confmap.find( name.ToUpper() );
00670     if ( iter != confmap.end() ) {
00671         return iter->second;
00672     } else {
00673         return 0;
00674     }
00675 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void tConfItemBase::ReadVal ( std::istream &  s  )  [pure virtual]

Implemented in tConfItemPassword, nConfItemLine, SwigDirector_TConfItemBase, tConfItem< T >, tConfItemLine, tConfItemFunc, tSettingRotation, tConfItem_key, tConfItem< float >, tConfItem< tString >, tConfItem< int >, and tConfItem< nConfigItemBehavior >.

Referenced by LoadLine().

Here is the caller graph for this function:

virtual void tConfItemBase::WriteVal ( std::ostream &  s  )  [pure virtual]

Implemented in tConfItemPassword, SwigDirector_TConfItemBase, tConfItem< T >, tConfItemLine, tConfItemFunc, tSettingRotation, tConfItem_key, tConfItem< float >, tConfItem< tString >, tConfItem< int >, and tConfItem< nConfigItemBehavior >.

Referenced by gAutoCompleterConsole::Complete(), vValue::Expr::Bindings::Legacy::ConfItem::Read(), and SaveAll().

Here is the caller graph for this function:

virtual void tConfItemBase::WasChanged (  )  [inline, virtual]

Reimplemented in nConfItem< T >, and nConfItem< tString >.

Definition at line 152 of file tConfiguration.h.

Referenced by LoadLine(), and nConfItem< tString >::WasChanged().

00152 {} // what to do if a read changed the thing

Here is the caller graph for this function:

virtual bool tConfItemBase::Writable ( void   )  [inline, virtual]

Reimplemented in nConfItemBase, and tSettingRotation.

Definition at line 154 of file tConfiguration.h.

Referenced by tConfItem< nConfigItemBehavior >::ReadVal().

00154                            {
00155         return true;
00156     }

Here is the caller graph for this function:

virtual bool tConfItemBase::Save (  )  [inline, virtual]

Reimplemented in nSettingItem< T >, tSettingItem< T >, tConfItemFunc, tSettingRotation, tSettingItem< float >, and tSettingItem< nConfigItemBehavior >.

Definition at line 158 of file tConfiguration.h.

Referenced by SaveAll().

00158                        {
00159         return true;
00160     }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class tCheckedPTRBase [friend]

Definition at line 104 of file tConfiguration.h.

friend class tConfItemLevel [friend]

Definition at line 105 of file tConfiguration.h.

friend class tAccessLevelSetter [friend]

Definition at line 106 of file tConfiguration.h.


Member Data Documentation

int tConfItemBase::id [private]

Definition at line 108 of file tConfiguration.h.

const tString tConfItemBase::title [protected]

Definition at line 110 of file tConfiguration.h.

Referenced by DocAll(), GetCommands(), GetTitle(), LoadLine(), nConfItem< tString >::NetReadVal(), tConfItem< nConfigItemBehavior >::ReadVal(), tConfItemLine::ReadVal(), nConfItemLine::ReadVal(), SaveAll(), nConfItemBase::SendConfig(), tConfItemBase(), and ~tConfItemBase().

const tOutput tConfItemBase::help [protected]

Definition at line 111 of file tConfiguration.h.

Referenced by DocAll(), LoadLine(), and tConfItemBase().

bool tConfItemBase::changed [protected]

Definition at line 112 of file tConfiguration.h.

Referenced by LoadLine(), nConfItem< tString >::NetReadVal(), tConfItem< nConfigItemBehavior >::ReadVal(), tConfItemLine::ReadVal(), nConfItemLine::ReadVal(), nConfItemBase::SendConfig(), and nConfItem< tString >::Set().

tAccessLevel tConfItemBase::requiredLevel [protected]

Definition at line 113 of file tConfiguration.h.

Referenced by LoadLine(), tAccessLevelSetter::tAccessLevelSetter(), and tConfItemBase().

callbackFunc* tConfItemBase::callback [private]

Definition at line 121 of file tConfiguration.h.

Referenced by ExecuteCallback().

bool tConfItemBase::printChange = true [static]

if set, setting changes are printed to the console and, if printErrors is set as well, suggestions of typo fixes are given.

Definition at line 128 of file tConfiguration.h.

Referenced by LoadLine(), nConfItem< tString >::NetReadVal(), tConfItem< nConfigItemBehavior >::ReadVal(), tConfItemLine::ReadVal(), nConfItemLine::ReadVal(), and st_LoadConfig().

bool tConfItemBase::printErrors = true [static]

if set, unknown settings are pointed out.

Definition at line 129 of file tConfiguration.h.

Referenced by LoadLine(), and st_LoadConfig().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:55:36 2008 for Armagetron Advanced by  doxygen 1.5.4