00001 /************************************************************************** 00002 ulxr_valueparse_base.cpp - parse rpc primitive values 00003 ------------------- 00004 begin : Fri Jan 09 2004 00005 copyright : (C) 2002-2007 by Ewald Arnold 00006 email : ulxmlrpcpp@ewald-arnold.de 00007 00008 $Id: ulxr_valueparse_base.cpp 940 2006-12-30 18:22:05Z ewald-arnold $ 00009 00010 ***************************************************************************/ 00011 00012 /************************************************************************** 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU Lesser General Public License as 00016 * published by the Free Software Foundation; either version 2 of the License, 00017 * or (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 ***************************************************************************/ 00029 00030 //#define ULXR_DEBUG_OUTPUT 00031 00032 #define ULXR_NEED_EXPORTS 00033 #include <ulxmlrpcpp/ulxmlrpcpp.h> 00034 00035 #include <ulxmlrpcpp/ulxr_valueparse_base.h> 00036 00037 00038 namespace ulxr { 00039 00040 00041 ULXR_API_IMPL0 ValueParserBase::~ValueParserBase() 00042 { 00043 } 00044 00045 00046 ULXR_API_IMPL(Value) ValueParserBase::getValue() const 00047 { 00048 ULXR_TRACE(ULXR_PCHAR("ValueParserBase::getValue()")); 00049 00050 // if (getTopState()->getState() != eNone) 00051 // cerr << ulxr_i18n("########## abnormal program behaviour: getTopState()->getState() != eNone: ") 00052 // << getTopState()->getState() 00053 // << endl; 00054 00055 Value *v = getTopValueState()->getValue(); 00056 if (v != 0) 00057 return *v; 00058 else 00059 return Value(); // return ulxr::Void() 00060 } 00061 00062 00064 // 00065 00066 ULXR_API_IMPL0 ValueParserBase::ValueState::ValueState (unsigned st) 00067 : XmlParserBase::ParserState(st), 00068 value (0) 00069 { 00070 } 00071 00072 00073 ULXR_API_IMPL(void) ValueParserBase::ValueState::takeValue(Value *val) 00074 { 00075 ULXR_TRACE(ULXR_PCHAR("ValueParserBase::ValueState::takeValue(Value *)")); 00076 value = val; 00077 } 00078 00079 00080 ULXR_API_IMPL(CppString) ValueParserBase::ValueState::getStateName() const 00081 { 00082 switch (getParserState()) 00083 { 00084 case XmlParserBase::eNone : return ULXR_PCHAR("eNone"); 00085 case ValueParserBase::eValue : return ULXR_PCHAR("eValue"); 00086 case ValueParserBase::eArray : return ULXR_PCHAR("eArray"); 00087 case ValueParserBase::eData : return ULXR_PCHAR("eData"); 00088 case ValueParserBase::eStruct : return ULXR_PCHAR("eStruct"); 00089 case ValueParserBase::eMember : return ULXR_PCHAR("eMember"); 00090 case ValueParserBase::eName : return ULXR_PCHAR("eName"); 00091 case ValueParserBase::eBoolean: return ULXR_PCHAR("eBoolean"); 00092 case ValueParserBase::eInt : return ULXR_PCHAR("eInt"); 00093 case ValueParserBase::eI4 : return ULXR_PCHAR("eI4"); 00094 case ValueParserBase::eDouble : return ULXR_PCHAR("eDouble"); 00095 case ValueParserBase::eString : return ULXR_PCHAR("eString"); 00096 case ValueParserBase::eBase64 : return ULXR_PCHAR("eBase64"); 00097 case ValueParserBase::eDate : return ULXR_PCHAR("eDate"); 00098 00099 case ValueParserBase::eValueParserLast: return ULXR_PCHAR("eValueParserLast"); 00100 } 00101 00102 return ULXR_PCHAR("eUnknown"); 00103 } 00104 00105 00106 ULXR_API_IMPL(void) ValueParserBase::ValueState::takeName(const CppString & /* name */ ) 00107 { 00108 } 00109 00110 00111 ULXR_API_IMPL(CppString) ValueParserBase::ValueState::getName() const 00112 { 00113 return name; 00114 } 00115 00116 00117 ULXR_API_IMPL(void) ValueParserBase::ValueState::setName(const CppString &nm) 00118 { 00119 name = nm; 00120 } 00121 00122 00123 ULXR_API_IMPL(Value*) ValueParserBase::ValueState::getValue() const 00124 { 00125 return value; 00126 } 00127 00128 00130 // 00131 00132 00133 ULXR_API_IMPL0 ValueParserBase::MemberState::MemberState(unsigned st, Value *val) 00134 : ValueState(st), 00135 mem_val(0) 00136 { 00137 value = val; 00138 } 00139 00140 00141 ULXR_API_IMPL(void) ValueParserBase::MemberState::takeValue(Value *v) 00142 { 00143 ULXR_TRACE(ULXR_PCHAR("ValueParserBase::MemberState::takeValue(Value *)")); 00144 if (getName().length() != 0) // wait for name, maybe second tag 00145 { 00146 value->getStruct()->addMember(getName(), *v); 00147 delete v; 00148 } 00149 else 00150 mem_val = v; 00151 } 00152 00153 00154 ULXR_API_IMPL(void) ValueParserBase::MemberState::takeName(const CppString &n) 00155 { 00156 if (mem_val != 0) 00157 { 00158 value->getStruct()->addMember(n, *mem_val); 00159 delete mem_val; 00160 mem_val = 0; 00161 } 00162 else 00163 setName(n); 00164 } 00165 00166 00168 // 00169 00170 ULXR_API_IMPL0 ValueParserBase::ArrayState::ArrayState(unsigned st) 00171 : ValueState(st) 00172 { 00173 } 00174 00175 00176 ULXR_API_IMPL(void) ValueParserBase::ArrayState::takeValue(Value *v) 00177 { 00178 ULXR_TRACE(ULXR_PCHAR("ValueParserBase::ArrayState::takeValue(Value *)")); 00179 if (value == 0) 00180 value = new Value(Array()); 00181 00182 value->getArray()->addItem(*v); 00183 delete v; 00184 } 00185 00186 00187 } // namespace ulxr 00188