Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_interface / tie_sh.cpp
blobe28fc23849241ee61eb5eece352110aa5914966e
2 //=============================================================================
3 /**
4 * @file tie_sh.cpp
6 * Visitor generating code for TIE class for an Interface in the header
7 * file.
9 * @author Aniruddha Gokhale
11 //=============================================================================
13 #include "interface.h"
15 be_visitor_interface_tie_sh::be_visitor_interface_tie_sh (
16 be_visitor_context *ctx)
17 : be_visitor_interface (ctx)
21 be_visitor_interface_tie_sh::~be_visitor_interface_tie_sh ()
25 int
26 be_visitor_interface_tie_sh::visit_interface (be_interface *node)
28 if (node->imported () || node->is_abstract ())
30 return 0;
33 static char namebuf [NAMEBUFSIZE];
34 static char tiename [NAMEBUFSIZE];
36 ACE_OS::memset (namebuf,
37 '\0',
38 NAMEBUFSIZE);
39 ACE_OS::memset (tiename,
40 '\0',
41 NAMEBUFSIZE);
43 TAO_OutStream *os = this->ctx_->stream ();
45 // Generate the skeleton class name which will be used to determine the TIE
46 // class name.
48 // We shall have a POA_ prefix only if we are at the topmost level.
49 if (node->is_nested ())
51 ACE_OS::sprintf (namebuf,
52 "%s",
53 node->local_name ());
54 ACE_OS::sprintf (tiename,
55 "%s_tie",
56 node->local_name ());
58 else
60 // We are outermost.
61 ACE_OS::sprintf (namebuf,
62 "POA_%s",
63 node->local_name ());
64 ACE_OS::sprintf (tiename,
65 "POA_%s_tie",
66 node->local_name ());
69 // Now generate the class definition.
70 TAO_INSERT_COMMENT (os);
72 *os << "// TIE class: Refer to CORBA v2.2, Section 20.34.4" << be_nl;
73 *os << "template <class T>" << be_nl;
74 *os << "class " << " " << tiename << " : public " << namebuf << be_nl;
75 *os << "{" << be_nl
76 << "public:" << be_idt_nl
77 << "/// the T& ctor" << be_nl
78 << tiename << " (T &t);" << be_nl
79 << "/// ctor taking a POA" << be_nl
80 << tiename << " (T &t, PortableServer::POA_ptr poa);" << be_nl
81 << "/// ctor taking pointer and an ownership flag" << be_nl
82 << tiename << " (T *tp, ::CORBA::Boolean release = true);" << be_nl
83 << "/// ctor with T*, ownership flag and a POA" << be_nl
84 << tiename << " (" << be_idt << be_idt_nl
85 << "T *tp," << be_nl
86 << "PortableServer::POA_ptr poa," << be_nl
87 << "::CORBA::Boolean release = true);" << be_uidt
88 << be_uidt_nl
89 << "/// dtor" << be_nl
90 << "~" << tiename << " ();" << be_nl
91 << "// TIE specific functions" << be_nl
92 << "/// return the underlying object" << be_nl
93 << "T *_tied_object ();" << be_nl
94 << "/// set the underlying object" << be_nl
95 << "void _tied_object (T &obj);" << be_nl
96 << "/// set the underlying object and the ownership flag" << be_nl
97 << "void _tied_object (T *obj, ::CORBA::Boolean release = true);" << be_nl
98 << "/// do we own it" << be_nl
99 << "::CORBA::Boolean _is_owner ();" << be_nl
100 << "/// set the ownership" << be_nl_2
101 << "void _is_owner (::CORBA::Boolean b);" << be_nl
102 << "// overridden ServantBase operations" << be_nl
103 << "PortableServer::POA_ptr _default_POA ();";
105 int status =
106 node->traverse_inheritance_graph (
107 be_visitor_interface_tie_sh::method_helper,
111 if (status == -1)
113 ACE_ERROR_RETURN ((LM_ERROR,
114 "be_visitor_interface_tie_sh_ss::"
115 "visit_interface - "
116 "traversal of inhertance graph failed\n"),
117 -1);
120 *os << be_uidt_nl << be_nl
121 << "private:" << be_idt_nl
122 << "T *ptr_;" << be_nl
123 << "PortableServer::POA_var poa_;" << be_nl
124 << "::CORBA::Boolean rel_;" << be_nl_2
125 << tiename << " (const " << tiename << " &) = delete;" << be_nl
126 << "void operator= (const " << tiename << " &) = delete;" << be_uidt_nl
127 << "};";
129 return 0;
133 be_visitor_interface_tie_sh::visit_component (be_component *node)
135 return this->visit_interface (node);
139 be_visitor_interface_tie_sh::method_helper (be_interface *,
140 be_interface *node,
141 TAO_OutStream *os)
143 // Any methods from abstract parents have already been
144 // "added" to the derived interface scope by the overridden
145 // visit_scope() method in be_visitor_interface, so we can skip
146 // this base interface, if it is abstract.
147 if (node->is_abstract ())
149 return 0;
152 be_visitor_context ctx;
153 ctx.stream (os);
154 ctx.state (TAO_CodeGen::TAO_ROOT_TIE_SH);
155 be_visitor_interface_tie_sh visitor (&ctx);
157 if (visitor.visit_scope (node) == -1)
159 ACE_ERROR_RETURN ((LM_ERROR,
160 "be_visitor_interface_tie_sh::"
161 "method_helper\n"),
162 -1);
165 return 0;