File: xmlrpcType.cpp

package info (click to toggle)
xmlrpc-c 1.60.05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,132 kB
  • sloc: ansic: 55,332; cpp: 13,541; sh: 3,321; makefile: 2,556; perl: 593; xml: 134
file content (270 lines) | stat: -rw-r--r-- 6,334 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <map>
#include <vector>

#include <xmlrpc-c/base.hpp>

#include "xmlrpcType.hpp"

using namespace std;



//=========================================================================
//  abstract class xmlrpcType
//=========================================================================
//  Instances of xmlrpcType know how generate code fragments for manipulating
//  a specific XML-RPC data type.

string
xmlrpcType::defaultParameterBaseName(unsigned int const position) const {

    ostringstream nameStream;

    nameStream << typeName() << position;

    return nameStream.str();
}



class rawXmlrpcType : public xmlrpcType {
public:
    rawXmlrpcType(string const& typeName) : xmlrpcType(typeName) {}
    
    virtual string
    parameterFragment(string const& baseName) const;

    virtual string
    inputConversionFragment(string const& baseName) const;

    virtual string
    returnTypeFragment() const;

    virtual string
    outputConversionFragment(string const& varName) const;
};



string
rawXmlrpcType::parameterFragment(string const& baseName) const {
    return "xmlrpc_c::value /*" + typeName() + "*/ " + baseName;
}



string
rawXmlrpcType::inputConversionFragment(string const& baseName) const {

    return baseName;
}



string
rawXmlrpcType::returnTypeFragment() const {
    return "xmlrpc_c::value /*" + typeName() + "*/";
}



string
rawXmlrpcType::outputConversionFragment(string const& varName) const {

    return varName;
}



class simpleXmlrpcType : public xmlrpcType {

    string mNativeType;
    string mMakerFunc;
    string mGetterFunc;

public:
    simpleXmlrpcType(string const& typeName,
                     string const& nativeType,
                     string const& makerFunc,
                     string const& getterFunc);

    virtual string
    parameterFragment(string const& baseName) const;

    virtual string
    inputConversionFragment(string const& baseName) const;

    virtual string
    returnTypeFragment() const;

    virtual string
    outputConversionFragment(string const& varName) const;
};



simpleXmlrpcType::simpleXmlrpcType(string const& typeName,
                                   string const& nativeType,
                                   string const& makerFunc,
                                   string const& getterFunc)
    : xmlrpcType(typeName),
      mNativeType(nativeType),
      mMakerFunc(makerFunc),
      mGetterFunc(getterFunc) {
}



string
simpleXmlrpcType::parameterFragment(string const& baseName) const {

    return mNativeType + " const " + baseName;
}



string
simpleXmlrpcType::inputConversionFragment(string const& baseName) const {

    return mMakerFunc + "(" + baseName + ")";
}



string
simpleXmlrpcType::returnTypeFragment() const {

    return mNativeType; 
}



string
simpleXmlrpcType::outputConversionFragment(string const& varName) const {
    return mMakerFunc + "(" + varName + ")";
}



class voidXmlrpcType : public xmlrpcType {
public:
    voidXmlrpcType() : xmlrpcType("void") {}
    
    virtual string
    parameterFragment(string const& baseName) const;

    virtual string
    inputConversionFragment(string const& baseName) const;

    virtual string
    returnTypeFragment() const;

    virtual string
    outputConversionFragment(string const& varName) const;
};



string
voidXmlrpcType::parameterFragment(string const&) const {

    throw domain_error("Can't handle functions with 'void' arguments'");
}



string
voidXmlrpcType::inputConversionFragment(string const&) const {

    throw domain_error("Can't handle functions with 'void' arguments'");
}



string
voidXmlrpcType::returnTypeFragment () const {

    return "void";
}



string
voidXmlrpcType::outputConversionFragment(string const&) const {
    return "/* Return value ignored. */";
}



static simpleXmlrpcType const intType    ("int", "int",
                                          "xmlrpc_c::value_int",
                                          "getInt");
static simpleXmlrpcType const boolType   ("bool", "bool",
                                          "xmlrpc_c::value_boolean",
                                          "getBool");
static simpleXmlrpcType const doubleType ("double", "double",
                                          "xmlrpc_c::value_double",
                                          "getDouble");
static simpleXmlrpcType const stringType ("string", "std::string",
                                          "xmlrpc_c::value_string",
                                          "getString");

static rawXmlrpcType const dateTimeType  ("dateTime");
static rawXmlrpcType const base64Type    ("base64");
static rawXmlrpcType const structType    ("struct");
static rawXmlrpcType const arrayType     ("array");

static voidXmlrpcType const voidType;



const xmlrpcType&
findXmlrpcType(string const& name) {
/*----------------------------------------------------------------------------
  Given the name of an XML-RPC data type, try to find a corresponding
  xmlrpcType object.
-----------------------------------------------------------------------------*/
    if (name == "int" || name == "i4")
        return intType;
    else if (name == "boolean")
        return boolType;
    else if (name == "double")
        return doubleType;
    else if (name == "string")
        return stringType;
    else if (name == "dateTime.iso8601")
        return dateTimeType;
    else if (name == "base64")
        return base64Type;
    else if (name == "struct")
        return structType;
    else if (name == "array")
        return arrayType;
    else if (name == "void")
        return voidType;
    else if (name == "INT")
        return intType;
    else if (name == "BOOLEAN")
        return boolType;
    else if (name == "DOUBLE")
        return doubleType;
    else if (name == "STRING")
        return stringType;
    else if (name == "DATETIME.ISO8601")
        return dateTimeType;
    else if (name == "BASE64")
        return base64Type;
    else if (name == "STRUCT")
        return structType;
    else if (name == "ARRAY")
        return arrayType;
    else if (name == "VOID")
        return voidType;
    else if (name == "NIL")
        return voidType;
    else
        throw domain_error("Unknown XML-RPC type name '" + name + "'");
}