Data Access Library (DAL)
/home/amesfoort/DAL/dal/hdf5/types/FileInfo.h
00001 /* Copyright 2011-2012  ASTRON, Netherlands Institute for Radio Astronomy
00002  * This file is part of the Data Access Library (DAL).
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either 
00007  * version 3 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public 
00015  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef DAL_FILE_INFO_H
00018 #define DAL_FILE_INFO_H
00019 
00020 #include <string>
00021 #include "versiontype.h"
00022 
00023 namespace dal {
00024 
00025 class FileInfoType;
00026 
00032 class FileInfo {
00033   FileInfoType* ptr;
00034 
00035 public:
00036   typedef int FileMode; // see class Node for possible values
00037 
00038   FileInfo();
00039   FileInfo(const std::string& fullFilename, FileMode fileMode,
00040            const std::string& versionAttrName);
00041   FileInfo(const FileInfo& other);
00042   ~FileInfo();
00043   FileInfo& operator=(FileInfo rhs);
00044 
00045   friend void swap(FileInfo& fi0, FileInfo& fi1);
00046 
00047   const std::string& filename() const;
00048   int fileDirfd() const;
00049   FileMode fileMode() const;
00050   const std::string& versionAttrName() const;
00051   VersionType& fileVersion() const;
00052 
00053   void setFileVersion(const VersionType& newVersion);
00054 
00055 
00056   static std::string getBasename(const std::string& filename);
00057   static std::string getDirname(const std::string& filename);
00058 
00059 private:
00060   int openOtherDirname(const std::string& filename);
00061 };
00062 
00075 class FileInfoType {
00076   friend class FileInfo;
00077 
00078 
00079   mutable unsigned refCount;
00080 
00084   const std::string filename;
00085 
00090   const int fdirfd;
00091 
00093   const FileInfo::FileMode fileMode;
00094 
00096   const std::string versionAttrName;
00097 
00098 
00099   // The (cached) file version as stored by HDF5 in the attribute named versionAttrName.
00100   // Not initialized by the constructor, because we don't know for sure if the file is already open.
00101   VersionType fileVersion;
00102 
00103 
00104   FileInfoType();
00105   FileInfoType(const std::string& filename, const int fdirfd,
00106                FileInfo::FileMode fileMode, const std::string& versionAttrName);
00107 };
00108 
00109 
00110 }
00111 
00112 #endif
00113 
 All Classes Functions Variables Typedefs Friends