home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / CardRecord.cc < prev    next >
C/C++ Source or Header  |  2000-06-10  |  2KB  |  96 lines

  1. //
  2. //  $Id: CardRecord.cc,v 1.5 2000/06/10 00:19:40 sergey Exp $
  3. //
  4.  
  5. #include <Pilot.h>
  6. #include "CardRecord.h"
  7. #include "DB/ResourceDatabase.h"
  8. #include "Util/Assert.h"
  9.  
  10.  
  11. // constants
  12.  
  13. const int FIRST_RECORD_ID   = 5000;         // Resource id of the first Card record. First part for app resources, second - for the cards
  14. const int RECORD_ID_STEP    = 10;           // Distance between two sequential records.
  15.  
  16. const int NAME_ID_OFFSET        = 0;
  17. const int SCRIPT_ID_OFFSET      = 1;
  18. const int IMAGE_ID_OFFSET       = 2;
  19. const int LIB_SCRIPT_ID_OFFSET  = 3;
  20.  
  21.  
  22. // construction
  23.  
  24. CardRecord::CardRecord()
  25. {}
  26.  
  27. CardRecord::~CardRecord()
  28. {}
  29.  
  30. // operations
  31.  
  32. bool CardRecord::load(int recordIndex, const DB::ResourceDatabase& cardDb)
  33. {
  34.     int id = FIRST_RECORD_ID+recordIndex*RECORD_ID_STEP;
  35.  
  36.     if (!cardDb.readResource(strRsc, id+NAME_ID_OFFSET, _name))
  37.         return false;
  38.  
  39.     if (!cardDb.readResource(strRsc, id+SCRIPT_ID_OFFSET, _script))
  40.         return false;
  41.  
  42.     loadImage(cardDb, id);
  43.  
  44.     if (!loadLibScript(cardDb, id))
  45.         return false;
  46.  
  47.     return true;
  48. }
  49.  
  50. // utilities
  51.  
  52. int CardRecord::countRecords(const DB::ResourceDatabase& cardDb)
  53. {
  54.     // Find all sequential Card records starting from the first one.
  55.  
  56.     int count = 0;
  57.     for (int id = FIRST_RECORD_ID; cardDb.findResource(strRsc, id) != -1; id += RECORD_ID_STEP)
  58.         ++count;
  59.  
  60.     return count;
  61. }
  62.  
  63. // implementation
  64.  
  65. void CardRecord::loadImage(const DB::ResourceDatabase& cardDb, int cardID)
  66. {
  67.     // image could be absend
  68.     if (cardDb.findResource(bitmapRsc, cardID+IMAGE_ID_OFFSET) != -1)
  69.         cardDb.readResource(bitmapRsc, cardID+IMAGE_ID_OFFSET, _image);
  70.     else
  71.         _image = BitmapResource();
  72. }
  73.  
  74. bool CardRecord::loadLibScript(const DB::ResourceDatabase& cardDb, int cardID)
  75. {
  76.     // not all cards needs the library script
  77.     if (cardDb.findResource(strRsc, cardID+LIB_SCRIPT_ID_OFFSET) != -1)
  78.     {
  79.         StringResource libScriptID;
  80.  
  81.         if (cardDb.readResource(strRsc, cardID+LIB_SCRIPT_ID_OFFSET, libScriptID))
  82.         {
  83.             if (cardDb.readResource(strRsc, StrAToI(libScriptID.data()), _libScript))
  84.                 return true;
  85.         }
  86.         return true;
  87.     }
  88.     else
  89.     {
  90.         _libScript = StringResource();
  91.         return true;
  92.     }
  93.  
  94.     return false;
  95. }
  96.