Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / OBV / Supports / Supports_Test_impl.cpp
blob11b9d4d4795c7e5b9a1699c32a42f969edfc4ac5
1 // FUZZ: disable check_for_streams_include
3 #include "Supports_Test_impl.h"
5 #include "ace/streams.h"
7 /* vt_graph_impl */
9 vt_graph_impl::vt_graph_impl ()
13 // Creates a vt_graph_impl with the given number of nodes. There will be one
14 // root node and the rest will be children of it.
15 vt_graph_impl::vt_graph_impl (int num_nodes)
17 nodes_ ().length (0);
18 add_node ("ROOT");
19 for (int i = 1; i < num_nodes; i++)
21 add_node ("CHILD");
22 nodes_ ()[0]->add_edge (nodes_ ()[i]);
26 // Get the number of nodes in the vt_graph.
27 CORBA::Long vt_graph_impl::size ()
29 return nodes_ ().length ();
32 // Add a node to the graph with no edges.
33 void
34 vt_graph_impl::add_node (const char * name)
36 Supports_Test::Node * new_node = 0;
37 ACE_NEW (new_node, node_impl (name));
38 nodes_ ().length (nodes_ ().length () + 1);
39 nodes_ ()[nodes_ ().length () - 1] = new_node;
42 // Print out information about each node.
43 void
44 vt_graph_impl::print ()
46 ACE_DEBUG ((LM_DEBUG,
47 "Printing graph data...\n"));
49 ACE_DEBUG ((LM_DEBUG,
50 "Number of nodes: [%d]\n", nodes_ ().length ()));
52 for (size_t i = 0; i < nodes_ ().length (); i++)
53 nodes_ ()[i]->print ();
57 /* vt_graph_init_impl - factory operations */
59 Supports_Test::vt_graph *
60 vt_graph_init_impl::create ()
62 vt_graph_impl * ret_val = 0;
63 ACE_NEW_RETURN (ret_val, vt_graph_impl, 0);
64 return ret_val;
67 CORBA::ValueBase *
68 vt_graph_init_impl::create_for_unmarshal ()
70 vt_graph_impl * ret_val = 0;
71 ACE_NEW_RETURN (ret_val, vt_graph_impl, 0);
72 return ret_val;
76 /* test_impl */
78 test_impl::test_impl (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb))
82 test_impl::~test_impl ()
86 void
87 test_impl::pass_obj_graph_in (
88 Supports_Test::graph * graph_param)
90 ACE_ASSERT (graph_param->size () == 3);
91 graph_param->add_node ("NEW1");
92 ACE_ASSERT (graph_param->size () == 4);
95 void
96 test_impl::pass_vt_graph_in (
97 Supports_Test::vt_graph * vt_graph_param)
99 ACE_ASSERT (vt_graph_param->size () == 3);
100 vt_graph_param->add_node ("NEW1");
101 ACE_ASSERT (vt_graph_param->size () == 4);
104 void
105 test_impl::pass_obj_graph_out (
106 Supports_Test::graph_out graph_param)
108 vt_graph_impl * the_vt_graph = 0;
109 ACE_NEW (the_vt_graph, vt_graph_impl (4));
110 graph_param = the_vt_graph->_this ();
112 ACE_ASSERT (graph_param->size () == 4);
113 graph_param->add_node ("NEW1");
114 ACE_ASSERT (graph_param->size () == 5);
117 void
118 test_impl::pass_vt_graph_out (
119 Supports_Test::vt_graph_out vt_graph_param)
121 vt_graph_impl * the_vt_graph = 0;
122 ACE_NEW (the_vt_graph, vt_graph_impl (4));
123 vt_graph_param = the_vt_graph;
125 ACE_ASSERT (vt_graph_param->size () == 4);
126 vt_graph_param->add_node ("NEW1");
127 ACE_ASSERT (vt_graph_param->size () == 5);
130 void
131 test_impl::pass_obj_graph_inout (
132 Supports_Test::graph * &graph_param)
134 ACE_ASSERT (graph_param->size () == 6);
135 graph_param->add_node ("NEW3");
136 ACE_ASSERT (graph_param->size () == 7);
139 void
140 test_impl::pass_vt_graph_inout (
141 Supports_Test::vt_graph * &vt_graph_param)
143 ACE_ASSERT (vt_graph_param->size () == 6);
144 vt_graph_param->add_node ("NEW3");
145 ACE_ASSERT (vt_graph_param->size () == 7);
148 void
149 test_impl::start ()
153 void
154 test_impl::finish ()
156 this->orb_->shutdown (false);
160 /* node_impl */
162 node_impl::node_impl ()
166 // Initialize state.
167 node_impl::node_impl (const char * name)
169 name_ (name);
170 weight_ (0);
171 degree_ (0);
172 neighbors_ ().length (0);
175 // Add an edge from this node to neighbor.
176 void
177 node_impl::add_edge (Supports_Test::Node * neighbor)
179 degree_ (degree_ () + 1);
180 neighbors_ ().length (neighbors_ ().length () + 1);
181 neighbors_ ()[neighbors_ ().length () - 1] = neighbor;
182 neighbor->_add_ref ();
185 // Remove the edge from this node to neighbor.
186 void
187 node_impl::remove_edge (Supports_Test::Node * neighbor)
189 for (unsigned int i = 0; i < neighbors_ ().length (); i++)
190 if (neighbors_ ()[i] == neighbor)
192 neighbors_ ()[i] = neighbors_ ()[neighbors_ ().length () - 1];
193 neighbors_ ().length (neighbors_ ().length () - 1);
194 neighbor->_remove_ref ();
198 void
199 node_impl::change_weight (CORBA::Long new_weight)
201 weight_ (new_weight);
204 void
205 node_impl::print ()
207 cout << " Name: " << name_ () << endl;
208 cout << " Weight: " << weight_ () << endl;
209 cout << " Degree: " << degree_ () << endl;
210 cout << " Neighbors: " << endl;
211 for (size_t i = 0; i < neighbors_ ().length (); i++)
212 cout << " " << neighbors_ ()[i]->name_ () << endl;
215 /* node_init_impl - factory operations */
217 Supports_Test::Node *
218 node_init_impl::create ()
220 node_impl * ret_val = 0;
221 ACE_NEW_RETURN (ret_val, node_impl, 0);
222 return ret_val;
225 CORBA::ValueBase *
226 node_init_impl::create_for_unmarshal ()
228 node_impl * ret_val = 0;
229 ACE_NEW_RETURN (ret_val, node_impl, 0);
230 return ret_val;