diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
| commit | f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch) | |
| tree | 13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/old/confpair.h | |
| parent | 74d4c8cd27334fc7204d5a8773deb3d424565778 (diff) | |
| download | libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2 libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip | |
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a
unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/old/confpair.h')
| -rw-r--r-- | src/old/confpair.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/old/confpair.h b/src/old/confpair.h new file mode 100644 index 0000000..56eb06e --- /dev/null +++ b/src/old/confpair.h | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #ifndef CONF_PAIR_H | ||
| 2 | #define CONF_PAIR_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <string> | ||
| 6 | #include <sstream> | ||
| 7 | #include "confpairbase.h" | ||
| 8 | |||
| 9 | /** | ||
| 10 | * | ||
| 11 | */ | ||
| 12 | template<class T> | ||
| 13 | class ConfPair : public ConfPairBase | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | ConfPair( const std::string &sName ) : | ||
| 17 | sName( sName ) | ||
| 18 | { } | ||
| 19 | |||
| 20 | virtual ~ConfPair() | ||
| 21 | { } | ||
| 22 | |||
| 23 | T &value() | ||
| 24 | { | ||
| 25 | return tValue; | ||
| 26 | } | ||
| 27 | |||
| 28 | const std::string &name() | ||
| 29 | { | ||
| 30 | return sName; | ||
| 31 | } | ||
| 32 | |||
| 33 | virtual void setFromString( const std::string &sStr ) | ||
| 34 | { | ||
| 35 | std::stringstream(sStr) >> tValue; | ||
| 36 | } | ||
| 37 | |||
| 38 | virtual std::string getAsString() | ||
| 39 | { | ||
| 40 | std::stringstream tmp; | ||
| 41 | tmp << tValue; | ||
| 42 | return tmp.str(); | ||
| 43 | } | ||
| 44 | |||
| 45 | private: | ||
| 46 | std::string sName; | ||
| 47 | T tValue; | ||
| 48 | }; | ||
| 49 | |||
| 50 | template<> | ||
| 51 | void ConfPair<std::string>::setFromString( const std::string &sStr ) | ||
| 52 | { | ||
| 53 | tValue = sStr; | ||
| 54 | } | ||
| 55 | |||
| 56 | template<> | ||
| 57 | std::string ConfPair<std::string>::getAsString() | ||
| 58 | { | ||
| 59 | return tValue; | ||
| 60 | } | ||
| 61 | |||
| 62 | template<> | ||
| 63 | void ConfPair<bool>::setFromString( const std::string &sStr ) | ||
| 64 | { | ||
| 65 | if( !strcasecmp( sStr.c_str(), "true" ) || | ||
| 66 | !strcasecmp( sStr.c_str(), "yes" ) || | ||
| 67 | !strcasecmp( sStr.c_str(), "on" ) ) | ||
| 68 | tValue = true; | ||
| 69 | else | ||
| 70 | tValue = false; | ||
| 71 | } | ||
| 72 | |||
| 73 | template<> | ||
| 74 | std::string ConfPair<bool>::getAsString() | ||
| 75 | { | ||
| 76 | if( tValue == true ) | ||
| 77 | return "True"; | ||
| 78 | return "False"; | ||
| 79 | } | ||
| 80 | |||
| 81 | #endif | ||
