C++ TargetRTS
Loading...
Searching...
No Matches
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 void log( wchar_t );
81#if RTUseFloatingPoint
82 void log( double );
83 void log( float );
84 void log( long double );
85#endif
86 void log( int );
87 void log( long );
88 void log( long long );
89 void log( short );
90 void log( const RTDataObject & );
91
96 void log( const void * data, const RTObject_class * type);
97
102 RTS_INLINE void log( const RTTypedValue & );
103
104 void log( unsigned int );
105 void log( unsigned long );
106 void log( unsigned long long );
107 void log( unsigned short );
108 void log( unsigned char );
109
110 void show( char );
111 void show( wchar_t );
112#if RTUseFloatingPoint
113 void show( double );
114 void show( float );
115 void show( long double );
116#endif
117 void show( int );
118 void show( long );
119 void show( long long );
120 void show( short );
121 void show( const RTDataObject & );
122
127 void show( const void * data, const RTObject_class * type);
128
133 RTS_INLINE void show( const RTTypedValue & );
134
135 void show( unsigned int );
136 void show( unsigned long );
137 void show( unsigned long long );
138 void show( unsigned short );
139 void show( unsigned char );
140#endif
141 void space( void );
142 void tab( void );
143 void clear( void );
144
149 void commit( void );
150
154 Base& operator<<( const RTDataObject & obj );
155
160 Base& operator<<( const RTTypedValue & info );
161
165 Base& operator<<( std::ostream& (*manip)(std::ostream&) );
166
170 template <typename T>
171 Base& operator<<( const T& value )
172 {
173 outputStream << value;
174 return *this;
175 }
176
177
178 private:
179 // unavailable methods
180 Base( const Base & );
181 Base & operator=( const Base & );
182 bool valueParsingUtil( const void * value, const RTObject_class * type );
183 std::ostream& outputStream;
184 };
185
186 static Base out;
187 static Base err;
188
192 static std::ostream& endl( std::ostream& os );
193
197 static std::ostream& lock( std::ostream& os );
198
202 static std::ostream& unlock( std::ostream& os );
203
204
205 class Stream
206 {
207 private:
208 std::ofstream ofStream;
209 Base* baseStream;
210 bool ownsStream;
211
212 // unavailable methods
213 Stream( const Stream & );
214 Stream & operator=( const Stream & );
215
216 public:
225 Stream( const char * filename, bool overwrite = true );
226
230 Stream( std::ostream* stdStreamPtr );
231
235 Stream( Base* baseStreamPtr );
236 ~Stream();
237
243
247 Stream& operator<<(std::ostream& (*manip)(std::ostream&));
248
252 template <typename T>
253 Stream& operator<<(const T& value)
254 {
255 if (baseStream)
256 {
257 (*baseStream) << value;
258 }
259 return *this;
260 }
261 };
262};
263
264#if RTS_INLINES
265#include <RTLog.inl>
266#endif
267
268#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:171
Definition: RTLog.h:206
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:253
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