00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <fcntl.h>
00025 #include <stdio.h>
00026 #include <string>
00027 #include <map>
00028 #include "classad_stl.h"
00029 #include <sys/types.h>
00030
00031 BEGIN_NAMESPACE( classad )
00032
00033 typedef struct{
00034 int offset;
00035 } tag;
00036
00037 struct eqstr
00038 {
00039 bool operator()(const char* s1, const char* s2) const
00040 {
00041 return strcmp(s1, s2) == 0;
00042 }
00043 };
00044
00045 class IndexFile {
00046 public:
00047 void Init(int file_handler);
00048 bool FindInFile(std::string key,tag &offset);
00053 bool UpdateIndex(std::string key);
00054 bool WriteBack(std::string key, std::string ad);
00055
00056 bool DeleteFromStorageFile(std::string key);
00057 bool UpdateIndex(std::string key, int offset);
00058 int First(std::string &key);
00059 int Next(std::string &key);
00060 std::string GetClassadFromFile(std::string key, int offset);
00061 bool TruncateStorageFile();
00062 int dump_index();
00063 private:
00064 classad_hash_map<std::string,int,StringHash> Index;
00065 classad_hash_map<std::string,int,StringHash>::iterator index_itr;
00066 int filed;
00067 };
00068
00069 END_NAMESPACE