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 #if defined (ACE_HAS_CPP11)
21 #include "ace/OS_NS_stdio.h"
22 #include <type_traits>
23 #endif /* ACE_HAS_CPP11 */
29 // A dummy structure to inform TAO_OutStream's << operator to put a newline
30 // and use the current indentation for the succeeding line
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.
49 TAO_INDENT (int do_now
= 0);
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.
62 TAO_UNINDENT (int do_now
= 0);
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".
78 TAO_ACE_CHECK (const char *retval
= 0,
79 bool do_return
= false);
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.
98 /// Enumerated type to indicate the stream type
123 CIAO_AMI4CCM_CONN_IDL
,
124 CIAO_AMI_RH_IMPL_HDR
,
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.
145 /// Increment the indentation level and by default actually indent the output
147 int incr_indent (unsigned short flag
= 1);
149 /// Decrease the indentation level and by default actually indent the output
151 int decr_indent (unsigned short flag
= 1);
153 /// Reset indentation level to 0
156 /// Indent starting next line
159 /// Put a newline and indent on the next line
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
,
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
);
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__)
230 /// The underlying low-level I/O handle
234 TAO_OutStream::STREAM_TYPE st_
;
236 /// Indentation level
239 /// Used to set tab spaces.
240 ACE_CString tab_unit_str_
;
243 #endif // if !defined