Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_helper.h
blob1dd0ca843f12f74ee127583bea44a5a151fa126d
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 #include "ace/OS_NS_stdio.h"
21 #include <type_traits>
23 class Identifier;
24 class UTL_IdList;
25 class AST_Expression;
27 // A dummy structure to inform TAO_OutStream's << operator to put a newline
28 // and use the current indentation for the succeeding line
29 struct TAO_NL
31 TAO_NL ();
34 struct TAO_NL_2
36 TAO_NL_2 ();
39 /**
40 * Operates like a manipulator, increasing the indentation level.
42 * Increase the indentation level, if the "do_now" parameter is
43 * not zero then the <indent> method is called on the stream.
45 struct TAO_INDENT
47 TAO_INDENT (int do_now = 0);
49 const int do_now_;
52 /**
53 * Operates like a manipulator, decreasing the indentation level.
55 * Decrease the indentation level, if the "do_now" parameter is
56 * not zero then the <indent> method is called on the stream.
58 struct TAO_UNINDENT
60 TAO_UNINDENT (int do_now = 0);
62 const int do_now_;
65 extern const TAO_NL be_nl;
66 extern const TAO_NL_2 be_nl_2;
67 extern const TAO_INDENT be_idt;
68 extern const TAO_INDENT be_idt_nl;
69 extern const TAO_UNINDENT be_uidt;
70 extern const TAO_UNINDENT be_uidt_nl;
72 // A structure to inform TAO_OutStream's << operator to
73 // conditionally output a newline and some form of "ACE_CHECK".
74 struct TAO_ACE_CHECK
76 TAO_ACE_CHECK (const char *retval = 0,
77 bool do_return = false);
79 const char *retval_;
80 bool do_return_;
83 /**
84 * @class TAO_OutStream
86 * Defines an interface by which the backend code generator can
87 * print its output to the underlying I/O handle. This is a
88 * helper class that will be used by the TAO_CodeGen
89 * class. However, this is an abstract class and classes that
90 * understand specific front ends must derive from this class.
92 class TAO_OutStream
94 public:
95 /// Enumerated type to indicate the stream type
96 enum STREAM_TYPE
98 TAO_CLI_HDR,
99 TAO_CLI_INL,
100 TAO_CLI_IMPL,
101 TAO_SVR_HDR,
102 TAO_IMPL_HDR,
103 TAO_IMPL_SKEL,
104 TAO_SVR_TMPL_HDR,
105 TAO_SVR_INL,
106 TAO_SVR_TMPL_INL,
107 TAO_SVR_IMPL,
108 TAO_SVR_TMPL_IMPL,
109 TAO_GPERF_INPUT,
110 CIAO_SVNT_HDR,
111 CIAO_SVNT_IMPL,
112 CIAO_SVNT_T_HDR,
113 CIAO_SVNT_T_IMPL,
114 CIAO_EXEC_HDR,
115 CIAO_EXEC_IMPL,
116 CIAO_EXEC_IDL,
117 CIAO_EXEC_SVNT,
118 CIAO_CONN_HDR,
119 CIAO_CONN_IMPL,
120 CIAO_AMI4CCM_CONN_IDL,
121 CIAO_AMI_RH_IMPL_HDR,
122 CIAO_AMI_RH_IMPL_SRC
125 TAO_OutStream ();
127 virtual ~TAO_OutStream ();
129 /// Open the underlying low-level handle for output.
130 int open (const char *fname,
131 TAO_OutStream::STREAM_TYPE st = TAO_OutStream::TAO_CLI_HDR);
133 /// Set the stream type
134 void stream_type (TAO_OutStream::STREAM_TYPE);
136 /// Return the stream type
137 TAO_OutStream::STREAM_TYPE stream_type ();
139 /// Return the underlying lowlevel file pointer.
140 FILE *&file ();
142 /// Increment the indentation level and by default actually indent the output
143 /// accordingly
144 int incr_indent (unsigned short flag = 1);
146 /// Decrease the indentation level and by default actually indent the output
147 /// accordingly
148 int decr_indent (unsigned short flag = 1);
150 /// Reset indentation level to 0
151 int reset ();
153 /// Indent starting next line
154 int indent ();
156 /// Put a newline and indent on the next line
157 int nl ();
159 /// "printf" style variable argument print
160 int print (const char *format, ...)
161 ACE_GCC_FORMAT_ATTRIBUTE (printf, 2, 3);
163 /// Generate a #if !defined, #defined macro
164 int gen_ifdef_macro (const char *flat_name,
165 const char *suffix = 0,
166 bool add_stream_type_suffix = true);
168 /// Generate an endif statement
169 int gen_endif ();
171 // =overloaded operators
172 // Avoid duplication for the underlying type of size_t
173 template <typename Dummy = TAO_OutStream &>
174 typename std::enable_if<std::is_same<Dummy, TAO_OutStream &>::value &&
175 !std::is_same<ACE_CDR::ULongLong, size_t>::value &&
176 !std::is_same<ACE_CDR::ULong, size_t>::value,
177 TAO_OutStream &>::type
178 operator << (const size_t num)
180 ACE_OS::fprintf (this->fp_,
181 ACE_SIZE_T_FORMAT_SPECIFIER_ASCII,
182 num);
184 return *this;
187 TAO_OutStream &operator<< (const char *str);
188 TAO_OutStream &operator<< (char ch);
189 TAO_OutStream &operator<< (const ACE_CString &str);
190 TAO_OutStream &operator<< (const ACE_CDR::UShort num);
191 TAO_OutStream &operator<< (const ACE_CDR::Short num);
192 TAO_OutStream &operator<< (const ACE_CDR::ULong num);
193 TAO_OutStream &operator<< (const ACE_CDR::Long num);
194 TAO_OutStream &operator<< (const ACE_CDR::ULongLong num);
195 TAO_OutStream &operator<< (const ACE_CDR::LongLong num);
197 // = MANIPULATORS
199 TAO_OutStream &operator<< (const TAO_NL& nl);
200 TAO_OutStream &operator<< (const TAO_NL_2& nl_twice);
201 TAO_OutStream &operator<< (const TAO_INDENT& i);
202 TAO_OutStream &operator<< (const TAO_UNINDENT& i);
204 // The following will be provided by specialized classes
206 /// Output an Identifier node
207 TAO_OutStream &operator<< (Identifier *id);
209 /// Output a scoped name
210 TAO_OutStream &operator<< (UTL_IdList *idl);
212 /// Output an AST_Expression node
213 TAO_OutStream &operator<< (AST_Expression *expr);
215 TAO_OutStream &print (Identifier *id);
217 TAO_OutStream &print (UTL_IdList *idl);
219 TAO_OutStream &print (AST_Expression *idl);
221 void insert_comment (const char *file, int line);
222 #define TAO_INSERT_COMMENT(STRM) (STRM)->insert_comment (__FILE__, __LINE__)
224 protected:
225 /// The underlying low-level I/O handle
226 FILE *fp_;
228 /// Stream type
229 TAO_OutStream::STREAM_TYPE st_;
231 /// Indentation level
232 int indent_level_;
234 /// Used to set tab spaces.
235 ACE_CString tab_unit_str_;
238 #endif // if !defined