Genivia Home Documentation
graph.cpp Source File

updated Fri Aug 16 2024 by Robert van Engelen
 
graph.cpp
Go to the documentation of this file.
1 
23 /*
24 --------------------------------------------------------------------------------
25 gSOAP XML Web services tools
26 Copyright (C) 2000-2015, Robert van Engelen, Genivia, Inc. All Rights Reserved.
27 This software is released under one of the following two licenses:
28 GPL.
29 --------------------------------------------------------------------------------
30 GPL license.
31 
32 This program is free software; you can redistribute it and/or modify it under
33 the terms of the GNU General Public License as published by the Free Software
34 Foundation; either version 2 of the License, or (at your option) any later
35 version.
36 
37 This program is distributed in the hope that it will be useful, but WITHOUT ANY
38 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
39 PARTICULAR PURPOSE. See the GNU General Public License for more details.
40 
41 You should have received a copy of the GNU General Public License along with
42 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
43 Place, Suite 330, Boston, MA 02111-1307 USA
44 
45 Author contact information:
46 engelen@genivia.com / engelen@acm.org
47 --------------------------------------------------------------------------------
48 A commercial use license is available from Genivia, Inc., contact@genivia.com
49 --------------------------------------------------------------------------------
50 */
51 
52 int main();
53 
54 // include all gSOAP header files:
55 #include "graphH.h"
56 #include "g.nsmap"
57 
59 static struct Namespace nosoap_nsmap[] =
60 {
61  {"SOAP-ENV", NULL, NULL, NULL},
62  {"SOAP-ENC", NULL, NULL, NULL},
63  {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
64  {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
65  {"g", "urn:graph", NULL, NULL},
66  {NULL, NULL, NULL, NULL}
67 };
68 
70 static struct Namespace soap11_nsmap[] =
71 {
72  {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
73  {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL},
74  {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
75  {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
76  {"g", "urn:graph", NULL, NULL},
77  {NULL, NULL, NULL, NULL}
78 };
79 
81 static struct Namespace soap12_nsmap[] =
82 {
83  {"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", NULL},
84  {"SOAP-ENC", "http://www.w3.org/2003/05/soap-encoding", "http://schemas.xmlsoap.org/soap/encoding/", NULL},
85  {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
86  {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
87  {"g", "urn:graph", NULL, NULL},
88  {NULL, NULL, NULL, NULL}
89 };
90 
91 int main()
92 {
93  struct soap *ctx = soap_new1(SOAP_XML_INDENT);
94 
95  soap_set_namespaces(ctx, nosoap_nsmap);
96 
97  // a tree:
98  Graph tree;
99  // with 5 branches:
100  for (int i = 0; i < 4; ++i)
101  {
102  Graph *branch = soap_new_Graph(ctx);
103  tree.edges.push_back(branch);
104  // each branch has a couple of leaves:
105  for (int j = 0; j < i; ++j)
106  branch->edges.push_back(soap_new_Graph(ctx));
107  }
108 
109  std::cout << "**** XML TREE FROM C++ TREE ****" << std::endl;
110  soap_write_Graph(ctx, &tree);
111  std::cout << std::endl << std::endl;
112 
113  std::cout << "**** XML TREE FROM C++ DIGRAPH ****" << std::endl;
114  tree.edges[0] = tree.edges[1]; // first pair of edges point to shared node
115  tree.edges[2] = tree.edges[3]; // second pair of edges point to shared node
116  soap_write_Graph(ctx, &tree);
117  std::cout << std::endl << std::endl;
118 
119  std::cout << "**** XML ID-REF DIGRAPH FROM C++ DIGRAPH ****" << std::endl;
120  soap_set_omode(ctx, SOAP_XML_GRAPH);
121  soap_write_Graph(ctx, &tree);
122  std::cout << std::endl << std::endl;
123  soap_clr_omode(ctx, SOAP_XML_GRAPH);
124 
125  std::cout << "**** XML ID-REF DIGRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
126  tree.edges[0]->edges = tree.edges; // create cycle
127  soap_set_omode(ctx, SOAP_XML_GRAPH);
128  soap_write_Graph(ctx, &tree);
129  std::cout << std::endl << std::endl;
130  soap_clr_omode(ctx, SOAP_XML_GRAPH);
131 
132  std::cout << "**** XML TREE (PRUNED CYCLIC BRANCHES) FROM C++ CYCLIC GRAPH ****" << std::endl;
133  soap_set_omode(ctx, SOAP_XML_TREE);
134  soap_write_Graph(ctx, &tree);
135  std::cout << std::endl << std::endl;
136  soap_clr_omode(ctx, SOAP_XML_TREE);
137 
138  std::cout << "**** SOAP 1.1 ENCODED GRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
139  soap_set_namespaces(ctx, soap11_nsmap);
140  soap_set_version(ctx, 1); // enable SOAP 1.1
141  ctx->encodingStyle = ""; // encoded
142  soap_write_Graph(ctx, &tree);
143  std::cout << std::endl << std::endl;
144 
145  std::cout << "**** SOAP 1.2 ENCODED GRAPH FROM C++ CYCLIC GRAPH ****" << std::endl;
146  soap_set_namespaces(ctx, soap12_nsmap);
147  soap_set_version(ctx, 2); // enable SOAP 1.2
148  ctx->encodingStyle = ""; // encoded
149  soap_write_Graph(ctx, &tree);
150  std::cout << std::endl << std::endl;
151 
152  soap_destroy(ctx); // delete objects
153  soap_end(ctx); // free temp data
154  soap_free(ctx); // release context
155 
156  return 0;
157 }
158 
static struct Namespace soap11_nsmap[]
Namespace mapping table for SOAP 1.1.
Definition: graph.cpp:70
static struct Namespace nosoap_nsmap[]
Namespace mapping table for non-SOAP use.
Definition: graph.cpp:59
static struct Namespace soap12_nsmap[]
Namespace mapping table for SOAP 1.2.
Definition: graph.cpp:81
int main()
Definition: graph.cpp:91