home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / Util / AppPreferencesInputStream.cc next >
C/C++ Source or Header  |  2000-06-03  |  2KB  |  69 lines

  1. //
  2. //  $Id: AppPreferencesInputStream.cc,v 1.1.1.1 2000/06/02 22:23:01 sergey Exp $
  3. //
  4.  
  5. #include <Pilot.h>
  6. #include "AppPreferencesInputStream.h"
  7.  
  8.  
  9. namespace Util
  10. {
  11.     AppPreferencesInputStream::AppPreferencesInputStream():
  12.         _position(0)
  13.     {}
  14.  
  15.     AppPreferencesInputStream::~AppPreferencesInputStream()
  16.     {
  17.         close();
  18.     }
  19.  
  20.     // operations
  21.  
  22.     bool AppPreferencesInputStream::open(DWord creatorID, Word preferencesID)
  23.     {
  24.         close();
  25.  
  26.         Word size = 0;
  27.         if (PrefGetAppPreferences(creatorID, preferencesID, NULL, &size, true) != noPreferenceFound)
  28.         {
  29.             if (_buffer.allocate(size))
  30.             {
  31.                 PrefGetAppPreferences(creatorID, preferencesID, _buffer.lock(), &size, true);
  32.                 _buffer.unlock();
  33.  
  34.                 return true;
  35.             }
  36.         }
  37.  
  38.         return false;
  39.     }
  40.  
  41.     void AppPreferencesInputStream::close()
  42.     {
  43.         _position = 0;
  44.     }
  45.  
  46.     int AppPreferencesInputStream::readData(void* data, int size) const
  47.     {
  48.         if (!eof() && data != 0 && size > 0)
  49.         {
  50.             if (_position+size > _buffer.size())
  51.                 size = _buffer.size()-_position;
  52.  
  53.             MemMove(data, (Byte*)_buffer.lock()+_position, size);
  54.             _buffer.unlock();
  55.  
  56.             _position += size;
  57.             return size;
  58.         }
  59.  
  60.         return 0;
  61.     }
  62.  
  63.     bool AppPreferencesInputStream::eof() const
  64.     {
  65.         return _position >= _buffer.size();
  66.     }
  67. }
  68. // namespace Util
  69.