-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinter.h
193 lines (137 loc) · 6.07 KB
/
Printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* Copyright (C) neoliant.com - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary
* Written by neoliant - info@neoliant.com, February 2021
*/
#ifndef PRINTER_H
#define PRINTER_H
#include <string>
using namespace std;
#include <dds-opcua_builtin_typesC.h>
using namespace OMG::DDSOPCUA::OPCUA2DDS;
class Printer {
public:
string PrintBoolean( const CORBA::Boolean& object );
string PrintChar( const CORBA::Char & object );
string PrintOctet( const CORBA::Octet & object );
string PrintFloat( const CORBA::Float& object );
string PrintDouble( const CORBA::Double& object );
string PrintDateTime( DateTime datetime );
string PrintGuid( Guid guid );
string PrintByteString( ByteString bytestring );
string PrintXmlElement( XmlElement xmlelement );
string PrintNodeId( NodeId nodeid );
string PrintExpandedNodeId( ExpandedNodeId expandednodeid );
string PrintStatusCode( StatusCode statuscode );
string PrintQualifiedName( QualifiedName qualifiedname );
string PrintLocalizedText( LocalizedText localizeddtext );
string PrintExtensionObject( ExtensionObject extensionobject );
string PrintULongInHexaString( CORBA::ULong l );
string PrintUShortInHexaString( CORBA::UShort s );
string PrintOctetInHexaString( CORBA::Octet o );
string PrintVariant( const Variant & variant );
template<typename T>
string PrintArray( T array )
{
string output = "";
for (int i = 0; i < array.length(); i++)
{
if ( std::is_same<T, FloatArray>::value )
output += PrintFloat( array[ i ] );
else if ( std::is_same<T, DoubleArray>::value )
output += PrintDouble( array[ i ] );
else
output += std::to_string( array[ i ] );
output += " ";
}
return output;
}
template<typename T>
string PrintMatrix( T matrix )
{
string output = "";
int uaDimsSize = matrix.array_dimensions.length();
int currentIndex[ uaDimsSize ];
for (int i = 0; i < uaDimsSize; i++)
currentIndex[i] = 0;
bool nextLevel = false;
for (int i = 0; i < matrix.array.length(); i++) {
string currentIndexString = "";
for (int j = 0; j < uaDimsSize; j++) {
currentIndexString += std::to_string( currentIndex[ j ] );
currentIndexString += " ";
}
output += currentIndexString;
output += ": ";
if ( std::is_same<T, BooleanMatrix>::value )
output += PrintBoolean( matrix.array[ i ] );
else if ( std::is_same<T, SByteMatrix>::value )
output += PrintChar( matrix.array[ i ] );
else if ( std::is_same<T, ByteMatrix>::value )
output += PrintOctet( matrix.array[ i ] );
else if ( std::is_same<T, Int16Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, UInt16Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, Int32Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, UInt32Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, Int64Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, UInt64Matrix>::value )
output += std::to_string( matrix.array[ i ] );
else if ( std::is_same<T, FloatMatrix>::value )
output += PrintFloat( matrix.array[ i ] );
else if ( std::is_same<T, DoubleMatrix>::value )
output += PrintDouble( matrix.array[ i ] );
else if ( std::is_same<T, DateTimeMatrix>::value )
output += PrintDateTime( matrix.array[ i ] );
else if ( std::is_same<T, StatusCodeMatrix>::value )
output += std::to_string( matrix.array[ i ] );
nextLevel = true;
for (int j = uaDimsSize - 1; j >= 0; j--)
{
if (nextLevel)
{
currentIndex[ j ] += 1;
nextLevel = false;
}
if (currentIndex[ j ] == matrix.array_dimensions[ j ])
{
currentIndex[ j ] = 0;
nextLevel = true;
}
}
if (i == matrix.array.length() - 1)
break;
else
output += " / ";
}
return output;
}
string PrintStringArray( StringArray array );
string PrintDateTimeArray( DateTimeArray array );
string PrintGuidArray( GuidArray array );
string PrintByteStringArray( ByteStringArray array );
string PrintXmlElementArray( XmlElementArray array );
string PrintNodeIdArray( NodeIdArray array );
string PrintExpandedNodeIdArray( ExpandedNodeIdArray array );
string PrintStatusCodeArray( StatusCodeArray array );
string PrintQualifiedNameArray( QualifiedNameArray array );
string PrintLocalizedTextArray( LocalizedTextArray array );
string PrintExtensionObjectArray( ExtensionObjectArray array );
string PrintStringMatrix( StringMatrix matrix );
string PrintDateTimeMatrix( DateTimeMatrix matrix );
string PrintGuidMatrix( GuidMatrix matrix );
string PrintByteStringMatrix( ByteStringMatrix matrix );
string PrintXmlElementMatrix( XmlElementMatrix matrix );
string PrintNodeIdMatrix( NodeIdMatrix matrix );
string PrintExpandedNodeIdMatrix( ExpandedNodeIdMatrix matrix );
string PrintStatusCodeMatrix( StatusCodeMatrix matrix );
string PrintQualifiedNameMatrix( QualifiedNameMatrix matrix );
string PrintLocalizedTextMatrix( LocalizedTextMatrix matrix );
string PrintExtensionObjectMatrix( ExtensionObjectMatrix matrix );
string PrintDataValue( DataValue value );
};
#endif