1 #ifndef XPARAM_VALUE_SOURCE_IMP_H 2 #define XPARAM_VALUE_SOURCE_IMP_H 3 4 /* Copyright (C) 2001,2002,2003 Ronnie Maor and Michael Brand 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this software; see the file COPYING. If not, write to 18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 * 20 * As a special exception, the copyright holders give permission 21 * for additional uses of the text contained in its release of XPARAM. 22 * 23 * The exception is that, if you link the XPARAM library with other files 24 * to produce an executable, this does not by itself cause the 25 * resulting executable to be covered by the GNU General Public License. 26 * Your use of that executable is in no way restricted on account of 27 * linking the XPARAM library code into it. 28 * 29 * This exception does not however invalidate any other reasons why 30 * the executable file might be covered by the GNU General Public License. 31 * 32 * If you write modifications of your own for XPARAM, it is your choice 33 * whether to permit this exception to apply to your modifications. 34 * If you do not wish that, delete this exception notice. 35 */ 36 37 /* 38 * Implements the Val and PtrVal functions (and the helper classes they need) 39 */ 40 41 #include "xp_value_source.h" 42 #include "xp_value_management.h" 43 44 namespace xParam_internal { 45 46 class ValSource : public ValueSource { 47 public: ValSource(const Handle<Value> & val)48 ValSource(const Handle<Value>& val) : m_val(val) {} get_value(bool flexible)49 virtual Handle<Value> get_value(bool flexible) const { return m_val;} 50 51 private: 52 Handle<Value> m_val; 53 }; 54 55 // make_source - returns a Handle<ValueSource> from a Handle<Value> make_source(const Handle<Value> & val)56 inline Handle<ValueSource> make_source(const Handle<Value>& val) { 57 return Handle<ValueSource>(new ValSource(val)); 58 } 59 60 // Val function - returns a Handle<ValueSource> from an object 61 template<class T> Val(const T & val)62 Handle<ValueSource> Val(const T& val) { 63 return make_source(make_value_copy(val)); 64 } 65 Val(const char * c_string)66 inline Handle<ValueSource> Val(const char* c_string) { 67 return Val(std::string(c_string)); 68 } 69 70 /* 71 typedef const char* ConstCString; 72 73 inline Handle<ValueSource> Val(const ConstCString& c_string) { 74 return Val(std::string(c_string)); 75 } 76 77 typedef char* NonConstCString; 78 79 inline Handle<ValueSource> Val(const NonConstCString& c_string) { 80 return Val(std::string(c_string)); 81 } 82 */ 83 84 // PtrVal function - returns a Handle<ValueSource> from a pointer to an object 85 template<class T> PtrVal(const T * val_ptr)86 Handle<ValueSource> PtrVal(const T* val_ptr) 87 { 88 return make_source(make_value_copy_ptr(val_ptr)); 89 } 90 91 // ParseSource - parses a value from a given string 92 class ParseSource : public ValueSource { 93 public: ParseSource(const std::string & str)94 ParseSource(const std::string& str) : m_str(str) {} 95 virtual Handle<Value> get_value(bool flexible) const; 96 97 private: 98 std::string m_str; 99 }; 100 xParse(const std::string & str)101 inline Handle<ValueSource> xParse(const std::string& str) 102 { 103 return Handle<ValueSource>(new ParseSource(str)); 104 } 105 106 107 } // namespace xParam_internal 108 109 #endif // XPARAM_VALUE_SOURCE_IMP_H 110