-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsttp.i
2230 lines (1839 loc) · 88.9 KB
/
sttp.i
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//******************************************************************************************************
// sttp.i - Gbtc
//
// Copyright © 2019, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 06/22/2019 - J. Ritchie Carroll
// Generated original version of source code.
//
//******************************************************************************************************
// SWIG Interface File: Used to build .NET Wrapper Code in sttp.net and sttp.net.lib projects
%module(directors="1") Common
%include "stdint.i"
%include "std_string.i"
%include "std_map.i"
%include "std_vector.i"
%include <boost_shared_ptr.i>
%include "exception.i"
%include "arrays_csharp.i"
%exception
{
try
{
$action
}
catch (const std::exception& e)
{
SWIG_exception(SWIG_RuntimeError, e.what());
}
}
%define SWIGEXCODE3 "\n if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
%{
// Include STTP library header files
#include "../cppapi/src/lib/CommonTypes.h"
#include "../cppapi/src/lib/Nullable.h"
#include "../cppapi/src/lib/data/DataSet.h"
#include "../cppapi/src/lib/transport/TransportTypes.h"
#include "../cppapi/src/lib/transport/SubscriberInstance.h"
#include "../cppapi/src/lib/transport/PublisherInstance.h"
%}
// Hijack module class modifiers to inject needed target classes into root namespace
%pragma(csharp) moduleclassmodifiers = %{
// Measurement structure uses custom marshaling as an optimization
// Fundamental data type representing a measurement in STTP
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public unsafe struct Measurement
{
// Measurement's globally unique identifier bytes.
public fixed byte SignalID[16];
// Instantaneous value of the measurement.
public double Value;
// The time, in ticks, that this measurement was taken.
public long Timestamp;
// Flags indicating the state of the measurement as reported by the device that took it.
public MeasurementStateFlags Flags;
public Measurement(System.Guid signalID, System.DateTime timestamp, double value = double.NaN, MeasurementStateFlags flags = MeasurementStateFlags.Normal)
{
Value = value;
Timestamp = timestamp.Ticks;
Flags = flags;
this.SetSignalID(signalID);
}
public Measurement(System.Guid signalID, long timestamp, double value = double.NaN, MeasurementStateFlags flags = MeasurementStateFlags.Normal)
{
Value = value;
Timestamp = timestamp;
Flags = flags;
this.SetSignalID(signalID);
}
}
public static class MeasurementExtensions
{
public static unsafe System.Guid GetSignalID(this ref Measurement measurement)
{
fixed (byte* data = measurement.SignalID)
{
byte* swap = stackalloc byte[8];
byte* copy = stackalloc byte[8];
for (int i = 0; i < 8; i++)
copy[i] = data[i];
// The following uint32 and two uint16 values are little-endian encoded in Microsoft implementations,
// boost follows RFC encoding rules and encodes the bytes as big-endian. For proper Guid interpretation
// by .NET applications the following bytes must be swapped before deserialization:
swap[0] = copy[3];
swap[1] = copy[2];
swap[2] = copy[1];
swap[3] = copy[0];
swap[4] = copy[5];
swap[5] = copy[4];
swap[6] = copy[7];
swap[7] = copy[6];
return new System.Guid
(
/* a */ *(uint*)swap, // First 4 bytes of GUID
/* b */ *(ushort*)(swap + 4), // Next 2 bytes of GUID
/* c */ *(ushort*)(swap + 6), // Next 2 bytes of GUID
/* d */ data[8], // Remaining bytes
/* e */ data[9],
/* f */ data[10],
/* g */ data[11],
/* h */ data[12],
/* i */ data[13],
/* j */ data[14],
/* k */ data[15]
);
}
}
public static unsafe void SetSignalID(this ref Measurement measurement, System.Guid value)
{
fixed (byte* data = measurement.SignalID)
{
byte* copy = stackalloc byte[8];
fixed (byte* source = value.ToByteArray())
{
for (int i = 0; i < 16; i++)
{
if (i < 8)
copy[i] = source[i];
else
data[i] = source[i];
}
}
// Convert Microsoft encoding to RFC
data[0] = copy[3];
data[1] = copy[2];
data[3] = copy[0];
data[2] = copy[1];
data[4] = copy[5];
data[5] = copy[4];
data[6] = copy[7];
data[7] = copy[6];
}
}
public static System.DateTime GetDateTime(this ref Measurement measurement) => new System.DateTime(measurement.Timestamp);
public static void SetDateTime(this ref Measurement measurement, System.DateTime value) => measurement.Timestamp = value.Ticks;
}
public class SubscriberInstance : SubscriberInstanceBase
{
public SubscriberInstance()
{
System.Reflection.Assembly assembly = typeof(SubscriberInstance).Assembly;
System.Reflection.AssemblyName assemblyInfo = assembly.GetName();
System.DateTime buildDate = System.IO.File.GetLastWriteTime(assembly.Location);
GetAssemblyInfo(out string source, out string version, out string updatedOn);
string wrapperAssemblyInfo = $", wrapping {source} version {version} updated on {updatedOn}";
SetAssemblyInfo(assemblyInfo.Name, $"{assemblyInfo.Version.Major}.{assemblyInfo.Version.Minor}.{assemblyInfo.Version.Build}", $"{buildDate:yyyy-MM-dd HH:mm:ss}{wrapperAssemblyInfo}");
}
internal override unsafe void ReceivedNewMeasurements(SimpleMeasurement simpleMeasurementArray, int length)
{
Measurement* measurements = (Measurement*)SimpleMeasurement.getCPtr(simpleMeasurementArray).Handle.ToPointer();
if (measurements == null)
return;
ReceivedNewMeasurements(measurements, length);
}
public virtual unsafe void ReceivedNewMeasurements(Measurement* measurements, int length)
{
}
public new static readonly string SubscribeAllExpression = SubscriberInstanceBase.SubscribeAllExpression;
public new static readonly string SubscribeAllNoStatsExpression = SubscriberInstanceBase.SubscribeAllNoStatsExpression;
public new static readonly string FilterMetadataStatsExpression = SubscriberInstanceBase.FilterMetadataStatsExpression;
}
public class%}
// Define SWIG types to wrap in target language
namespace sttp
{
// Mark C++ library specific class pointer wrappers as internal
%typemap(csclassmodifiers) sttp::decimal_t, sttp::decimal_t*, sttp::decimal_t&, sttp::decimal_t[], sttp::decimal_t (CLASS::*) "internal class"
%typemap(csclassmodifiers) datetime_t, datetime_t*, datetime_t&, datetime_t[], datetime_t (CLASS::*) "internal class"
%typemap(csclassmodifiers) Guid, Guid*, Guid&, Guid[], Guid (CLASS::*) "internal class"
typedef float float32_t;
typedef double float64_t;
class decimal_t
{
decimal_t();
decimal_t(const decimal_t&);
};
%rename(guid_t) Guid;
class Guid
{
Guid();
Guid(const Guid&);
};
class datetime_t
{
datetime_t();
datetime_t(const datetime_t&);
};
namespace data
{
class DataSet;
class DataTable;
class DataRow;
class DataColumn;
}
namespace transport
{
struct SimpleMeasurement;
struct Measurement;
struct MeasurementMetadata;
struct PhasorMetadata;
struct PhasorReference;
struct DeviceMetadata;
struct ConfigurationFrame;
class SignalIndexCache;
%rename(SubscriberInstanceBase) SubscriberInstance;
class SubscriberInstance;
class SubscriberConnection;
class PublisherInstance;
}
}
%shared_ptr(sttp::data::DataSet)
%shared_ptr(sttp::data::DataTable)
%shared_ptr(sttp::data::DataRow)
%shared_ptr(sttp::data::DataColumn)
%shared_ptr(sttp::transport::MeasurementMetadata)
%shared_ptr(sttp::transport::PhasorMetadata)
%shared_ptr(sttp::transport::PhasorReference)
%shared_ptr(sttp::transport::DeviceMetadata)
%shared_ptr(sttp::transport::ConfigurationFrame)
%shared_ptr(sttp::transport::SignalIndexCache)
%shared_ptr(sttp::transport::SubscriberInstance)
%shared_ptr(sttp::transport::SubscriberConnection)
%shared_ptr(sttp::transport::PublisherInstance)
%csmethodmodifiers GetGuidBytes "internal unsafe";
%apply uint8_t FIXED[] {uint8_t* data}
%inline
%{
// Get byte array representing a globally unique identifier
void GetGuidBytes(const sttp::Guid& value, uint8_t* data)
{
memcpy(data, value.data, 16);
uint8_t copy[8];
for (uint32_t i = 0; i < 8; i++)
copy[i] = data[i];
// The following uint32 and two uint16 values are little-endian encoded in Microsoft implementations,
// boost follows RFC encoding rules and encodes the bytes as big-endian. For proper Guid interpretation
// by .NET applications the following bytes must be swapped before deserialization:
data[3] = copy[0];
data[2] = copy[1];
data[1] = copy[2];
data[0] = copy[3];
data[4] = copy[5];
data[5] = copy[4];
data[6] = copy[7];
data[7] = copy[6];
}
std::string GetSubscriberConnectionIPAddress(const boost::shared_ptr<sttp::transport::SubscriberConnection>& connection)
{
return connection->GetIPAddress().to_string();
}
%}
%csmethodmodifiers ParseDecimal "internal";
%inline
%{
// Parse decimal_t from string
sttp::decimal_t ParseDecimal(const std::string& value)
{
sttp::decimal_t decVal;
sttp::TryParseDecimal(value, decVal);
return decVal;
}
%}
namespace sttp
{
// Define nullable class (minimal definition)
%typemap(csclassmodifiers) Nullable<T> "internal class"
template <class T>
class Nullable {
public:
Nullable();
Nullable(const T& value);
bool HasValue() const;
const T& GetValueOrDefault() const;
};
%typemap(cstype) Nullable<T>, const Nullable<T> & "$typemap(cstype, T)?"
%naturalvar Nullable<T>;
%template(NullableString) Nullable<std::string>;
%template(NullableBool) Nullable<bool>;
%template(NullableDateTime) Nullable<datetime_t>;
%template(NullableFloat32) Nullable<float32_t>;
%template(NullableFloat64) Nullable<float64_t>;
%template(NullableDecimal) Nullable<sttp::decimal_t>;
%template(NullableGuid) Nullable<Guid>;
%template(NullableInt8) Nullable<int8_t>;
%template(NullableInt16) Nullable<int16_t>;
%template(NullableInt32) Nullable<int32_t>;
%template(NullableInt64) Nullable<int64_t>;
%template(NullableUInt8) Nullable<uint8_t>;
%template(NullableUInt16) Nullable<uint16_t>;
%template(NullableUInt32) Nullable<uint32_t>;
%template(NullableUInt64) Nullable<uint64_t>;
// The boost decimal type has a very complex internal representation, although slower,
// it's safer convert the value to and from a string:
%csmethodmodifiers ToString "internal";
std::string ToString(const sttp::decimal_t& value);
// Map sttp::decimal_t (boost::multiprecision::cpp_dec_float_100) to System.Decimal
%typemap(cstype) sttp::decimal_t, const sttp::decimal_t& "decimal"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.ParseDecimal($csinput.ToString());"
)
sttp::decimal_t "$csclassname.getCPtr(temp$csinput)"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.ParseDecimal($csinput.ToString());"
)
const sttp::decimal_t& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) sttp::decimal_t& "out decimal"
%typemap(csin,
pre=" using ($csclassname temp$csinput = new $csclassname()) {",
post=" $csinput = System.Convert.ToDecimal($module.ToString(temp$csinput));",
terminator=" }",
cshin="out $csinput"
)
sttp::decimal_t& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype, out="decimal") sttp::decimal_t* "ref decimal"
%typemap(csin,
pre=" using ($csclassname temp$csinput = $module.ParseDecimal($csinput.ToString())) {",
post=" $csinput = System.Convert.ToDecimal($module.ToString(temp$csinput));",
terminator=" }",
cshin="ref $csinput"
)
sttp::decimal_t* "$csclassname.getCPtr(temp$csinput)"
%typemap(csvarin, excode=SWIGEXCODE3) sttp::decimal_t*, sttp::decimal_t&, sttp::decimal_t
%{
set {
$csclassname temp$csinput = $module.ParseDecimal($csinput.ToString());
$imcall;$excode
}
%}
%typemap(csvarout, excode=SWIGEXCODE3) sttp::decimal_t*, sttp::decimal_t&, sttp::decimal_t
%{
get {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
return System.Convert.ToDecimal($module.ToString(tempDate));
}
}
%}
%typemap(cstype) sttp::decimal_t, const sttp::decimal_t "decimal"
%typemap(csout, excode=SWIGEXCODE2) sttp::decimal_t, const sttp::decimal_t, const sttp::decimal_t&
{
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
return System.Convert.ToDecimal($module.ToString(tempDate));
}
}
// Convert 16 contiguous bytes into a globally unique identifier
%csmethodmodifiers ParseGuid "internal unsafe";
%apply uint8_t FIXED[] {const uint8_t* data}
extern Guid ParseGuid(const uint8_t* data, bool swapEndianness);
// Map Guid (boost::uuids::uuid) to System.Guid
%typemap(cstype) Guid, const Guid& "System.Guid"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.ParseGuid($csinput.ToByteArray(), true);"
)
Guid "$csclassname.getCPtr(temp$csinput)"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.ParseGuid($csinput.ToByteArray(), true);"
)
const Guid& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) Guid& "out System.Guid"
%typemap(csin,
pre=" using ($csclassname temp$csinput = new $csclassname()) {",
post=
" byte[] $csinput_data = new byte[16];\n"
" $module.GetGuidBytes(temp$csinput, $csinput_data);\n"
" $csinput = new System.Guid($csinput_data);",
terminator=" }",
cshin="out $csinput"
)
Guid& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype, out="System.Guid") Guid* "ref System.Guid"
%typemap(csin,
pre=" using ($csclassname temp$csinput = $module.ParseGuid($csinput.ToByteArray(), true)) {",
post=
" byte[] $csinput_data = new byte[16];\n"
" $module.GetGuidBytes(temp$csinput), $csinput_data);\n"
" $csinput = new System.Guid($csinput_data);",
terminator=" }",
cshin="ref $csinput"
)
Guid* "$csclassname.getCPtr(temp$csinput)"
%typemap(csvarin, excode=SWIGEXCODE3) Guid*, Guid&, Guid
%{
set {
$csclassname temp$csinput = $module.ParseGuid($csinput.ToByteArray(), true);
$imcall;$excode
}
%}
%typemap(csvarout, excode=SWIGEXCODE3) Guid*, Guid&, Guid
%{
get {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempGuid = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
byte[] data = new byte[16];
$module.GetGuidBytes(tempGuid, data);
return new System.Guid(data);
}
}
%}
%typemap(cstype) Guid, const Guid "System.Guid"
%typemap(csout, excode=SWIGEXCODE2) Guid, const Guid, const Guid&
{
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempGuid = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
byte[] data = new byte[16];
$module.GetGuidBytes(tempGuid, data);
return new System.Guid(data);
}
}
// Converts a timestamp, in Ticks, to datetime_t
%csmethodmodifiers FromTicks "internal";
datetime_t FromTicks(int64_t ticks);
// Converts a datetime_t to Ticks
%csmethodmodifiers ToTicks "internal";
int64_t ToTicks(const datetime_t& time);
// Map datetime_t (boost::posix_time::ptime) to System.DateTime
%typemap(cstype) datetime_t, const datetime_t& "System.DateTime"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.FromTicks($csinput.Ticks);"
)
datetime_t "$csclassname.getCPtr(temp$csinput)"
%typemap(csin,
pre=" $csclassname temp$csinput = $module.FromTicks($csinput.Ticks);"
)
const datetime_t& "$csclassname.getCPtr(temp$csinput)"
%typemap(csdirectorin,
pre =
" $csclassname tempDate = new datetime_t($iminput, false);\n"
" System.DateTime temp$iminput = new System.DateTime($module.ToTicks(tempDate));"
)
datetime_t "temp$iminput"
%typemap(cstype) datetime_t& "out System.DateTime"
%typemap(csin,
pre=" using ($csclassname temp$csinput = new $csclassname()) {",
post=" $csinput = new System.DateTime($module.ToTicks(temp$csinput));",
terminator=" }",
cshin="out $csinput"
)
datetime_t& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype, out="System.DateTime") datetime_t* "ref System.DateTime"
%typemap(csin,
pre=" using ($csclassname temp$csinput = $module.FromTicks($csinput)) {",
post=" $csinput = new System.DateTime($module.ToTicks(temp$csinput));",
terminator=" }",
cshin="ref $csinput"
)
datetime_t* "$csclassname.getCPtr(temp$csinput)"
%typemap(csvarin, excode=SWIGEXCODE3) datetime_t*, datetime_t&, datetime_t
%{
set {
$csclassname temp$csinput = $module.FromTicks($csinput.Ticks);
$imcall;$excode
}
%}
%typemap(csvarout, excode=SWIGEXCODE3) datetime_t*, datetime_t&, datetime_t
%{
get {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
return new System.DateTime($module.ToTicks(tempDate));
}
}
%}
%typemap(cstype) datetime_t, const datetime_t "System.DateTime"
%typemap(csout, excode=SWIGEXCODE2) datetime_t, const datetime_t, const datetime_t&
{
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
return new System.DateTime($module.ToTicks(tempDate));
}
}
// Note: Do not change the spacing on the following Nullable typemaps as it affects spacing in generated code (see DataRow.cs):
// Map sttp::Nullable<std::string> to string
%typemap(cstype) const sttp::Nullable<std::string>& "string"
%typemap(csin,
pre=" $csclassname temp$csinput = new $csclassname($csinput);"
)
const sttp::Nullable<std::string>& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) sttp::Nullable<std::string> "string"
%typemap(csout, excode=SWIGEXCODE) sttp::Nullable<std::string> {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempString = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
return tempString?.GetValueOrDefault();
}
}
// Map sttp::Nullable<sttp::decimal_t> to decimal
%typemap(cstype) const sttp::Nullable<sttp::decimal_t>& "decimal?"
%typemap(csin,
pre=" $csclassname temp$csinput = $csinput.HasValue ? new $csclassname($module.ParseDecimal($csinput.Value.ToString())) : null;"
)
const sttp::Nullable<sttp::decimal_t>& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) sttp::Nullable<sttp::decimal_t> "decimal?"
%typemap(csout, excode=SWIGEXCODE) sttp::Nullable<sttp::decimal_t> {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDecimal = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
if (tempDecimal?.HasValue() ?? false) return System.Convert.ToDecimal($module.ToString(tempDecimal.GetValueOrDefault()));
return null;
}
}
// Map sttp::Nullable<Guid> to System.Guid
%typemap(cstype) const sttp::Nullable<Guid>& "System.Guid?"
%typemap(csin,
pre=" $csclassname temp$csinput = $csinput.HasValue ? new $csclassname($module.ParseGuid($csinput.Value.ToByteArray(), true)) : null;"
)
const sttp::Nullable<Guid>& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) sttp::Nullable<Guid> "System.Guid?"
%typemap(csout, excode=SWIGEXCODE) sttp::Nullable<Guid> {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempGuid = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
if (!(tempGuid?.HasValue() ?? false)) return null;
byte[] data = new byte[16];
$module.GetGuidBytes(tempGuid.GetValueOrDefault(), data);
return new System.Guid(data);
}
}
// Map sttp::Nullable<datetime_t> to System.DateTime
%typemap(cstype) const sttp::Nullable<datetime_t>& "System.DateTime?"
%typemap(csin,
pre=" $csclassname temp$csinput = $csinput.HasValue ? new $csclassname($module.FromTicks($csinput.Value.Ticks)) : null;"
)
const sttp::Nullable<datetime_t>& "$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) sttp::Nullable<datetime_t> "System.DateTime?"
%typemap(csout, excode=SWIGEXCODE) sttp::Nullable<datetime_t> {
global::System.IntPtr cPtr = $imcall;$excode
using ($csclassname tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {
if (tempDate?.HasValue() ?? false) return new System.DateTime($module.ToTicks(tempDate.GetValueOrDefault()));
return null;
}
}
%define NULLABLE_CSOUT_EXPANSION "\n\
global::System.IntPtr cPtr = $imcall;\n\
if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();\n\
using ($csclassname tempValue = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner)) {\n\
if (tempValue?.HasValue() ?? false) return tempValue.GetValueOrDefault();\n\
return null;\n\
}\n"
%enddef
#define NULLABLE_TYPEDECL(stype, ttype)\
%typemap(cstype) const sttp::Nullable<stype>& "ttype?"\
%typemap(csin, pre=" $csclassname temp$csinput = $csinput.HasValue ? new $csclassname($csinput.Value) : null;")\
const sttp::Nullable<stype>& "$csclassname.getCPtr(temp$csinput)"\
%typemap(cstype) sttp::Nullable<stype> "ttype?" \
%typemap(csout, excode=NULLABLE_CSOUT_EXPANSION) sttp::Nullable<stype> {$excode }
// Map Nullable templates for simple types
NULLABLE_TYPEDECL(bool, bool);
NULLABLE_TYPEDECL(float32_t, float);
NULLABLE_TYPEDECL(float64_t, double);
NULLABLE_TYPEDECL(int8_t, sbyte);
NULLABLE_TYPEDECL(int16_t, short);
NULLABLE_TYPEDECL(int32_t, int);
NULLABLE_TYPEDECL(int64_t, long);
NULLABLE_TYPEDECL(uint8_t, byte);
NULLABLE_TYPEDECL(uint16_t, ushort);
NULLABLE_TYPEDECL(uint32_t, uint);
NULLABLE_TYPEDECL(uint64_t, ulong);
}
namespace std
{
%naturalvar string;
class string;
// string &
%typemap(ctype) std::string & "char**"
%typemap(imtype) std::string & "out string"
%typemap(cstype) std::string & "out string"
//C++
%typemap(in, canthrow=1) std::string &
%{ //typemap in
std::string temp$1_name;
$1 = &temp$1_name;
%}
//C++
%typemap(argout) std::string &
%{
//Typemap argout in c++ file.
//This will convert c++ string to c# string
*$input = SWIG_csharp_string_callback($1->c_str());
%}
%typemap(argout) const std::string &
%{
//argout typemap for const std::string&
%}
%typemap(csin) std::string & "out $csinput"
%typemap(throws, canthrow=1) string &
%{ SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
return $null; %}
%template(ByteBuffer) vector<unsigned char>;
%template(StringCollection) vector<string>;
%template(GuidCollection) vector<sttp::Guid>;
%template(DataTableCollection) vector<boost::shared_ptr<sttp::data::DataTable>>;
%template(MeasurementMetadataCollection) vector<boost::shared_ptr<sttp::transport::MeasurementMetadata>>;
%template(PhasorMetadataCollection) vector<boost::shared_ptr<sttp::transport::PhasorMetadata>>;
%template(PhasorReferenceCollection) vector<boost::shared_ptr<sttp::transport::PhasorReference>>;
%template(DeviceMetadataCollection) vector<boost::shared_ptr<sttp::transport::DeviceMetadata>>;
%template(SubscriberConnectionCollection) vector<boost::shared_ptr<sttp::transport::SubscriberConnection>>;
%template(DeviceMetadataMap) map<string, boost::shared_ptr<sttp::transport::DeviceMetadata>>;
%template(MeasurementMetadataMap) map<sttp::Guid, boost::shared_ptr<sttp::transport::MeasurementMetadata>>;
}
namespace sttp {
namespace data
{
enum class DataType
{
String,
Boolean,
DateTime,
Single,
Double,
Decimal,
Guid,
Int8,
Int16,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
UInt64
};
typedef boost::shared_ptr<DataSet> DataSetPtr;
typedef boost::shared_ptr<DataTable> DataTablePtr;
typedef boost::shared_ptr<DataRow> DataRowPtr;
typedef boost::shared_ptr<DataColumn> DataColumnPtr;
%rename(_TableCount) DataSet::TableCount;
%rename(_TableNames) DataSet::TableNames;
%rename(_Tables) DataSet::Tables;
class DataSet
{
public:
DataSet();
~DataSet();
const DataTablePtr& Table(const std::string& tableName) const;
DataTablePtr CreateTable(const std::string& name);
%csmethodmodifiers TableCount "private";
int32_t TableCount() const;
%csmethodmodifiers TableNames "private";
std::vector<std::string> TableNames() const;
%csmethodmodifiers Tables "private";
std::vector<DataTablePtr> Tables() const;
bool AddOrUpdateTable(DataTablePtr table);
bool RemoveTable(const std::string& tableName);
void ReadXml(const std::string& fileName);
void ReadXml(const std::vector<uint8_t>& buffer);
%csmethodmodifiers ReadXml "public unsafe";
%apply uint8_t FIXED[] {uint8_t* buffer}
void ReadXml(const uint8_t* buffer, uint32_t length);
void WriteXml(const std::string& fileName, const std::string& dataSetName = "DataSet") const;
void WriteXml(std::vector<uint8_t>& buffer, const std::string& dataSetName = "DataSet") const;
static DataSetPtr FromXml(const std::string& fileName);
static DataSetPtr FromXml(const std::vector<uint8_t>& buffer);
%csmethodmodifiers FromXml "public unsafe";
%apply uint8_t FIXED[] {const uint8_t* buffer}
static DataSetPtr FromXml(const uint8_t* buffer, uint32_t length);
static const std::string XmlSchemaNamespace;
static const std::string ExtXmlSchemaDataNamespace;
};
%extend DataSet {
%proxycode
%{
public int TableCount => _TableCount();
public StringCollection TableNames => _TableNames();
public DataTableCollection Tables => _Tables();
public DataTable this[string tableName] => Table(tableName);
%}}
%rename(_Parent) DataTable::Parent;
%rename(_Name) DataTable::Name;
%rename(_ColumnCount) DataTable::ColumnCount;
%rename(_RowCount) DataTable::RowCount;
class DataTable
{
public:
DataTable(DataSetPtr parent, std::string name);
~DataTable();
%csmethodmodifiers Parent "private";
const DataSetPtr& Parent() const;
%csmethodmodifiers Name "private";
const std::string& Name() const;
void AddColumn(DataColumnPtr column);
const DataColumnPtr& Column(const std::string& columnName) const;
const DataColumnPtr& Column(int32_t index) const;
DataColumnPtr CreateColumn(const std::string& name, DataType type, std::string expression = "");
DataColumnPtr CloneColumn(const DataColumnPtr& source);
%csmethodmodifiers ColumnCount "private";
int32_t ColumnCount() const;
const DataRowPtr& Row(int32_t index);
void AddRow(DataRowPtr row);
DataRowPtr CreateRow();
DataRowPtr CloneRow(const DataRowPtr& source);
%csmethodmodifiers RowCount "private";
int32_t RowCount() const;
};
%extend DataTable {
%proxycode
%{
public DataSet Parent => _Parent();
public string Name => _Name();
public int ColumntCount => _ColumnCount();
public int RowCount => _RowCount();
public DataColumn this[int index] => Column(index);
public DataColumn this[string columnName] => Column(columnName);
%}}
%rename(_Parent) DataRow::Parent;
class DataRow
{
public:
DataRow(DataTablePtr parent);
~DataRow();
%csmethodmodifiers Parent "private";
const DataTablePtr& Parent() const;
bool IsNull(int32_t columnIndex);
bool IsNull(const std::string& columnName);
void SetNullValue(int32_t columnIndex);
void SetNullValue(const std::string& columnName);
sttp::Nullable<std::string> ValueAsString(int32_t columnIndex);
sttp::Nullable<std::string> ValueAsString(const std::string& columnName);
void SetStringValue(int32_t columnIndex, const sttp::Nullable<std::string>& value);
void SetStringValue(const std::string& columnName, const sttp::Nullable<std::string>& value);
sttp::Nullable<bool> ValueAsBoolean(int32_t columnIndex);
sttp::Nullable<bool> ValueAsBoolean(const std::string& columnName);
void SetBooleanValue(int32_t columnIndex, const sttp::Nullable<bool>& value);
void SetBooleanValue(const std::string& columnName, const sttp::Nullable<bool>& value);
sttp::Nullable<sttp::datetime_t> ValueAsDateTime(int32_t columnIndex);
sttp::Nullable<sttp::datetime_t> ValueAsDateTime(const std::string& columnName);
void SetDateTimeValue(int32_t columnIndex, const sttp::Nullable<sttp::datetime_t>& value);
void SetDateTimeValue(const std::string& columnName, const sttp::Nullable<sttp::datetime_t>& value);
sttp::Nullable<sttp::float32_t> ValueAsSingle(int32_t columnIndex);
sttp::Nullable<sttp::float32_t> ValueAsSingle(const std::string& columnName);
void SetSingleValue(int32_t columnIndex, const sttp::Nullable<sttp::float32_t>& value);
void SetSingleValue(const std::string& columnName, const sttp::Nullable<sttp::float32_t>& value);
sttp::Nullable<sttp::float64_t> ValueAsDouble(int32_t columnIndex);
sttp::Nullable<sttp::float64_t> ValueAsDouble(const std::string& columnName);
void SetDoubleValue(int32_t columnIndex, const sttp::Nullable<sttp::float64_t>& value);
void SetDoubleValue(const std::string& columnName, const sttp::Nullable<sttp::float64_t>& value);
sttp::Nullable<sttp::decimal_t> ValueAsDecimal(int32_t columnIndex);
sttp::Nullable<sttp::decimal_t> ValueAsDecimal(const std::string& columnName);
void SetDecimalValue(int32_t columnIndex, const sttp::Nullable<sttp::decimal_t>& value);
void SetDecimalValue(const std::string& columnName, const sttp::Nullable<sttp::decimal_t>& value);
sttp::Nullable<sttp::Guid> ValueAsGuid(int32_t columnIndex);
sttp::Nullable<sttp::Guid> ValueAsGuid(const std::string& columnName);
void SetGuidValue(int32_t columnIndex, const sttp::Nullable<sttp::Guid>& value);
void SetGuidValue(const std::string& columnName, const sttp::Nullable<sttp::Guid>& value);
sttp::Nullable<int8_t> ValueAsInt8(int32_t columnIndex);
sttp::Nullable<int8_t> ValueAsInt8(const std::string& columnName);
void SetInt8Value(int32_t columnIndex, const sttp::Nullable<int8_t>& value);
void SetInt8Value(const std::string& columnName, const sttp::Nullable<int8_t>& value);
sttp::Nullable<int16_t> ValueAsInt16(int32_t columnIndex);
sttp::Nullable<int16_t> ValueAsInt16(const std::string& columnName);
void SetInt16Value(int32_t columnIndex, const sttp::Nullable<int16_t>& value);
void SetInt16Value(const std::string& columnName, const sttp::Nullable<int16_t>& value);
sttp::Nullable<int32_t> ValueAsInt32(int32_t columnIndex);
sttp::Nullable<int32_t> ValueAsInt32(const std::string& columnName);
void SetInt32Value(int32_t columnIndex, const sttp::Nullable<int32_t>& value);
void SetInt32Value(const std::string& columnName, const sttp::Nullable<int32_t>& value);
sttp::Nullable<int64_t> ValueAsInt64(int32_t columnIndex);
sttp::Nullable<int64_t> ValueAsInt64(const std::string& columnName);
void SetInt64Value(int32_t columnIndex, const sttp::Nullable<int64_t>& value);
void SetInt64Value(const std::string& columnName, const sttp::Nullable<int64_t>& value);
sttp::Nullable<uint8_t> ValueAsUInt8(int32_t columnIndex);
sttp::Nullable<uint8_t> ValueAsUInt8(const std::string& columnName);
void SetUInt8Value(int32_t columnIndex, const sttp::Nullable<uint8_t>& value);
void SetUInt8Value(const std::string& columnName, const sttp::Nullable<uint8_t>& value);
sttp::Nullable<uint16_t> ValueAsUInt16(int32_t columnIndex);
sttp::Nullable<uint16_t> ValueAsUInt16(const std::string& columnName);
void SetUInt16Value(int32_t columnIndex, const sttp::Nullable<uint16_t>& value);
void SetUInt16Value(const std::string& columnName, const sttp::Nullable<uint16_t>& value);
sttp::Nullable<uint32_t> ValueAsUInt32(int32_t columnIndex);
sttp::Nullable<uint32_t> ValueAsUInt32(const std::string& columnName);
void SetUInt32Value(int32_t columnIndex, const sttp::Nullable<uint32_t>& value);
void SetUInt32Value(const std::string& columnName, const sttp::Nullable<uint32_t>& value);
sttp::Nullable<uint64_t> ValueAsUInt64(int32_t columnIndex);
sttp::Nullable<uint64_t> ValueAsUInt64(const std::string& columnName);
void SetUInt64Value(int32_t columnIndex, const sttp::Nullable<uint64_t>& value);
void SetUInt64Value(const std::string& columnName, const sttp::Nullable<uint64_t>& value);
};
%extend DataRow {
%proxycode
%{
public DataTable Parent => _Parent();
public object this[int columnIndex]
{
get
{
switch (Parent[columnIndex].Type)
{
case DataType.String:
return ValueAsString(columnIndex);
case DataType.Boolean:
return ValueAsBoolean(columnIndex);
case DataType.DateTime:
return ValueAsDateTime(columnIndex);
case DataType.Single:
return ValueAsSingle(columnIndex);
case DataType.Double:
return ValueAsDouble(columnIndex);
case DataType.Decimal:
return ValueAsDecimal(columnIndex);
case DataType.Guid:
return ValueAsGuid(columnIndex);
case DataType.Int8:
return ValueAsInt8(columnIndex);
case DataType.Int16:
return ValueAsInt16(columnIndex);
case DataType.Int32:
return ValueAsInt32(columnIndex);
case DataType.Int64:
return ValueAsInt64(columnIndex);
case DataType.UInt8:
return ValueAsUInt8(columnIndex);
case DataType.UInt16:
return ValueAsUInt16(columnIndex);
case DataType.UInt32:
return ValueAsUInt32(columnIndex);
case DataType.UInt64:
return ValueAsUInt64(columnIndex);
default:
throw new System.ArgumentOutOfRangeException();
}
}
set
{
switch (Parent[columnIndex].Type)
{
case DataType.String:
SetStringValue(columnIndex, value.ToString());
break;
case DataType.Boolean: