00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _LEMUR_KEYFILE_H
00014 #define _LEMUR_KEYFILE_H
00015 #include <string>
00016 namespace lemur
00017 {
00018 namespace file
00019 {
00020
00023 class Keyfile {
00024 public:
00026 Keyfile() : _handleSize(0), _handle(NULL) {
00027 }
00028
00031 void put( const char* key, const void* value, int valueSize );
00032
00035 void put( int key, const void* value, int valueSize );
00036
00039 bool get( const char* key, void* value, int& actualSize, int maxSize ) const;
00040
00043 bool get( const char* key, char** value, int& actualSize ) const;
00044
00047 bool get( int key, void* value, int& actualSize, int maxSize ) const;
00048
00051 bool get( int key, char** value, int& actualSize ) const;
00052
00053
00054 bool next( char* key, int& keyLength, char* value, int& valueLength );
00055 bool next( int& key, char* value, int& valueLength );
00056
00057 bool previous( char* key, int& keyLength, char* value, int& valueLength );
00058 bool previous( int& key, char* value, int& valueLength );
00059
00062 int getSize( const char* key ) const;
00063
00066 int getSize( int key ) const;
00067
00069 void remove( const char* key );
00070
00072 void remove( int key );
00073
00075 void open( const std::string& filename, int cacheSize = 1024 * 1024, bool readOnly = false);
00076
00078 void open( const char* filename, int cacheSize = 1024 * 1024, bool readOnly = false );
00079
00080 void openRead( const std::string& filename, int cacheSize = 1024 * 1024 );
00081
00083 void create( const std::string& filename, int cacheSize = 1024 * 1024 );
00084
00086 void create( const char* filename, int cacheSize = 1024 * 1024 );
00087
00089 void close();
00090
00092 void setFirst();
00093
00095 bool getNext( int& key, void* value, int& actualSize, int maxSize ) const;
00096
00098 bool getNext( char* key, int maxKeySize, void* value,
00099 int& actualSize, int maxSize ) const;
00100
00103 bool getNext( char* key, int& actKeySize, int maxKeySize, void* value,
00104 int& actualSize, int maxSize ) const;
00105
00106 enum {
00108 MAX_KEY_LENGTH = 512
00109 };
00110
00111 private:
00112 char* _handle;
00113 int _handleSize;
00114
00115 void _buildHandle( int cacheSize );
00116 void _createKey( char* keyBuf, int number ) const;
00117 int _decodeKey( char* keyBuf ) const;
00118 };
00119 }
00120 }
00121
00122 #endif // _LEMUR_KEYFILE_H