浏览代码

cmPrefs.h/c: Added cmPrefsGetUInt().

master
kevin 11 年前
父节点
当前提交
aec942c05a
共有 2 个文件被更改,包括 67 次插入40 次删除
  1. 61
    37
      cmPrefs.c
  2. 6
    3
      cmPrefs.h

+ 61
- 37
cmPrefs.c 查看文件

@@ -472,7 +472,7 @@ void _cmPrefsFormPath( cmPr_t* p, const cmPrNode_t* np )
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 477
   cmJsRC_t    jsRC      = kOkJsRC;
478 478
   const char* typeLabel = NULL;
@@ -490,27 +490,33 @@ cmPrRC_t _cmPrefsValue( cmPr_t* p, const cmPrNode_t* np, const cmJsonNode_t* jnp
490 490
     typeLabel = "bool";
491 491
   }
492 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 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 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 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 521
   if( jsRC != kOkJsRC )
516 522
   {
@@ -522,14 +528,19 @@ cmPrRC_t _cmPrefsValue( cmPr_t* p, const cmPrNode_t* np, const cmJsonNode_t* jnp
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 534
   cmPrRC_t    rc = kOkPrRC;
528 535
   cmPr_t*     p  = _cmPrefsHandleToPtr(h);
529 536
   cmPrNode_t* np = NULL;
537
+  unsigned    eleCnt = 1;
538
+
539
+  if( eleCntPtr != NULL )
540
+    eleCnt = *eleCntPtr;
530 541
 
531 542
   // if no return buffer was given - do nothing
532
-  if( *eleCntPtr == 0 )
543
+  if( eleCnt == 0 )
533 544
     return kOkPrRC;
534 545
 
535 546
   // locate the pref node from 'id'
@@ -542,8 +553,11 @@ cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, int* ivp, double*
542 553
   // if the requested pref. var is a scalar
543 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 562
   else // the request pref. var. is an array
549 563
   {
@@ -554,9 +568,10 @@ cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, int* ivp, double*
554 568
     if( eleIdx == cmInvalidIdx )
555 569
     {
556 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 575
         _cmPrefsFormPath(p,np);
561 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 577
         goto errLabel;
@@ -567,11 +582,12 @@ cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, int* ivp, double*
567 582
       {
568 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 586
           goto errLabel;
572 587
       }
573 588
 
574
-      *eleCntPtr = n;
589
+      if( eleCntPtr != NULL )
590
+        *eleCntPtr = n;
575 591
     }
576 592
     else // a single ele of the array was requested
577 593
     {
@@ -589,30 +605,38 @@ cmPrRC_t _cmPrefsGetValue( cmPrH_t h, unsigned id, bool* bvp, int* ivp, double*
589 605
       assert(cnp != NULL );
590 606
 
591 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 617
  errLabel:
599 618
   if( rc != kOkPrRC )
600
-    *eleCntPtr = 0;
601
-
619
+  {
620
+    if( eleCntPtr != NULL )
621
+      *eleCntPtr = 0;
622
+  }
602 623
   return rc;
603 624
 }
604 625
 
605 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 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 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 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 641
 bool            cmPrefsBool(   cmPrH_t h, unsigned id )
618 642
 {
@@ -812,23 +836,23 @@ bool            cmPrefsBoolEle(   cmPrH_t h, unsigned id, unsigned idx )
812 836
 {
813 837
   bool     v = false;;
814 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 840
   return v;
817 841
 }
818 842
 
819 843
 unsigned        cmPrefsUIntEle(   cmPrH_t h, unsigned id, unsigned idx )
820 844
 {
821
-  int      v = 0;
845
+  unsigned      v = 0;
822 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 851
 int             cmPrefsIntEle(    cmPrH_t h, unsigned id, unsigned idx )
828 852
 {
829 853
   int      v = 0;
830 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 856
   return v;
833 857
 }
834 858
 
@@ -836,7 +860,7 @@ float           cmPrefsFloatEle(  cmPrH_t h, unsigned id, unsigned idx )
836 860
 {
837 861
   double   v = 0;
838 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 864
   return (float)v;
841 865
 }
842 866
 
@@ -844,7 +868,7 @@ double          cmPrefsRealEle(   cmPrH_t h, unsigned id, unsigned idx )
844 868
 {
845 869
   double   v = 0;
846 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 872
   return v;
849 873
 }
850 874
 
@@ -852,7 +876,7 @@ const cmChar_t* cmPrefsStringEle( cmPrH_t h, unsigned id, unsigned idx )
852 876
 {
853 877
   const cmChar_t* v = "";
854 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 880
     return v;
857 881
   return "";
858 882
 }

+ 6
- 3
cmPrefs.h 查看文件

@@ -65,10 +65,13 @@ extern "C" {
65 65
   // is associated with id.  Returns 1 if the variable is a scalar.
66 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 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 75
   cmPrRC_t cmPrefsGetInt(    cmPrH_t h, unsigned id, int*             vp, unsigned* eleCntPtr );
73 76
   cmPrRC_t cmPrefsGetReal(   cmPrH_t h, unsigned id, double*          vp, unsigned* eleCntPtr );
74 77
   cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t** vp, unsigned* eleCntPtr );

正在加载...
取消
保存