indexfile.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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     //should delete it from file and index
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__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends