diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 12:23:13 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 12:23:13 +0000 |
commit | 4b8bad3d711f39db84f094edf83c5496a3f02cd6 (patch) | |
tree | bbaf654af3e82e67544ae17f07b7fbe7d02ce0ec /src/confpair.h | |
parent | 737b1aee54da9ff45a4fb6eb7e636eff9019128e (diff) | |
download | libbu++-4b8bad3d711f39db84f094edf83c5496a3f02cd6.tar.gz libbu++-4b8bad3d711f39db84f094edf83c5496a3f02cd6.tar.bz2 libbu++-4b8bad3d711f39db84f094edf83c5496a3f02cd6.tar.xz libbu++-4b8bad3d711f39db84f094edf83c5496a3f02cd6.zip |
Wow, craziness. Part way through working on the confpair system I got some
sudden insperation and completely redid Hash. Now everything but delete is
implemented, including typesafe iterators and more. It's really cool, and
everyone should check it out and start using it right away!
Diffstat (limited to '')
-rw-r--r-- | src/confpair.h | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/confpair.h b/src/confpair.h index 5be33c8..56eb06e 100644 --- a/src/confpair.h +++ b/src/confpair.h | |||
@@ -3,11 +3,14 @@ | |||
3 | 3 | ||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <string> | 5 | #include <string> |
6 | #include <sstream> | ||
7 | #include "confpairbase.h" | ||
8 | |||
6 | /** | 9 | /** |
7 | * | 10 | * |
8 | */ | 11 | */ |
9 | template<class T> | 12 | template<class T> |
10 | class ConfPair | 13 | class ConfPair : public ConfPairBase |
11 | { | 14 | { |
12 | public: | 15 | public: |
13 | ConfPair( const std::string &sName ) : | 16 | ConfPair( const std::string &sName ) : |
@@ -27,9 +30,52 @@ public: | |||
27 | return sName; | 30 | return sName; |
28 | } | 31 | } |
29 | 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 | |||
30 | private: | 45 | private: |
31 | std::string sName; | 46 | std::string sName; |
32 | T tValue; | 47 | T tValue; |
33 | }; | 48 | }; |
34 | 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 | |||
35 | #endif | 81 | #endif |