00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _LEMUR_KEYFILE_H
00014 #define _LEMUR_KEYFILE_H
00015
00018 class Keyfile {
00019 public:
00021 Keyfile() : _handleSize(0), _handle(NULL) {
00022 }
00023
00026 void put( const char* key, const void* value, int valueSize );
00027
00030 void put( int key, const void* value, int valueSize );
00031
00034 bool get( const char* key, void* value, int& actualSize, int maxSize ) const;
00035
00038 bool get( const char* key, char** value, int& actualSize ) const;
00039
00042 bool get( int key, void* value, int& actualSize, int maxSize ) const;
00043
00046 bool get( int key, char** value, int& actualSize ) const;
00047
00048
00049 bool next( char* key, int& keyLength, char* value, int& valueLength );
00050 bool next( int& key, char* value, int& valueLength );
00051
00052 bool previous( char* key, int& keyLength, char* value, int& valueLength );
00053 bool previous( int& key, char* value, int& valueLength );
00054
00057 int getSize( const char* key ) const;
00058
00061 int getSize( int key ) const;
00062
00064 void remove( const char* key );
00065
00067 void remove( int key );
00068
00070 void open( const std::string& filename, int cacheSize = 1024 * 1024, bool readOnly = false);
00071
00073 void open( const char* filename, int cacheSize = 1024 * 1024, bool readOnly = false );
00074
00075 void openRead( const std::string& filename, int cacheSize = 1024 * 1024 );
00076
00078 void create( const std::string& filename, int cacheSize = 1024 * 1024 );
00079
00081 void create( const char* filename, int cacheSize = 1024 * 1024 );
00082
00084 void close();
00085
00087 void setFirst();
00088
00090 bool getNext( int& key, void* value, int& actualSize, int maxSize ) const;
00091
00093 bool getNext( char* key, int maxKeySize, void* value,
00094 int& actualSize, int maxSize ) const;
00095
00098 bool getNext( char* key, int& actKeySize, int maxKeySize, void* value,
00099 int& actualSize, int maxSize ) const;
00100
00101 enum {
00103 MAX_KEY_LENGTH = 512
00104 };
00105
00106 private:
00107 char* _handle;
00108 int _handleSize;
00109
00110 void _buildHandle( int cacheSize );
00111 void _createKey( char* keyBuf, int number ) const;
00112 int _decodeKey( char* keyBuf ) const;
00113 };
00114
00115 #endif // _LEMUR_KEYFILE_H