Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / DynAny_Test / analyzer.cpp
blob6fdec95c44fc3caa6d2481904d7294f2a7b88b67
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file analyzer.cpp
7 * This file contains a DynAny analyzer that dumps the contents of a DynAny
8 * to the logging.
10 * @author Johnny Willemsen (jwillemsen@remedy.nl)
12 //=============================================================================
14 #include "analyzer.h"
16 #include "tao/DynamicAny/DynCommon.h"
17 #include "tao/DynamicAny/DynAnyFactory.h"
19 #define CASEE(type,CT,str) case CORBA::tk_##type: {\
20 CORBA::CT b = da->get_##type(); \
21 tab (level_); \
22 if (debug_) \
23 ACE_DEBUG ((LM_DEBUG, str , b)); \
24 } break;
26 #define CASEBS(type,CT,str) case CORBA::tk_##type: \
28 CORBA::CT##Seq_var seq = da->get_##type##_seq (); \
29 ++level_; \
30 CORBA::ULong len = seq->length (); \
31 tab (level_); \
32 if (debug_) \
33 { \
34 ACE_DEBUG ((LM_DEBUG, "length = %u\n", len)); \
35 } \
36 for (CORBA::ULong i = 0; i < len; ++i) \
37 { \
38 CORBA::CT b = seq[i]; \
39 tab (level_); \
40 if (debug_) \
41 { \
42 ACE_DEBUG ((LM_DEBUG, "[%d]\n", i)); \
43 ACE_DEBUG ((LM_DEBUG, str, b)); \
44 } \
45 } \
46 --level_; \
47 } \
48 break;
50 DynAnyAnalyzer::DynAnyAnalyzer (CORBA::ORB_ptr orb,
51 DynamicAny::DynAnyFactory_ptr dynany_factory,
52 int debug)
53 : orb_ (CORBA::ORB::_duplicate (orb)),
54 dynany_factory_ (DynamicAny::DynAnyFactory::_duplicate (dynany_factory)),
55 level_ (0),
56 debug_ (debug)
60 void DynAnyAnalyzer::tab (int t)
62 if (debug_)
64 for (int i = 0 ; i < t ; ++i)
66 ACE_DEBUG ((LM_DEBUG, "\t"));
71 DynAnyAnalyzer::~DynAnyAnalyzer ()
75 void DynAnyAnalyzer::resetTab ()
77 level_ = 0;
80 void DynAnyAnalyzer::analyze (DynamicAny::DynAny_ptr da)
82 CORBA::TypeCode_var tc = da->type ();
84 CORBA::TCKind kind = tc->kind ();
86 CORBA::TypeCode_var dup = CORBA::TypeCode::_duplicate (tc.in ());
88 // strip aliases
89 while (kind == CORBA::tk_alias)
91 dup = dup->content_type ();
93 kind = dup->kind ();
96 switch (kind)
98 case CORBA::tk_struct:
100 DynamicAny::DynStruct_var ds
101 = DynamicAny::DynStruct::_narrow (da);
103 tab (level_);
105 if (debug_)
107 ACE_DEBUG ((LM_DEBUG,
108 "STRUCT\n"));
111 if (da->seek (0) )
113 level_++;
117 DynamicAny::DynAny_var cc =
118 ds->current_component ();
120 DynamicAny::FieldName_var fn =
121 ds->current_member_name ();
123 tab(level_);
125 if (debug_)
127 ACE_DEBUG ((LM_DEBUG,
128 "Member = %C\n", fn.in ()));
131 if (!CORBA::is_nil (cc.in ()))
133 this->analyze (cc.in ());
136 } while (da->next ());
138 level_--;
141 break; // end tk_struct
143 case CORBA::tk_sequence:
145 if (TAO_DynCommon::is_basic_type_seq (tc.in ()))
147 this->analyze_basic_seq (dup.in (), da);
149 else
151 DynamicAny::DynSequence_var ds =
152 DynamicAny::DynSequence::_narrow (da);
154 int i = 0;
155 tab(level_);
157 if (debug_)
159 ACE_DEBUG ((LM_DEBUG,
160 "SEQUENCE\n"));
163 if (ds->seek (0UL))
165 level_++;
169 tab(level_);
171 if (debug_)
172 ACE_DEBUG ((LM_DEBUG,
173 "[%d]\n", i));
175 DynamicAny::DynAny_var cc (ds->current_component ());
177 if (!CORBA::is_nil (cc.in ()))
179 analyze (cc.in ());
182 i++;
183 } while (da->next ());
185 level_--;
189 break; // end tk_sequence
191 case CORBA::tk_array:
193 tab (level_);
195 if (debug_)
197 ACE_DEBUG ((LM_DEBUG,
198 "ARRAY\n"));
201 level_++;
203 CORBA::ULong const len =
204 dup->length ();
206 for (CORBA::ULong i = 0 ; i < len; ++i)
208 tab (level_);
210 if (debug_)
212 ACE_DEBUG ((LM_DEBUG, "[%d]\n", i));
215 DynamicAny::DynAny_var cc = da->current_component();
217 if (!CORBA::is_nil (cc.in ()))
219 analyze (cc.in ());
222 da->next ();
224 level_--;
226 break;
228 case CORBA::tk_union:
230 DynamicAny::DynUnion_var value =
231 DynamicAny::DynUnion::_narrow (da);
233 if (!value->has_no_active_member ())
235 DynamicAny::DynAny_var disc = value->member ();
237 if (!CORBA::is_nil (disc.in ()))
239 this->analyze (disc.in ());
243 break;
245 case CORBA::tk_any:
247 DynamicAny::DynAny_var dynany;
248 CORBA::Any_var any = da->get_any ();
250 dynany =
251 dynany_factory_->create_dyn_any (any.in ());
253 if (!CORBA::is_nil (dynany.in ()))
255 this->analyze (dynany.in ());
258 dynany->destroy ();
260 break;
262 case CORBA::tk_enum:
264 DynamicAny::DynEnum_var value =
265 DynamicAny::DynEnum::_narrow (da);
267 CORBA::String_var s = value->get_as_string ();
268 tab (level_);
270 if (debug_)
272 ACE_DEBUG ((LM_DEBUG, " Value (enum) = %C\n", s.in()));
275 break;
277 CASEE (boolean, Boolean, " Value (bool) = %d\n");
278 CASEE (short, Short, " Value (short) = %d\n");
279 CASEE (ushort, UShort, " Value (ushort) = %u\n");
280 CASEE (long, Long, " Value (long) = %d\n");
281 CASEE (ulong, ULong, " Value (ulong) = %u\n");
282 CASEE (longlong, LongLong, " Value (longlong) %Ld\n");
283 CASEE (ulonglong, ULongLong, " Value (ulonglong) %Lu\n");
284 CASEE (char, Char, " Value (char) = %c\n");
285 CASEE (float, Float, " Value (float) = %f\n");
286 CASEE (double, Double, " Value (double) = %f\n");
287 CASEE (octet, Octet, " Value (octet) = %c\n");
289 case CORBA::tk_string:
291 CORBA::String_var b (da->get_string ());
292 tab (level_);
294 if (debug_)
296 ACE_DEBUG ((LM_DEBUG, " Value (string) = %C\n", b.in ()));
299 break;
301 case CORBA::tk_TypeCode:
303 tab (level_);
305 if (debug_)
307 CORBA::TCKind const kind =
308 da->get_typecode ()->kind ();
310 ACE_DEBUG ((LM_DEBUG,
311 " Value (TypeCode) = %d\n",
312 static_cast<int> (kind)));
315 break;
317 default:
319 tab (level_);
321 if (debug_)
323 CORBA::TCKind const kind =
324 tc->kind ();
326 ACE_DEBUG ((LM_DEBUG,
327 " unhandled typecode = %d\n",
328 static_cast<int> (kind)));
331 break;
334 if (debug_)
336 ACE_DEBUG ((LM_DEBUG, "\n"));
340 void
341 DynAnyAnalyzer::analyze_basic_seq (CORBA::TypeCode_ptr tc,
342 DynamicAny::DynAny_ptr da)
344 CORBA::TypeCode_var ct = tc->content_type ();
345 CORBA::TCKind tk = ct->kind ();
347 tab (level_);
349 if (debug_)
351 ACE_DEBUG ((LM_DEBUG,
352 "BASIC TYPE SEQUENCE\n"));
355 switch (tk)
357 CASEBS (boolean, Boolean, " Value (bool) = %d\n");
358 CASEBS (octet, Octet, " Value (octet) = %c\n");
359 CASEBS (char, Char, " Value (char) = %c\n");
360 CASEBS (wchar, WChar, " Value (wchar) = %u\n");
361 CASEBS (short, Short, " Value (short) = %d\n");
362 CASEBS (ushort, UShort, " Value (ushort) = %u\n");
363 CASEBS (long, Long, " Value (long) = %d\n");
364 CASEBS (ulong, ULong, " Value (ulong) = %u\n");
365 CASEBS (longlong, LongLong, " Value (longlong) = %Ld\n");
366 CASEBS (ulonglong, ULongLong, " Value (ulonglong) = %Lu\n");
367 CASEBS (float, Float, " Value (float) = %f\n");
368 CASEBS (double, Double, " Value (double) = %f\n");
369 case CORBA::tk_longdouble:
370 default:
371 tab (level_);
373 if (debug_)
375 ACE_DEBUG ((LM_DEBUG,
376 " unhandled typecode = %d\n",
377 static_cast<int> (tk)));
380 break;