3 //=============================================================================
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>
27 // A dummy structure to inform TAO_OutStream's << operator to put a newline
28 // and use the current indentation for the succeeding line
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.
47 TAO_INDENT (int do_now
= 0);
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.
60 TAO_UNINDENT (int do_now
= 0);
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".
76 TAO_ACE_CHECK (const char *retval
= 0,
77 bool do_return
= false);
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.
95 /// Enumerated type to indicate the stream type
120 CIAO_AMI4CCM_CONN_IDL
,
121 CIAO_AMI_RH_IMPL_HDR
,
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.
142 /// Increment the indentation level and by default actually indent the output
144 int incr_indent (unsigned short flag
= 1);
146 /// Decrease the indentation level and by default actually indent the output
148 int decr_indent (unsigned short flag
= 1);
150 /// Reset indentation level to 0
153 /// Indent starting next line
156 /// Put a newline and indent on the next line
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
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
,
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
);
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__)
225 /// The underlying low-level I/O handle
229 TAO_OutStream::STREAM_TYPE st_
;
231 /// Indentation level
234 /// Used to set tab spaces.
235 ACE_CString tab_unit_str_
;
238 #endif // if !defined