initial load of upstream version 1.06.32
[xmlrpc-c] / tools / xml-rpc-api2cpp / XmlRpcClass.cpp
1 #include <iostream>
2 #include <stdexcept>
3 #include <vector>
4
5 using namespace std;
6
7 #include "xmlrpc-c/oldcppwrapper.hpp"
8
9 #include "DataType.hpp"
10 #include "XmlRpcFunction.hpp"
11 #include "XmlRpcClass.hpp"
12
13
14 //=========================================================================
15 //  XmlRpcClass
16 //=========================================================================
17 //  This class stores information about a proxy class, and knows how to
18 //  generate code.
19
20 XmlRpcClass::XmlRpcClass (string class_name)
21     : mClassName(class_name)
22 {
23 }
24
25 XmlRpcClass::XmlRpcClass (const XmlRpcClass& c)
26     : mClassName(c.mClassName),
27       mFunctions(c.mFunctions)
28 {
29 }
30
31 XmlRpcClass& XmlRpcClass::operator= (const XmlRpcClass& c)
32 {
33     if (this == &c)
34         return *this;
35     mClassName = c.mClassName;
36     mFunctions = c.mFunctions;
37     return *this;
38 }
39
40 void XmlRpcClass::addFunction (const XmlRpcFunction& function)
41 {
42     mFunctions.push_back(function);
43 }
44
45 void XmlRpcClass::printDeclaration (ostream&)
46 {
47     cout << "class " << mClassName << " {" << endl;
48     cout << "    XmlRpcClient mClient;" << endl;
49     cout << endl;
50     cout << "public:" << endl;
51     cout << "    " << mClassName << " (const XmlRpcClient& client)" << endl;
52     cout << "        : mClient(client) {}" << endl;
53     cout << "    " << mClassName << " (const string& server_url)" << endl;
54     cout << "        : mClient(XmlRpcClient(server_url)) {}" << endl;
55     cout << "    " << mClassName << " (const " << mClassName << "& o)" << endl;
56     cout << "        : mClient(o.mClient) {}" << endl;
57     cout << endl;
58     cout << "    " << mClassName << "& operator= (const "
59          << mClassName << "& o) {" << endl;
60     cout << "        if (this != &o) mClient = o.mClient;" << endl;
61     cout << "        return *this;" << endl;
62     cout << "    }" << endl;
63
64     vector<XmlRpcFunction>::iterator f;
65     for (f = mFunctions.begin(); f < mFunctions.end(); ++f) {
66         f->printDeclarations(cout);
67     }
68
69     cout << "};" << endl;    
70 }
71
72 void XmlRpcClass::printDefinition (ostream&)
73 {
74     vector<XmlRpcFunction>::iterator f;
75     for (f = mFunctions.begin(); f < mFunctions.end(); ++f) {
76         f->printDefinitions(cout, mClassName);
77     }
78 }