Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_helper.h
blob297864ac586e6355746f1636f3c35f79e9860f60
1 /* -*- c++ -*- */
3 //=============================================================================
4 /**
5 * @file be_helper.h
7 * Defines the abstract class for outputting the C++ mapping. This is a
8 * helper class to the singleton TAO_CodeGen class
10 * @author Aniruddha Gokhale Improvements by Carlos O'Ryan
12 //=============================================================================
14 #ifndef TAO_BE_OUTSTRM_H
15 #define TAO_BE_OUTSTRM_H
17 #include "ace/CDR_Base.h"
18 #include "ace/SString.h"
20 #if defined (ACE_HAS_CPP11)
21 #include "ace/OS_NS_stdio.h"
22 #include <type_traits>
23 #endif /* ACE_HAS_CPP11 */
25 class Identifier;
26 class UTL_IdList;
27 class AST_Expression;
29 // A dummy structure to inform TAO_OutStream's << operator to put a newline
30 // and use the current indentation for the succeeding line
31 struct TAO_NL
33 TAO_NL (void);
36 struct TAO_NL_2
38 TAO_NL_2 (void);
41 /**
42 * Operates like a manipulator, increasing the indentation level.
44 * Increase the indentation level, if the "do_now" parameter is
45 * not zero then the <indent> method is called on the stream.
47 struct TAO_INDENT
49 TAO_INDENT (int do_now = 0);
51 const int do_now_;
54 /**
55 * Operates like a manipulator, decreasing the indentation level.
57 * Decrease the indentation level, if the "do_now" parameter is
58 * not zero then the <indent> method is called on the stream.
60 struct TAO_UNINDENT
62 TAO_UNINDENT (int do_now = 0);
64 const int do_now_;
67 extern const TAO_NL be_nl;
68 extern const TAO_NL_2 be_nl_2;
69 extern const TAO_INDENT be_idt;
70 extern const TAO_INDENT be_idt_nl;
71 extern const TAO_UNINDENT be_uidt;
72 extern const TAO_UNINDENT be_uidt_nl;
74 // A structure to inform TAO_OutStream's << operator to
75 // conditionally output a newline and some form of "ACE_CHECK".
76 struct TAO_ACE_CHECK
78 TAO_ACE_CHECK (const char *retval = 0,
79 bool do_return = false);
81 const char *retval_;
82 bool do_return_;
85 /**
86 * @class TAO_OutStream
88 * Defines an interface by which the backend code generator can
89 * print its output to the underlying I/O handle. This is a
90 * helper class that will be used by the TAO_CodeGen
91 * class. However, this is an abstract class and classes that
92 * understand specific front ends must derive from this class.
94 class TAO_OutStream
96 public:
98 /// Enumerated type to indicate the stream type
99 enum STREAM_TYPE
101 TAO_CLI_HDR,
102 TAO_CLI_INL,
103 TAO_CLI_IMPL,
104 TAO_SVR_HDR,
105 TAO_IMPL_HDR,
106 TAO_IMPL_SKEL,
107 TAO_SVR_TMPL_HDR,
108 TAO_SVR_INL,
109 TAO_SVR_TMPL_INL,
110 TAO_SVR_IMPL,
111 TAO_SVR_TMPL_IMPL,
112 TAO_GPERF_INPUT,
113 CIAO_SVNT_HDR,
114 CIAO_SVNT_IMPL,
115 CIAO_SVNT_T_HDR,
116 CIAO_SVNT_T_IMPL,
117 CIAO_EXEC_HDR,
118 CIAO_EXEC_IMPL,
119 CIAO_EXEC_IDL,
120 CIAO_EXEC_SVNT,
121 CIAO_CONN_HDR,
122 CIAO_CONN_IMPL,
123 CIAO_AMI4CCM_CONN_IDL,
124 CIAO_AMI_RH_IMPL_HDR,
125 CIAO_AMI_RH_IMPL_SRC
128 TAO_OutStream (void);
130 virtual ~TAO_OutStream (void);
132 /// Open the underlying low-level handle for output.
133 int open (const char *fname,
134 TAO_OutStream::STREAM_TYPE st = TAO_OutStream::TAO_CLI_HDR);
136 /// Set the stream type
137 void stream_type (TAO_OutStream::STREAM_TYPE);
139 /// Return the stream type
140 TAO_OutStream::STREAM_TYPE stream_type (void);
142 /// Return the underlying lowlevel file pointer.
143 FILE *&file (void);
145 /// Increment the indentation level and by default actually indent the output
146 /// accordingly
147 int incr_indent (unsigned short flag = 1);
149 /// Decrease the indentation level and by default actually indent the output
150 /// accordingly
151 int decr_indent (unsigned short flag = 1);
153 /// Reset indentation level to 0
154 int reset (void);
156 /// Indent starting next line
157 int indent (void);
159 /// Put a newline and indent on the next line
160 int nl (void);
162 /// "printf" style variable argument print
163 int print (const char *format, ...)
164 ACE_GCC_FORMAT_ATTRIBUTE (printf, 2, 3);
166 /// Generate a #if !defined, #defined macro
167 int gen_ifdef_macro (const char *flat_name,
168 const char *suffix = 0,
169 bool add_stream_type_suffix = true);
171 /// Generate an endif statement
172 int gen_endif (void);
174 // =overloaded operators
175 #if defined (ACE_HAS_CPP11)
176 // Avoid duplication for the underlying type of size_t
177 template <typename Dummy = TAO_OutStream &>
178 typename std::enable_if<std::is_same<Dummy, TAO_OutStream &>::value &&
179 !std::is_same<ACE_CDR::ULongLong, size_t>::value &&
180 !std::is_same<ACE_CDR::ULong, size_t>::value,
181 TAO_OutStream &>::type
182 operator << (const size_t num)
184 ACE_OS::fprintf (this->fp_,
185 ACE_SIZE_T_FORMAT_SPECIFIER_ASCII,
186 num);
188 return *this;
190 #endif /* ACE_HAS_CPP11 */
192 TAO_OutStream &operator<< (const char *str);
193 TAO_OutStream &operator<< (char ch);
194 TAO_OutStream &operator<< (const ACE_CString &str);
195 TAO_OutStream &operator<< (const ACE_CDR::UShort num);
196 TAO_OutStream &operator<< (const ACE_CDR::Short num);
197 TAO_OutStream &operator<< (const ACE_CDR::ULong num);
198 TAO_OutStream &operator<< (const ACE_CDR::Long num);
199 TAO_OutStream &operator<< (const ACE_CDR::ULongLong num);
200 TAO_OutStream &operator<< (const ACE_CDR::LongLong num);
202 // = MANIPULATORS
204 TAO_OutStream &operator<< (const TAO_NL& nl);
205 TAO_OutStream &operator<< (const TAO_NL_2& nl_twice);
206 TAO_OutStream &operator<< (const TAO_INDENT& i);
207 TAO_OutStream &operator<< (const TAO_UNINDENT& i);
209 // The following will be provided by specialized classes
211 /// Output an Identifier node
212 TAO_OutStream &operator<< (Identifier *id);
214 /// Output a scoped name
215 TAO_OutStream &operator<< (UTL_IdList *idl);
217 /// Output an AST_Expression node
218 TAO_OutStream &operator<< (AST_Expression *expr);
220 TAO_OutStream &print (Identifier *id);
222 TAO_OutStream &print (UTL_IdList *idl);
224 TAO_OutStream &print (AST_Expression *idl);
226 void insert_comment (const char *file, int line);
227 #define TAO_INSERT_COMMENT(STRM) (STRM)->insert_comment (__FILE__, __LINE__)
229 protected:
230 /// The underlying low-level I/O handle
231 FILE *fp_;
233 /// Stream type
234 TAO_OutStream::STREAM_TYPE st_;
236 /// Indentation level
237 int indent_level_;
239 /// Used to set tab spaces.
240 ACE_CString tab_unit_str_;
243 #endif // if !defined