Pārlūkot izejas kodu

cmPrefs.h/c: Added cmPrefsGetUInt().

master
kevin 11 gadus atpakaļ
vecāks
revīzija
aec942c05a
2 mainītis faili ar 67 papildinājumiem un 40 dzēšanām
  1. 61
    37
      cmPrefs.c
  2. 6
    3
      cmPrefs.h

+ 61
- 37
cmPrefs.c Parādīt failu

472
   }
472
   }
473
 }
473
 }
474
 
474
 
475
-cmPrRC_t _cmPrefsValue( cmPr_t* p, const cmPrNode_t* np, const cmJsonNode_t* jnp, bool* bvp, int* ivp, double* rvp, const cmChar_t** svp, unsigned retEleCnt )
475
+cmPrRC_t _cmPrefsValue( cmPr_t* p, const cmPrNode_t* np, const cmJsonNode_t* jnp, bool* bvp, unsigned* uvp, int* ivp, double* rvp, const cmChar_t** svp, unsigned retEleCnt )
476
 {
476
 {
477
   cmJsRC_t    jsRC      = kOkJsRC;
477
   cmJsRC_t    jsRC      = kOkJsRC;
478
   const char* typeLabel = NULL;
478
   const char* typeLabel = NULL;
490
     typeLabel = "bool";
490
     typeLabel = "bool";
491
   }
491
   }
492
   else
492
   else
493
-    if( ivp != NULL )
493
+    if( uvp != NULL )
494
     {
494
     {
495
-      jsRC = cmJsonIntValue(jnp,ivp);
496
-      typeLabel = "int";
495
+      jsRC = cmJsonUIntValue(jnp,uvp);
496
+      typeLabel = "uint";
497
     }
497
     }
498
     else
498
     else
499
-      if( rvp != NULL )
499
+      if( ivp != NULL )
500
       {
500
       {
501
-        jsRC = cmJsonRealValue(jnp,rvp);
502
-        typeLabel = "real";
501
+        jsRC = cmJsonIntValue(jnp,ivp);
502
+        typeLabel = "int";
503
       }
503
       }
504
       else
504
       else
505
-        if( svp != NULL )
505
+        if( rvp != NULL )
506
         {
506
         {
507
-          jsRC = cmJsonStringValue(jnp,svp);
508
-          typeLabel = "string";
507
+          jsRC = cmJsonRealValue(jnp,rvp);
508
+          typeLabel = "real";
509
         }
509
         }
510
         else
510
         else
511
-        {
512
-          assert(0);
513
-        }
511
+          if( svp != NULL )
512
+          {
513
+            jsRC = cmJsonStringValue(jnp,svp);
514
+            typeLabel = "string";
515
+          }
516
+          else
517
+          {
518
+            assert(0);
519
+          }
514
 
520
 
515
   if( jsRC != kOkJsRC )
521
   if( jsRC != kOkJsRC )
516
   {
522
   {
522
 
528
 
523
 } 
529
 } 
524
 
530
 
525
-cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, int* ivp, double* rvp, const cmChar_t** svp, unsigned* eleCntPtr, unsigned eleIdx )
531
+// if eleCntPtr is null then assume the value is a scalar
532
+cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, unsigned* uvp, int* ivp, double* rvp, const cmChar_t** svp, unsigned* eleCntPtr, unsigned eleIdx )
526
 {
533
 {
527
   cmPrRC_t    rc = kOkPrRC;
534
   cmPrRC_t    rc = kOkPrRC;
528
   cmPr_t*     p  = _cmPrefsHandleToPtr(h);
535
   cmPr_t*     p  = _cmPrefsHandleToPtr(h);
529
   cmPrNode_t* np = NULL;
536
   cmPrNode_t* np = NULL;
537
+  unsigned    eleCnt = 1;
538
+
539
+  if( eleCntPtr != NULL )
540
+    eleCnt = *eleCntPtr;
530
 
541
 
531
   // if no return buffer was given - do nothing
542
   // if no return buffer was given - do nothing
532
-  if( *eleCntPtr == 0 )
543
+  if( eleCnt == 0 )
533
     return kOkPrRC;
544
     return kOkPrRC;
534
 
545
 
535
   // locate the pref node from 'id'
546
   // locate the pref node from 'id'
542
   // if the requested pref. var is a scalar
553
   // if the requested pref. var is a scalar
543
   if( cmJsonIsArray(np->nodePtr) == false )
554
   if( cmJsonIsArray(np->nodePtr) == false )
544
   {    
555
   {    
545
-    if((rc = _cmPrefsValue(p,np,np->nodePtr,bvp,ivp,rvp,svp,*eleCntPtr)) == kOkPrRC )
546
-      *eleCntPtr = 1;
556
+    if((rc = _cmPrefsValue(p,np,np->nodePtr,bvp,uvp,ivp,rvp,svp,eleCnt)) == kOkPrRC )
557
+    {
558
+      if( eleCntPtr != NULL )
559
+        *eleCntPtr = 1;
560
+    }
547
   }
561
   }
548
   else // the request pref. var. is an array
562
   else // the request pref. var. is an array
549
   {
563
   {
554
     if( eleIdx == cmInvalidIdx )
568
     if( eleIdx == cmInvalidIdx )
555
     {
569
     {
556
       // if the return buffer is too small to hold all of the values.
570
       // if the return buffer is too small to hold all of the values.
557
-      if( *eleCntPtr < n )
571
+      if( eleCnt < n )
558
       {
572
       {
559
-        *eleCntPtr = 0; 
573
+        if( eleCntPtr != NULL )
574
+          *eleCntPtr = 0; 
560
         _cmPrefsFormPath(p,np);
575
         _cmPrefsFormPath(p,np);
561
         rc = cmErrMsg(&p->err,kBufTooSmallPrRC,"The return array for the preference variable '%s' (id:%i) is too small to hold '%i elements",p->pathBuf,np->id,n);
576
         rc = cmErrMsg(&p->err,kBufTooSmallPrRC,"The return array for the preference variable '%s' (id:%i) is too small to hold '%i elements",p->pathBuf,np->id,n);
562
         goto errLabel;
577
         goto errLabel;
567
       {
582
       {
568
         const cmJsonNode_t* cnp = cmJsonArrayElement(np->nodePtr,i);
583
         const cmJsonNode_t* cnp = cmJsonArrayElement(np->nodePtr,i);
569
 
584
 
570
-        if((rc= _cmPrefsValue(p,np,cnp,bvp==NULL?NULL:bvp+i,ivp==NULL?NULL:ivp+i,rvp==NULL?NULL:rvp+i,svp==NULL?NULL:svp+i,1)) != kOkPrRC )
585
+        if((rc= _cmPrefsValue(p,np,cnp,bvp==NULL?NULL:bvp+i,uvp==NULL?NULL:uvp+i,ivp==NULL?NULL:ivp+i,rvp==NULL?NULL:rvp+i,svp==NULL?NULL:svp+i,1)) != kOkPrRC )
571
           goto errLabel;
586
           goto errLabel;
572
       }
587
       }
573
 
588
 
574
-      *eleCntPtr = n;
589
+      if( eleCntPtr != NULL )
590
+        *eleCntPtr = n;
575
     }
591
     }
576
     else // a single ele of the array was requested
592
     else // a single ele of the array was requested
577
     {
593
     {
589
       assert(cnp != NULL );
605
       assert(cnp != NULL );
590
 
606
 
591
       // read the element from the array
607
       // read the element from the array
592
-      if((rc = _cmPrefsValue(p,np,cnp,bvp,ivp,rvp,svp,*eleCntPtr)) == kOkPrRC )
593
-        *eleCntPtr = 1;
608
+      if((rc = _cmPrefsValue(p,np,cnp,bvp,uvp,ivp,rvp,svp,eleCnt)) == kOkPrRC )
609
+      {
610
+        if( eleCntPtr != NULL)
611
+          *eleCntPtr = 1;
612
+      }
594
       
613
       
595
     }    
614
     }    
596
   }
615
   }
597
   
616
   
598
  errLabel:
617
  errLabel:
599
   if( rc != kOkPrRC )
618
   if( rc != kOkPrRC )
600
-    *eleCntPtr = 0;
601
-
619
+  {
620
+    if( eleCntPtr != NULL )
621
+      *eleCntPtr = 0;
622
+  }
602
   return rc;
623
   return rc;
603
 }
624
 }
604
 
625
 
605
 cmPrRC_t cmPrefsGetBool(   cmPrH_t h, unsigned id, bool*  vp, unsigned* eleCntPtr )
626
 cmPrRC_t cmPrefsGetBool(   cmPrH_t h, unsigned id, bool*  vp, unsigned* eleCntPtr )
606
-{ return _cmPrefsGetValue(h, id, vp, NULL, NULL, NULL, eleCntPtr, cmInvalidIdx ); }
627
+{ return _cmPrefsGetValue(h, id, vp, NULL, NULL, NULL, NULL, eleCntPtr, cmInvalidIdx ); }
628
+
629
+cmPrRC_t cmPrefsGetUInt(    cmPrH_t h, unsigned id, unsigned*  vp, unsigned* eleCntPtr )
630
+{ return _cmPrefsGetValue(h, id, NULL, vp, NULL, NULL, NULL, eleCntPtr, cmInvalidIdx ); }
607
 
631
 
608
 cmPrRC_t cmPrefsGetInt(    cmPrH_t h, unsigned id, int*         vp, unsigned* eleCntPtr )
632
 cmPrRC_t cmPrefsGetInt(    cmPrH_t h, unsigned id, int*         vp, unsigned* eleCntPtr )
609
-{ return _cmPrefsGetValue(h, id, NULL, vp, NULL, NULL, eleCntPtr, cmInvalidIdx ); }
633
+{ return _cmPrefsGetValue(h, id, NULL, NULL, vp, NULL, NULL, eleCntPtr, cmInvalidIdx ); }
610
 
634
 
611
 cmPrRC_t cmPrefsGetReal(   cmPrH_t h, unsigned id, double*      vp, unsigned* eleCntPtr )
635
 cmPrRC_t cmPrefsGetReal(   cmPrH_t h, unsigned id, double*      vp, unsigned* eleCntPtr )
612
-{ return _cmPrefsGetValue(h, id, NULL, NULL, vp, NULL, eleCntPtr, cmInvalidIdx ); }
636
+{ return _cmPrefsGetValue(h, id, NULL, NULL, NULL, vp, NULL, eleCntPtr, cmInvalidIdx ); }
613
 
637
 
614
 cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t**  vp, unsigned* eleCntPtr )
638
 cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t**  vp, unsigned* eleCntPtr )
615
-{ return _cmPrefsGetValue(h, id, NULL, NULL, NULL, vp, eleCntPtr, cmInvalidIdx ); }
639
+{ return _cmPrefsGetValue(h, id, NULL, NULL, NULL, NULL, vp, eleCntPtr, cmInvalidIdx ); }
616
 
640
 
617
 bool            cmPrefsBool(   cmPrH_t h, unsigned id )
641
 bool            cmPrefsBool(   cmPrH_t h, unsigned id )
618
 {
642
 {
812
 {
836
 {
813
   bool     v = false;;
837
   bool     v = false;;
814
   unsigned n = 1;
838
   unsigned n = 1;
815
-  _cmPrefsGetValue(h,id, &v, NULL, NULL, NULL, &n, idx );
839
+  _cmPrefsGetValue(h,id, &v, NULL, NULL, NULL, NULL, &n, idx );
816
   return v;
840
   return v;
817
 }
841
 }
818
 
842
 
819
 unsigned        cmPrefsUIntEle(   cmPrH_t h, unsigned id, unsigned idx )
843
 unsigned        cmPrefsUIntEle(   cmPrH_t h, unsigned id, unsigned idx )
820
 {
844
 {
821
-  int      v = 0;
845
+  unsigned      v = 0;
822
   unsigned n = 1;
846
   unsigned n = 1;
823
-  _cmPrefsGetValue(h,id, NULL, &v, NULL, NULL, &n, idx );
824
-  return (unsigned)v;
847
+  _cmPrefsGetValue(h,id, NULL, &v, NULL, NULL, NULL, &n, idx );
848
+  return v;
825
 }
849
 }
826
 
850
 
827
 int             cmPrefsIntEle(    cmPrH_t h, unsigned id, unsigned idx )
851
 int             cmPrefsIntEle(    cmPrH_t h, unsigned id, unsigned idx )
828
 {
852
 {
829
   int      v = 0;
853
   int      v = 0;
830
   unsigned n = 1;
854
   unsigned n = 1;
831
-  _cmPrefsGetValue(h,id, NULL, &v, NULL, NULL, &n, idx );
855
+  _cmPrefsGetValue(h,id, NULL, NULL, &v, NULL, NULL, &n, idx );
832
   return v;
856
   return v;
833
 }
857
 }
834
 
858
 
836
 {
860
 {
837
   double   v = 0;
861
   double   v = 0;
838
   unsigned n = 1;
862
   unsigned n = 1;
839
-  _cmPrefsGetValue(h,id, NULL, NULL, &v, NULL, &n, idx );
863
+  _cmPrefsGetValue(h,id, NULL, NULL, NULL, &v, NULL, &n, idx );
840
   return (float)v;
864
   return (float)v;
841
 }
865
 }
842
 
866
 
844
 {
868
 {
845
   double   v = 0;
869
   double   v = 0;
846
   unsigned n = 1;
870
   unsigned n = 1;
847
-  _cmPrefsGetValue(h,id, NULL, NULL, &v, NULL, &n, idx );
871
+  _cmPrefsGetValue(h,id, NULL, NULL, NULL, &v, NULL, &n, idx );
848
   return v;
872
   return v;
849
 }
873
 }
850
 
874
 
852
 {
876
 {
853
   const cmChar_t* v = "";
877
   const cmChar_t* v = "";
854
   unsigned        n = 1;
878
   unsigned        n = 1;
855
-  if( _cmPrefsGetValue(h,id, NULL, NULL, NULL, &v, &n, idx ) == kOkPrRC )
879
+  if( _cmPrefsGetValue(h,id, NULL, NULL, NULL, NULL, &v, &n, idx ) == kOkPrRC )
856
     return v;
880
     return v;
857
   return "";
881
   return "";
858
 }
882
 }

+ 6
- 3
cmPrefs.h Parādīt failu

65
   // is associated with id.  Returns 1 if the variable is a scalar.
65
   // is associated with id.  Returns 1 if the variable is a scalar.
66
   unsigned cmPrefsEleCount( cmPrH_t h,  unsigned id );
66
   unsigned cmPrefsEleCount( cmPrH_t h,  unsigned id );
67
 
67
 
68
-  // On input *'eleCntPtr' must contain the number of elements in the buffer pointed to by 'vp'.
69
-  // On return *'eleCntPtr' contains the actuall number of elements returned by the function.
70
-  // Set *eleCntPtr to 1 for scalar a values.
68
+  // On input *'eleCntPtr' must contain the number of elements in the buffer 
69
+  // pointed to by 'vp' or NULL if '*vp' is a scalar.
70
+  // On return *'eleCntPtr' contains the actual number of elements 
71
+  // returned by the function.  
72
+  // Set eleCntPtr to NULL for scalar a values.
71
   cmPrRC_t cmPrefsGetBool(   cmPrH_t h, unsigned id, bool*            vp, unsigned* eleCntPtr );
73
   cmPrRC_t cmPrefsGetBool(   cmPrH_t h, unsigned id, bool*            vp, unsigned* eleCntPtr );
74
+  cmPrRC_t cmPrefsGetUInt(   cmPrH_t h, unsigned id, unsigned*        vp, unsigned* eleCntPtr );
72
   cmPrRC_t cmPrefsGetInt(    cmPrH_t h, unsigned id, int*             vp, unsigned* eleCntPtr );
75
   cmPrRC_t cmPrefsGetInt(    cmPrH_t h, unsigned id, int*             vp, unsigned* eleCntPtr );
73
   cmPrRC_t cmPrefsGetReal(   cmPrH_t h, unsigned id, double*          vp, unsigned* eleCntPtr );
76
   cmPrRC_t cmPrefsGetReal(   cmPrH_t h, unsigned id, double*          vp, unsigned* eleCntPtr );
74
   cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t** vp, unsigned* eleCntPtr );
77
   cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t** vp, unsigned* eleCntPtr );

Notiek ielāde…
Atcelt
Saglabāt