Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
* Cleaned up getEnv and getCmdline methods.
Browse files Browse the repository at this point in the history
* Finished generalized accessor functions.
* This should be the last update for a few weeks - mid-terms and finals
  nipping at my ass.  If any severe bugs crop up, let me know.
  • Loading branch information
jaz147 committed Nov 2, 2000
1 parent 30dcab0 commit 8d5245e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,5 +1,11 @@
ChangeLog for varconf

Thu Nov 02 18:00:00 EST 2000 -- jaz <jaz147@psu.edu>
* Config.h: Added generalized accessor methods
* Config.cc: Implemented generalized accessor methods
* Config.cc: Finished getEnv clean-up.
* Config.cc: Finished getCmdline clean-up.

Mon Oct 23 16:10:38 EST 2000 -- jaz <jaz147@psu.edu>
* Config.cc: Removed Observer code.
* Config.cc: Converted callbacks to libsigc++.
Expand Down
5 changes: 0 additions & 5 deletions TODO
@@ -1,18 +1,13 @@
TODO for varconf

Major Tasks:
* Redo Config::getCmdline() and Config::getEnv() codex.
* Handle '--' arguments better
* Check validity of '-' arguments
* Unify configuration methods (ie: add section support to Config::getEnv())
+ Add delItem() and delSection() methods
* Unify error handling methods
* Convert file parser to lex/yacc
* Design and implement new Observer class
* Add overloaded operators for major functions
* Finish changing functions to general form (getItem to get, etc.)
* Document and arrange the source better.
* Submit the new interface to the mailing lists to recommend adoption.
* Write a proper testing program to verify functionality of features.

Minor Tasks:
Expand Down
19 changes: 7 additions & 12 deletions varconf/Config.cc
Expand Up @@ -92,34 +92,29 @@ bool Config::erase( const string& section, const string& key = "")
return false;
}

Variable Config::getItem( const string& section, const string& key)
Variable Config::get( const string& section, const string& key)
{
return ( m_conf[section])[key];
}

void Config::setItem( const string& section, const string& name,
const Variable item)
void Config::set( const string& section, const string& key,
const Variable item)
{
if ( name.empty()) {
if ( key.empty()) {
throw "Invalid configuration item!";
}
else {
string sec = section, nam = name;
string sec = section, nam = key;

clean( sec);
clean( nam);

( m_conf[sec])[nam] = item;

sig.emit();
sigv.emit( section, name);
sigv.emit( sec, nam);
}
} // Config::setItem()

bool Config::findItem( const string& section, const string& name)
{
return find( section, name);
}
} // Config::set()

bool Config::find( const string& section, const string& key = "")
{
Expand Down
30 changes: 23 additions & 7 deletions varconf/Config.h
Expand Up @@ -26,16 +26,32 @@ class Config {
static Config* inst();
// returns a pointer to the global configuration instance and
// initializes it if it does not already exist.

Variable getItem( const std::string& section, const std::string& key);

Variable get( const std::string& section, const std::string& key);
void set( const std::string& section, const std::string& key,
const Variable item);
bool erase( const std::string& section, const std::string& key = "");
bool find( const std::string& section, const std::string& key = "");
void clean( std::string& str);
// turns 'str' into a section name or key name compatible string.
// Config data manipulators - get a config key, set a config key, delete
// a config key or config section and find a config key or config section.

void setItem( const std::string& section, const std::string& name,
const Variable item);
bool findItem( const std::string& section, const std::string& name);
void clean( std::string& str);

Variable getItem( const std::string& section, const std::string& key)
{
return get( section, key);
}

void setItem( const std::string& section, const std::string& key,
const Variable item)
{
set( section, key, item);
}

bool findItem( const std::string& section, const std::string& key)
{
return find( section, key);
}

bool readFromFile( const std::string& filename);
// attempts to read a configuration file 'filename' and parse it. Returns
Expand Down

0 comments on commit 8d5245e

Please sign in to comment.