00001 /* Copyright (C) 2010 webis.de 00002 * All rights reserved. 00003 */ 00004 #ifndef AITOOLS_INVERTEDINDEX_GENERIC_RECORD_HPP 00005 #define AITOOLS_INVERTEDINDEX_GENERIC_RECORD_HPP 00006 00007 #include "ByteBuffer.hpp" 00008 #include <stdint.h> 00009 #include <string> 00010 00011 namespace aitools { 00012 namespace invertedindex { 00013 00024 class GenericRecord { 00025 00026 private: // nested types 00027 00028 typedef uint16_t key_size_t; 00029 typedef uint16_t val_size_t; 00030 00031 public: // class data 00032 00033 static const size_t max_key_size; 00034 static const size_t max_val_size; 00035 00036 private: // class data 00037 00038 static const size_t sizeof_key_size_t = sizeof(key_size_t); 00039 static const size_t sizeof_val_size_t = sizeof(val_size_t); 00040 00041 public: // c'tor / d'tor 00042 00043 GenericRecord(); 00044 00045 GenericRecord(const GenericRecord& record); 00046 00047 GenericRecord(const std::string& key, const ByteBuffer& value); 00048 00049 ~GenericRecord(); 00050 00051 public: // member 00052 00053 std::string& key(); 00054 00055 const std::string& key() const; 00056 00057 GenericRecord& operator=(const GenericRecord& record); 00058 00059 bool operator==(const GenericRecord& record) const; 00060 00061 bool operator!=(const GenericRecord& record) const; 00062 00063 ByteBuffer& value(); 00064 00065 const ByteBuffer& value() const; 00066 00067 bool write(FILE* file); 00068 00069 bool read(FILE* file); 00070 00071 size_t size() const; 00072 00073 private: // data 00074 00075 std::string key_; 00076 ByteBuffer val_; 00077 key_size_t key_size_; 00078 val_size_t val_size_; 00079 00080 }; 00081 00082 } // namespace invertedindex 00083 } // namespace aitools 00084 00088 namespace std { 00089 00090 ostream& 00091 operator<<(ostream& os, const aitools::invertedindex::GenericRecord& rec); 00092 } 00093 00094 #endif // AITOOLS_INVERTEDINDEX_GENERIC_RECORD_HPP