FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

RAMDirectory.h

浏览该文件的文档。
00001 //
00002 // Copyright(C) 2005--2006 Institute of Computing Tech, Chinese Academy of Sciences. 
00003 // All rights reserved.
00004 // This file is part of FirteX (www.firtex.org)
00005 //
00006 // Use of the FirteX is subject to the terms of the software license set forth in 
00007 // the LICENSE file included with this software, and also available at
00008 // http://www.firtex.org/license.html
00009 //
00010 // Author       : 郭瑞杰(GuoRuijie)
00011 // Email        : ruijieguo@software.ict.ac.cn,ruijieguo@gmail.com
00012 // Created      : 2006/7/2
00013 //
00014 #ifndef __RAMDIRECTORY_H
00015 #define __RAMDIRECTORY_H
00016 
00017 #if _MSC_VER > 1000
00018 #pragma once
00019 #endif // _MSC_VER > 1000
00020 
00021 #include "Directory.h"
00022 #include "IndexInput.h"
00023 #include "IndexOutput.h"
00024 #include "../utility/Misc.h"
00025 #include <map>
00026 #include <vector>
00027 using namespace std;
00028 
00029 
00030 namespace firtex
00031 {
00032         namespace store
00033         {
00034 
00035                 #define RAMFILE_STREAMSIZE      4096            //4K
00036                 #define RAMFILE_MAXSEGS         10000   
00037 
00038                 class CRAMFile
00039                 {
00040                 public:
00041                         CRAMFile()
00042                         {
00043                                 m_length = 0;
00044                                 m_lastModified = firtex::utility::CMisc::currentTimeMillis();
00045                                 m_streamBufSize = RAMFILE_STREAMSIZE;
00046                         }
00047                         ~CRAMFile()
00048                         {
00049                                 vector<byte*>::iterator iter = m_buffers.begin();
00050                                 while (iter != m_buffers.end())
00051                                 {
00052                                         delete[] (*iter);
00053                                         iter++;
00054                                 }
00055                                 m_buffers.clear();
00056                         }                       
00057                 public:
00058                         CRAMFile*       clone()
00059                         {
00060                                 CRAMFile* pRAM = new CRAMFile();
00061                                 pRAM->m_length = m_length;
00062                                 pRAM->m_lastModified = m_lastModified;
00063                                 pRAM->m_streamBufSize = m_streamBufSize;
00064                                 byte* tmp;
00065                                 vector<byte*>::iterator iter = m_buffers.begin();
00066                                 while (iter != m_buffers.end())
00067                                 {
00068                                         tmp = new byte[m_streamBufSize];
00069                                         memcpy(tmp,(*iter),m_streamBufSize);
00070                                         pRAM->m_buffers.push_back(tmp);
00071                                         iter++;
00072                                 }
00073                                 return pRAM;
00074                         }
00075                 protected:
00076                         int64_t         m_length;                       //文件长度
00077                         int64_t         m_lastModified;         //最后修改时间
00078 
00079                         vector<byte*>   m_buffers;              //文件内容buffer
00080                         int32_t                 m_streamBufSize;//m_buffers中每个buffer的大小
00081 
00082                         friend class CRAMDirectory;
00083                         friend class CRAMIndexInput;
00084                         friend class CRAMIndexOutput;
00085                 };
00086 
00087                 class CRAMIndexInput : public CIndexInput
00088                 {
00089                 public:
00090                         CRAMIndexInput(CRAMFile* file);
00091                         CRAMIndexInput(CRAMFile* file,char* buffer,size_t bufSize);
00092                         CRAMIndexInput(const CRAMIndexInput& clone);
00093                         virtual ~CRAMIndexInput();
00094                 public:
00101                         void                    readInternal(char* b, size_t offset, size_t len);
00102                         
00108                         CIndexInput*    clone(char* buffer,size_t buffsize);                    
00109 
00113                         CIndexInput*    clone();
00114 
00118                         void                    close();
00119                 protected:
00124                         void  seekInternal(int64_t position);           
00125                 protected:
00126                         CRAMFile*       m_file;
00127                         int64_t         m_pointer;
00128 
00129                         friend class CRAMDirectory;
00130                 };
00131 
00132                 class CRAMIndexOutput : public CIndexOutput
00133                 {
00134                 public:
00135                         CRAMIndexOutput();
00136                         CRAMIndexOutput(CRAMFile* ramFile);
00137                         virtual ~CRAMIndexOutput();
00138                 public:
00142                         void    seek(int64_t pos);
00143 
00147                         int64_t length(){return m_file->m_length;}
00148 
00152                         void    close();
00153 
00158                         void    writeTo(CIndexOutput* pOutput);
00159 
00160                 protected:
00166                         void    flushBuffer(char* b, size_t len);
00167                 protected:                              
00168                         CRAMFile*       m_file;
00169                         bool            m_bDeleteFile;
00170                         int64_t         m_pointer;
00171 
00172                         friend class CRAMDirectory;
00173                 };
00174 
00175                 class CRAMDirectory :   public CDirectory
00176                 {
00177                 public:
00178                         CRAMDirectory(const tchar* dir);
00179                         CRAMDirectory(CDirectory* pDir);
00180                         CRAMDirectory(void);
00181                         virtual ~CRAMDirectory(void);
00182                 public:
00187                         bool                    fileExists(const tstring& name) const;
00188 
00193                         int64_t                 fileModified(const tstring& name) const;
00194 
00199                         int64_t                 fileLength(const tstring& name) const;
00200 
00206                         FileList*               list();
00207 
00212                         CIndexInput*    openInput(const tstring& name);
00213 
00220                         CIndexInput*    openInput(const tstring& name,char* buf,size_t bufsize);
00221 
00227                         void                    deleteFile(const tstring& filename,bool throwError = true);
00228 
00234                         void                    renameFile(const tstring& from, const tstring& to);
00235 
00241                         void                    batDeleteFiles(const tstring& filename,bool throwError = true);
00242 
00248                         void                    copyFile(const tstring& filename,CIndexInput* pSrcFile,bool throwError = true);
00249 
00257                         void                    batCopyFiles(CDirectory*pFromDir,const tstring& from,const tstring& to,bool throwError = true);
00258 
00264                         void                    batRenameFiles(const tstring& from, const tstring& to);
00265                         
00270                         CIndexOutput*   createOutput(const tstring& name);
00271 
00276                         void                    touchFile(const tstring& name);
00277 
00283                         CDirectory*             clone();
00284 
00288                         void                    close();
00289                 protected:
00290                         void    fromDirectory(CDirectory* pDir,bool bCloseDir);
00291                 private:                        
00292                         map<tstring,CRAMFile*>          m_files;                //文件
00293                 };
00294         }
00295 }
00296 
00297 
00298 #endif

http://www.firtex.org http://www.sourceforge.net/projects/firtex