C++ TargetRTS
All Classes Functions Variables Enumerations Enumerator Pages
RTLog.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2021. All Rights Reserved.
4 * Copyright IBM Corporation 1999, 2016. All Rights Reserved.
5 *
6 * U.S. Government Users Restricted Rights - Use, duplication or
7 * disclosure restricted by GSA ADP Schedule.
8 */
9
10#ifndef __RTLog_h__
11#define __RTLog_h__ included
12
13#ifdef PRAGMA
14#pragma interface
15#endif
16
17#ifndef __RTProtocol_h__
18#include <RTProtocol.h>
19#endif
20
21#include <iostream>
22#include <sstream>
23#include <fstream>
24
25class RTDataObject;
26class RTMutex;
27struct RTObject_class;
28class RTString;
29struct RTTypedValue;
30
32struct Log
33{
35 class Base : public RTProtocol
36 {
37 private:
38 // this will eventually be a file descriptor.
39 int file;
40
41 public:
42 RTS_INLINE Base( void );
43 RTS_INLINE Base(std::ostream& stream);
44 RTS_INLINE ~Base( void );
45
46 static const RTProtocolDescriptor rt_class;
47
49 RTS_INLINE void cr( void );
50
51 void crtab( int = 1 );
52
53 // The below functions need not be called
54 void open( const char * );
55 void open( void );
56 void close( void );
57
61 void log( const char * str);
62
66 void log( const RTString & str);
67
71 void show( const char * str);
72
76 void show( const RTString & str);
77
78#if OBJECT_ENCODE
79 void log( char );
80#if RTUseFloatingPoint
81 void log( double );
82 void log( float );
83 void log( long double );
84#endif
85 void log( int );
86 void log( long );
87 void log( long long );
88 void log( short );
89 void log( const RTDataObject & );
90
95 void log( const void * data, const RTObject_class * type);
96
101 RTS_INLINE void log( const RTTypedValue & );
102
103 void log( unsigned int );
104 void log( unsigned long );
105 void log( unsigned long long );
106 void log( unsigned short );
107 void log( unsigned char );
108
109 void show( char );
110#if RTUseFloatingPoint
111 void show( double );
112 void show( float );
113 void show( long double );
114#endif
115 void show( int );
116 void show( long );
117 void show( long long );
118 void show( short );
119 void show( const RTDataObject & );
120
125 void show( const void * data, const RTObject_class * type);
126
131 RTS_INLINE void show( const RTTypedValue & );
132
133 void show( unsigned int );
134 void show( unsigned long );
135 void show( unsigned long long );
136 void show( unsigned short );
137 void show( unsigned char );
138#endif
139 void space( void );
140 void tab( void );
141 void clear( void );
142
147 void commit( void );
148
152 Base& operator<<( const RTDataObject & obj );
153
158 Base& operator<<( const RTTypedValue & info );
159
163 Base& operator<<( std::ostream& (*manip)(std::ostream&) );
164
168 template <typename T>
169 Base& operator<<( const T& value )
170 {
171 outputStream << value;
172 return *this;
173 }
174
175
176 private:
177 // unavailable methods
178 Base( const Base & );
179 Base & operator=( const Base & );
180 bool valueParsingUtil( const void * value, const RTObject_class * type );
181 std::ostream& outputStream;
182 };
183
184 static Base out;
185 static Base err;
186
190 static std::ostream& endl( std::ostream& os );
191
195 static std::ostream& lock( std::ostream& os );
196
200 static std::ostream& unlock( std::ostream& os );
201
202
203 class Stream
204 {
205 private:
206 std::ofstream ofStream;
207 Base* baseStream;
208 bool ownsStream;
209
210 // unavailable methods
211 Stream( const Stream & );
212 Stream & operator=( const Stream & );
213
214 public:
223 Stream( const char * filename, bool overwrite = true );
224
228 Stream( std::ostream* stdStreamPtr );
229
233 Stream( Base* baseStreamPtr );
234 ~Stream();
235
241
245 Stream& operator<<(std::ostream& (*manip)(std::ostream&));
246
250 template <typename T>
251 Stream& operator<<(const T& value)
252 {
253 if (baseStream)
254 {
255 (*baseStream) << value;
256 }
257 return *this;
258 }
259 };
260};
261
262#if RTS_INLINES
263#include <RTLog.inl>
264#endif
265
266#endif // __RTLog_h__
Represents a log port.
Definition: RTLog.h:36
Base & operator<<(const RTTypedValue &info)
Print an object to the log.
Base & operator<<(std::ostream &(*manip)(std::ostream &))
Used to call endl.
void log(const void *data, const RTObject_class *type)
Print the default ASCII encoding of an object to the log, followed by a carriage return.
void log(const char *str)
Print a string to the log, followed by a carriage return.
void commit(void)
Flush all buffered characters to the log.
void cr(void)
Print a carriage return to the log.
Definition: RTLog.inl:41
void show(const RTString &str)
Print a string to the log.
void log(const RTString &str)
Print a string to the log, followed by a carriage return.
Base & operator<<(const RTDataObject &obj)
Print an object to the log.
void show(const void *data, const RTObject_class *type)
Print the default ASCII encoding of an object to the log.
void show(const char *str)
Print a string to the log.
Base & operator<<(const T &value)
Template function to print the value of variable to the log.
Definition: RTLog.h:169
Definition: RTLog.h:204
Stream & operator<<(std::ostream &(*manip)(std::ostream &))
Invoke a manipulator on the stream, such as Log::endl or std::endl.
Stream & operator<<(const T &value)
Template function to print the value of variable to the log.
Definition: RTLog.h:251
Stream(Base *baseStreamPtr)
Logging Base stream e.g.
Stream(std::ostream *stdStreamPtr)
Logging for any ostream.
Stream(const char *filename, bool overwrite=true)
To append the log in file (e.g.
Stream & operator<<(const RTTypedValue &info)
Print an object to the log.
Provides a common interface to certain data type implementations (e.g.
Definition: RTDataObject.h:33
Represents a general capsule port typed by a protocol which determines the set of events that can be ...
Definition: RTProtocol.h:50
A C-style string wrapped in a data object.
Definition: RTString.h:24
Represents the predefined "Log" protocol.
Definition: RTLog.h:33
static std::ostream & lock(std::ostream &os)
Lock the Log::out or Log::err log statement.
static std::ostream & endl(std::ostream &os)
Insert the new line and flush the buffer.
static std::ostream & unlock(std::ostream &os)
Unlock the Log::out or Log::err log statement.
A type descriptor providing information about a type.
Definition: RTObject_class.h:64
Definition: RTProtocolDescriptor.h:40
Encapsulates a data object and its type descriptor.
Definition: RTTypedValue.h:29