-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfigdb.h
More file actions
1859 lines (1506 loc) · 41.2 KB
/
configdb.h
File metadata and controls
1859 lines (1506 loc) · 41.2 KB
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
/*
* =====================================================================================
*
* Filename: configdb.h
*
* Description: declaration of the IConfigDb and CConfigDb
*
* Version: 1.0
* Created: 07/21/2016 09:46:29 PM
* Revision: none
* Compiler: gcc
*
* Author: Ming Zhi( woodhead99@gmail.com )
* Organization:
*
* Copyright: 2019 Ming Zhi( woodhead99@gmail.com )
*
* License: Licensed under GPL-3.0. You may not use this file except in
* compliance with the License. You may find a copy of the
* License at 'http://www.gnu.org/licenses/gpl-3.0.html'
*
* =====================================================================================
*/
#pragma once
#include <arpa/inet.h>
#include "autoptr.h"
#include "buffer.h"
#include <stdexcept>
#include <unordered_map>
#include "variant.h"
// NOTE:
// changed back to std::map. Because usually the
// map element is less than 20, it should be ok to
// use std::map without performance loss. and
// keeping the order is important for generating
// the same hash across different platform.
#define hashmap unordered_map
namespace rpcf
{
class CIoManager;
class IConfigDb : public CObjBase
{
public:
typedef CObjBase super;
virtual gint32 RemoveProperty( gint32 iProp ) = 0;
virtual void RemoveAll() = 0;
virtual gint32 size() const = 0;
virtual bool exist( gint32 iProp ) const = 0;
virtual const IConfigDb& operator=( const IConfigDb& oCfg ) = 0;
virtual gint32 SetProperty( gint32 iProp, const BufPtr& pBuf ) = 0;
virtual gint32 GetProperty( gint32 iProp, BufPtr& pBuf ) const = 0;
virtual gint32 SetProperty( gint32 iProp, const Variant& oVar ) = 0;
virtual gint32 GetProperty( gint32 iProp, Variant& oVar ) const = 0;
// defined in CObjBase
virtual gint32 GetProperty( gint32 iProp, CBuffer& oBuf ) const = 0;
virtual gint32 SetProperty( gint32 iProp, const CBuffer& oProp ) = 0;
virtual gint32 GetPropertyType( gint32 iProp, gint32& iType ) const = 0;
// more helpers
virtual gint32 Clone( const IConfigDb& oCfg ) = 0;
};
// typedef CAutoPtr< clsid( CConfigDb2 ), IConfigDb > CfgPtr;
class CConfigDb2 : public IConfigDb
{
protected:
std::hashmap<gint32, Variant> m_mapProps;
public:
typedef IConfigDb super;
struct SERI_HEADER : public SERI_HEADER_BASE
{
typedef SERI_HEADER_BASE super;
guint32 dwCount;
SERI_HEADER() : SERI_HEADER_BASE()
{
dwClsid = clsid( CConfigDb2 );
dwCount = 0;
}
SERI_HEADER( const SERI_HEADER& rhs )
:SERI_HEADER_BASE( rhs )
{
dwCount = rhs.dwCount;
}
SERI_HEADER& operator=( const SERI_HEADER& rhs )
{
super::operator=( rhs );
dwCount = rhs.dwCount;
return *this;
}
void ntoh()
{
super::ntoh();
dwCount = ntohl( dwCount );
}
void hton()
{
super::hton();
dwCount = htonl( dwCount );
}
};
CConfigDb2( const IConfigDb* pCfg = nullptr );
~CConfigDb2();
// get a reference to pBuf content from the config db
gint32 GetProperty( gint32 iProp, BufPtr& pBuf ) const;
// add a reference to pBuf content to the config db
gint32 SetProperty( gint32 iProp, const BufPtr& pBuf );
// make a copy of oBuf content from the config db
gint32 GetProperty( gint32, CBuffer& oBuf ) const;
// add a copy of oBuf content to the config db
gint32 SetProperty( gint32, const CBuffer& oBuf );
gint32 GetPropertyType( gint32 iProp, gint32& iType ) const;
gint32 RemoveProperty( gint32 iProp );
void RemoveAll();
// get a reference to variant from the config db
gint32 GetProperty(
gint32 iProp, Variant& oVar ) const override;
// add a reference to variant to the config db
gint32 SetProperty(
gint32 iProp, const Variant& oVar ) override;
// get a reference to variant from the config db
const Variant& GetProperty( gint32 iProp ) const;
Variant& GetProperty( gint32 iProp );
const Variant* GetPropertyPtr( gint32 iProp ) const;
Variant* GetPropertyPtr( gint32 iProp );
gint32 GetPropIds( std::vector<gint32>& vecIds ) const;
virtual gint32 Deserialize( const CBuffer& oBuf );
gint32 Serialize( CBuffer& oBuf ) const override;
gint32 Deserialize( const char* oBuf, guint32 dwSize ) override;
gint32 size() const;
bool exist( gint32 iProp ) const;
const IConfigDb& operator=( const IConfigDb& oCfg );
gint32 Clone( const IConfigDb& oCfg );
virtual gint32 EnumProperties(
std::vector< gint32 >& vecProps ) const;
};
template< class T1, typename T=
typename std::enable_if< std::is_base_of< CObjBase, T1 >::value, T1 >::type >
class CCfgDbOpener
{
private:
ObjPtr m_pObjGuard;
protected:
T* m_pCfg;
const T* m_pConstCfg;
public:
CCfgDbOpener( const T* pObj )
{
m_pCfg = nullptr;
m_pConstCfg = nullptr;
if( pObj == nullptr )
{
return;
}
m_pConstCfg = pObj;
m_pCfg = nullptr;
m_pObjGuard = const_cast< T* >( pObj );
}
CCfgDbOpener( T* pObj ) :
CCfgDbOpener( ( const T* )pObj )
{
m_pCfg = pObj;
}
inline gint32 GetProperty(
gint32 iProp, CBuffer& oBuf ) const
{
BufPtr pBuf;
gint32 ret = GetProperty( iProp, pBuf );
if( ERROR( ret ) )
return ret;
oBuf = *pBuf;
return 0;
}
inline gint32 SetProperty(
gint32 iProp, const CBuffer& oBuf )
{
Variant oVar( oBuf );
return m_pCfg->SetProperty( iProp, oVar );
}
inline gint32 GetProperty(
gint32 iProp, BufPtr& pBuf ) const
{
Variant oVar;
gint32 ret = GetProperty( iProp, oVar );
if( ERROR( ret ) )
return ret;
pBuf = oVar.ToBuf();
return 0;
}
inline gint32 SetProperty(
gint32 iProp, const BufPtr& pBuf )
{
Variant oVar( *pBuf );
return m_pCfg->SetProperty( iProp, oVar );
}
inline gint32 GetProperty(
gint32 iProp, Variant& oBuf ) const
{
if( m_pConstCfg == nullptr )
return -EFAULT;
return m_pConstCfg->GetProperty( iProp, oBuf );
}
inline gint32 SetProperty(
gint32 iProp, const Variant& oBuf )
{
if( m_pCfg == nullptr )
return -EFAULT;
return m_pCfg->SetProperty( iProp, oBuf );
}
template< class U, typename U1=
class std::enable_if< std::is_base_of< CObjBase, U >::value, U >::type >
gint32 GetPointer( gint32 iProp, U*& pObj ) const
{
gint32 ret = 0;
do{
ObjPtr objPtr;
ret = GetObjPtr( iProp, objPtr );
if( ERROR( ret ) )
break;
pObj = objPtr;
}while( 0 );
return ret;
}
template< class U, typename U1=
class std::enable_if< std::is_base_of< CObjBase, U >::value, U >::type >
gint32 SetPointer( gint32 iProp, U* pObj )
{
gint32 ret = 0;
do{
ObjPtr objPtr( pObj );
ret = SetObjPtr( iProp, objPtr );
}while( 0 );
return ret;
}
gint32 GetObjPtr( gint32 iProp, ObjPtr& pObj ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
do{
Variant oVar;
ret = m_pConstCfg->GetProperty(
iProp, oVar );
if( ERROR( ret ) )
break;
try{
pObj = ( ObjPtr& )oVar;
}
catch( std::invalid_argument& e )
{
ret = -EINVAL;
}
}while( 0 );
return ret;
}
gint32 SetObjPtr( gint32 iProp, const ObjPtr& pObj )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
Variant oVar( pObj );
if( pObj.IsEmpty() )
oVar.Clear();
ret = m_pCfg->SetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
}while( 0 );
return ret;
}
gint32 GetStrProp( gint32 iProp, std::string& strVal ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
do{
Variant oVar;
ret = m_pConstCfg->GetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
strVal = ( stdstr& )oVar;
}while( 0 );
return ret;
}
gint32 SetStrProp( gint32 iProp, const std::string& strVal )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
Variant oVar( strVal );
ret = m_pCfg->SetProperty( iProp, oVar );
}while( 0 );
return ret;
}
gint32 GetStringProp( gint32 iProp, const char*& pStr ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
do{
Variant oVar;
ret = m_pConstCfg->GetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
pStr = ( const char* )oVar;
}while( 0 );
return ret;
}
gint32 GetMsgPtr( gint32 iProp, DMsgPtr& pMsg ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
do{
Variant oVar;
ret = m_pConstCfg->GetProperty(
iProp, oVar );
if( ERROR( ret ) )
break;
try{
pMsg = ( DMsgPtr& )oVar;
}
catch( std::invalid_argument& e )
{
ret = -EINVAL;
}
}while( 0 );
return ret;
}
gint32 SetMsgPtr( gint32 iProp, const DMsgPtr& pMsg )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
Variant oVar( pMsg );
ret = m_pCfg->SetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
}while( 0 );
return ret;
}
gint32 CopyProp( gint32 iProp, gint32 iSrcProp,
const CObjBase* pSrcCfg )
{
if( pSrcCfg == nullptr )
return -EINVAL;
CCfgDbOpener< CObjBase > a( pSrcCfg );
Variant oVar;
gint32 ret = a.GetProperty( iSrcProp, oVar );
if( ERROR( ret ) )
return ret;
return SetProperty( iProp, oVar );
}
gint32 CopyProp( gint32 iProp, const CObjBase* pSrcCfg )
{ return CopyProp( iProp, iProp, pSrcCfg ); }
gint32 MoveProp( gint32 iProp, CObjBase* pSrcCfg )
{
if( pSrcCfg == nullptr )
return -EINVAL;
gint32 ret = CopyProp( iProp, pSrcCfg );
if( ERROR( ret ) )
return ret;
ret = pSrcCfg->RemoveProperty( iProp );
return ret;
}
gint32 SwapProp( gint32 iProp1, gint32 iProp2 )
{
Variant oVar1, oVar2;
gint32 ret = GetProperty( iProp1, oVar1 );
if( ERROR( ret ) )
return ret;
ret = GetProperty( iProp2, oVar2 );
if( ERROR( ret ) )
return ret;
SetProperty( iProp1, oVar2 );
SetProperty( iProp2, oVar1 );
return ret;
}
template< typename PrimType >
gint32 GetPrimProp( gint32 iProp, PrimType& val ) const
{
gint32 ret = 0;
if( unlikely( m_pConstCfg == nullptr ) )
return -EFAULT;
do{
Variant oVar;
ret = m_pConstCfg->GetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
val = ( PrimType& )oVar;
}while( 0 );
return ret;
}
template< typename PrimType >
gint32 SetPrimProp( gint32 iProp, PrimType val )
{
gint32 ret = 0;
do{
if( unlikely( m_pCfg == nullptr ) )
{
ret = -EFAULT;
break;
}
Variant oVar;
oVar = val;
ret = m_pCfg->SetProperty( iProp, oVar );
if( ERROR( ret ) )
break;
}while( 0 );
return ret;
}
gint32 GetIntPtr( gint32 iProp, guint32*& val ) const
{
intptr_t val1;
Variant oVar;
gint32 ret = GetProperty( iProp, oVar );
if( ERROR( ret ) )
return ret;
val1 = oVar;
val = ( guint32* )val1;
return 0;
}
gint32 SetIntPtr( gint32 iProp, guint32* val )
{
Variant oVar;
oVar = ( intptr_t )val;
return SetProperty( iProp, oVar );
}
gint32 GetShortProp( gint32 iProp, guint16& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetShortProp( gint32 iProp, guint16 val )
{
return SetPrimProp( iProp, val );
}
gint32 GetIntProp( gint32 iProp, guint32& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetIntProp( gint32 iProp, guint32 val )
{
return SetPrimProp( iProp, val );
}
gint32 GetBoolProp( gint32 iProp, bool& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetBoolProp( gint32 iProp, bool val )
{
return SetPrimProp( iProp, val );
}
gint32 GetByteProp( gint32 iProp, guint8& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetByteProp( gint32 iProp, guint8 val )
{
return SetPrimProp( iProp, val );
}
gint32 GetFloatProp( gint32 iProp, float& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetFloatProp( gint32 iProp, float val )
{
return SetIntProp( iProp, val );
}
gint32 GetQwordProp( gint32 iProp, guint64& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetQwordProp( gint32 iProp, guint64 val )
{
return SetPrimProp( iProp, val );
}
gint32 GetDoubleProp( gint32 iProp, double& val ) const
{
return GetPrimProp( iProp, val );
}
gint32 SetDoubleProp( gint32 iProp, double val )
{
return SetPrimProp( iProp, val );
}
template< typename PrimType >
gint32 IsEqual( gint32 iProp, const PrimType& val )
{
// c++11 required
// static_assert( !std::is_base_of< CObjBase, PrimType >::value );
gint32 ret = 0;
do{
if( m_pConstCfg== nullptr )
{
ret = -EFAULT;
break;
}
Variant oVar1, oVar2;
ret = m_pConstCfg->GetProperty( iProp, oVar1 );
if( ERROR( ret ) )
break;
oVar2 = val;
if( oVar2 == oVar1 )
break;
ret = ERROR_FALSE;
}while( 0 );
return ret;
}
gint32 IsEqualProp( gint32 iProp, const CObjBase* pObj )
{
gint32 ret = 0;
do{
if( pObj == nullptr )
{
ret = -EINVAL;
break;
}
if( m_pConstCfg == nullptr )
{
ret = -EFAULT;
break;
}
Variant oVar1, oVar2;
ret = pObj->GetProperty( iProp, oVar1 );
if( ERROR( ret ) )
break;
ret = this->GetProperty( iProp, oVar2 );
if( ERROR( ret ) )
break;
if( oVar1 == oVar2 )
break;
ret = ERROR_FALSE;
}while( 0 );
return ret;
}
};
// template<> class CCfgDbOpener< CObjBase >;
#define CFGDB2( _pCfg ) \
static_cast< CConfigDb2* >( _pCfg )
#define CCFGDB2( _pCfg ) \
static_cast< const CConfigDb2* const >( _pCfg )
template<>
class CCfgDbOpener< IConfigDb >
{
protected:
IConfigDb* m_pCfg;
const IConfigDb* m_pConstCfg;
template< typename PrimType, typename T2=
typename std::enable_if< !std::is_same< PrimType, stdstr >::value, PrimType >::type >
gint32 GetPrimProp( gint32 iProp, PrimType& val ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
auto pdb2 = CCFGDB2( m_pConstCfg );
do{
const Variant* p =
pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -ENOENT;
break;
}
val = *p;
}while( 0 );
return ret;
}
template< typename PrimType, typename T2=
typename std::enable_if< std::is_same<
PrimType, stdstr >::value, PrimType >::type,
typename T3=T2 >
gint32 GetPrimProp(
gint32 iProp, PrimType& val ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
auto pdb2 = CCFGDB2( m_pConstCfg );
do{
const Variant* p =
pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -ENOENT;
break;
}
val = *p;
}while( 0 );
return ret;
}
template< typename PrimType >
gint32 SetPrimProp( gint32 iProp, PrimType val )
{
gint32 ret = 0;
auto pdb2 = CFGDB2( m_pCfg );
do{
Variant& o =
pdb2->GetProperty( iProp );
o = val;
}while( 0 );
return ret;
}
public:
CCfgDbOpener( const IConfigDb* pObj )
: m_pCfg( nullptr ),
m_pConstCfg( nullptr )
{
if( pObj == nullptr )
return;
m_pConstCfg = pObj;
}
CCfgDbOpener( IConfigDb* pObj ) :
CCfgDbOpener( ( const IConfigDb* )pObj )
{
if( pObj == nullptr )
return;
m_pCfg = pObj;
}
inline gint32 GetProperty(
gint32 iProp, BufPtr& pBuf ) const
{
if( m_pConstCfg == nullptr )
return -EFAULT;
return m_pConstCfg->GetProperty( iProp, pBuf );
}
inline gint32 SetProperty(
gint32 iProp, const BufPtr& pBuf )
{
if( m_pCfg == nullptr )
return -EFAULT;
return m_pCfg->SetProperty( iProp, pBuf );
}
inline gint32 GetProperty(
gint32 iProp, CBuffer& oBuf ) const
{
if( m_pConstCfg == nullptr )
return -EFAULT;
return m_pConstCfg->GetProperty( iProp, oBuf );
}
inline gint32 SetProperty(
gint32 iProp, const CBuffer& oBuf )
{
if( m_pCfg == nullptr )
return -EFAULT;
return m_pCfg->SetProperty( iProp, oBuf );
}
inline gint32 GetProperty(
gint32 iProp, Variant& oVar ) const
{
auto pdb2 = CCFGDB2( m_pConstCfg );
return pdb2->GetProperty( iProp, oVar );
}
inline gint32 SetProperty(
gint32 iProp, const Variant& oVar )
{
auto pdb2 = CFGDB2( m_pCfg );
return pdb2->SetProperty( iProp, oVar );
}
inline const Variant* GetPropPtr( gint32 iProp ) const
{
auto pdb2 = CCFGDB2( m_pConstCfg );
return pdb2->GetPropertyPtr( iProp );
}
inline Variant* GetPropPtr( gint32 iProp )
{
auto pdb2 = CFGDB2( m_pCfg );
return pdb2->GetPropertyPtr( iProp );
}
inline const Variant& operator[]( gint32 iProp ) const
{
auto pdb2 = CCFGDB2( m_pConstCfg );
return pdb2->GetProperty( iProp );
}
inline Variant& operator[]( gint32 iProp )
{
auto pdb2 = CFGDB2( m_pCfg );
return pdb2->GetProperty( iProp );
}
gint32 GetObjPtr( gint32 iProp, ObjPtr& pObj ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
auto pdb2 = CCFGDB2( m_pConstCfg );
do{
const Variant* p;
p = pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -ENOENT;
break;
}
if( p->GetTypeId() != typeObj )
{
ret = -EFAULT;
break;
}
pObj = ( const ObjPtr& )*p;
}while( 0 );
return ret;
}
gint32 SetObjPtr( gint32 iProp, const ObjPtr& pObj )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
auto pdb2 = CFGDB2( m_pCfg );
Variant& o = pdb2->GetProperty( iProp );
o = pObj;
}while( 0 );
return ret;
}
gint32 GetBufPtr( gint32 iProp, BufPtr& pBuf ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
auto pdb2 = CCFGDB2( m_pConstCfg );
do{
const Variant* p;
p = pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -ENOENT;
break;
}
if( p->GetTypeId() != typeByteArr )
{
ret = -EFAULT;
break;
}
pBuf = ( const BufPtr& )*p;
}while( 0 );
return ret;
}
inline gint32 SetBufPtr( gint32 iProp, const BufPtr& pBuf )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
auto pdb2 = CFGDB2( m_pCfg );
Variant& o = pdb2->GetProperty( iProp );
o = pBuf;
}while( 0 );
return ret;
}
gint32 GetStrProp( gint32 iProp, std::string& strVal ) const
{
gint32 ret = 0;
if( m_pConstCfg == nullptr )
return -EFAULT;
do{
auto pdb2 = CCFGDB2( m_pConstCfg );
const Variant* p =
pdb2->GetPropertyPtr( iProp );
if( p == nullptr )
{
ret = -ENOENT;
break;
}
if( p->GetTypeId() != typeString )
{
ret = -EFAULT;
break;
}
strVal = ( const stdstr& )*p;
}while( 0 );
return ret;
}
gint32 SetStrProp( gint32 iProp, const std::string& strVal )
{
gint32 ret = 0;
do{
if( m_pCfg == nullptr )
{
ret = -EFAULT;
break;
}
auto pdb2 = CFGDB2( m_pCfg );
Variant& o = pdb2->GetProperty( iProp );
o = strVal;
}while( 0 );