Main Page | Class Hierarchy | Class List | File List | Class Members

indexfile.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
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         //should delete it from file and index
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