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