Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

expandlib-vartype-bool.h

Go to the documentation of this file.
00001 
00002 /* This file is part of Expandlib.
00003 
00004   Copyright (C) 2002 Jasper van de Gronde
00005 
00006   This software is provided 'as-is', without any express or implied
00007   warranty.  In no event will the authors be held liable for any damages
00008   arising from the use of this software.
00009 
00010   Permission is granted to anyone to use this software for any purpose,
00011   including commercial applications, and to alter it and redistribute it
00012   freely, subject to the following restrictions:
00013 
00014   1. The origin of this software must not be misrepresented; you must not
00015      claim that you wrote the original software. If you use this software
00016      in a product, an acknowledgment in the product documentation would be
00017      appreciated but is not required.
00018   2. Altered source versions must be plainly marked as such, and must not be
00019      misrepresented as being the original software.
00020   3. This notice may not be removed or altered from any source distribution.
00021 
00022   Jasper van de Gronde th.v.d.gronde@hccnet.nl
00023 
00024 */
00025 
00030 #ifndef EXPANDLIB_VARTYPE_BOOL_H_INCLUDED
00031 #define EXPANDLIB_VARTYPE_BOOL_H_INCLUDED
00032 
00033 #include "expandlib-vartype.h"
00034 
00035 namespace expander { // *** Start of namespace
00036 
00038 
00044     template<
00045         // Used for the expandable string (and the expanded string)
00046         class StringType = ::std::string,
00047         bool DefaultValue = false
00048         >
00049     class expvartype_bool : public expandvartype<StringType> {
00050     protected:
00051         bool val;
00052         const StringType TrueString;
00053         const StringType FalseString;
00054 
00055     public:
00056 
00058         expvartype_bool() : TrueString(_T("true")), FalseString(_T("false")) { val=DefaultValue; };
00059 
00061         expvartype_bool(const StringType & ts, const StringType & fs) : TrueString(ts), FalseString(fs) { val=DefaultValue; };
00062 
00064         expvartype_bool(const bool b) : TrueString(_T("true")), FalseString(_T("false")) { val=b; };
00065 
00067         expvartype_bool(const bool b, const StringType & ts, const StringType & fs) : TrueString(ts), FalseString(fs) { val=b; };
00068 
00070         expvartype_bool(const _TCHAR * cs) : TrueString(_T("true")), FalseString(_T("false"))
00071         {
00072             const StringType s(cs);
00073             SetValue(s);
00074         };
00075 
00077         expvartype_bool(const _TCHAR * cs, const StringType & ts, const StringType & fs) : TrueString(ts), FalseString(fs)
00078         {
00079             const StringType s(cs);
00080             SetValue(s);
00081         };
00082 
00084         expvartype_bool(const StringType s) : TrueString(_T("true")), FalseString(_T("false"))
00085         {
00086             SetValue(s);
00087         };
00088 
00090         expvartype_bool(const StringType s, const StringType & ts, const StringType & fs) : TrueString(ts), FalseString(fs)
00091         {
00092             SetValue(s);
00093         };
00094 
00095         virtual void AppendValue(StringType &dest) const { dest+=( val ? TrueString : FalseString ); };
00096 
00097         virtual void AppendValue(StringType &dest, const FParamVectorType &params, const FVarMapType &vars, ExpandResultsType &results) const { dest+=( val ? TrueString : FalseString ); };
00098 
00099         virtual void SetValue(const StringType &s) throw()
00100         {
00101             if ( s == _T("yes") || s == _T("true") || s == TrueString ) {
00102                 val=true;
00103             } else if ( s == _T("no") || s == _T("false") || s == FalseString ) {
00104                 val=false;
00105             } else {
00106                 val=DefaultValue;
00107             }
00108         };
00109 
00110         inline void operator=(const StringType &s)
00111         {
00112             if ( s == _T("yes") || s == _T("true") ) {
00113                 val=true;
00114             } else if ( s == _T("no") || s == _T("false") ) {
00115                 val=false;
00116             } else {
00117                 val=DefaultValue;
00118             }
00119         };
00120 
00122         inline bool& get_value() { return val; }
00123     };
00124 
00125 } // *** End of namespace
00126 
00127 #endif //EXPANDLIB_VARTYPE_BOOL_H_INCLUDED

Generated on Tue Feb 4 17:24:13 2003 for ExpandLib by doxygen1.3-rc2