#ifndef _VFS_LOCATION_INTERFACE_H_ #define _VFS_LOCATION_INTERFACE_H_ #include "../vfs_types.h" #include "../vfs_debug.h" #include "vfs_file_interface.h" #include "vfs_iterator_interface.h" #include #include #include namespace vfs { class VFS_API IBaseLocation { public: typedef TIterator Iterator; virtual ~IBaseLocation() {}; virtual bool implementsWritable() = 0; virtual bool implementsReadable() = 0; virtual vfs::Path const& getPath() = 0; virtual bool fileExists(vfs::Path const& sFileName) = 0; virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0; virtual Iterator begin() = 0; virtual void getSubDirList(std::list& rlSubDirs) = 0; }; /** * TVFSLocation */ template class VFS_API TLocationTemplate : public IBaseLocation { public: typedef vfs::TLocationTemplate tLocationType; typedef vfs::TFileTemplate tFileType; typedef ReadType tReadType; typedef WriteType tWriteType; typedef std::list > tListFilesWithPath; public: TLocationTemplate(vfs::Path const& mountPoint) : m_mountPoint(mountPoint) {}; virtual ~TLocationTemplate() {}; // has to be virtual , or the types of the caller (not the real object) will be tested virtual bool implementsWritable() { return typeid(tWriteType) == typeid(vfs::IWritable); } virtual bool implementsReadable() { return typeid(tReadType) == typeid(vfs::IReadable); } vfs::Path const& getMountPoint() { return m_mountPoint; } /** * TLocationTemplate interface */ virtual vfs::Path const& getPath() { return m_mountPoint; } virtual bool fileExists(vfs::Path const& sFileName) = 0; virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0; virtual tFileType* getFileTyped(vfs::Path const& rFileName) = 0; protected: vfs::Path m_mountPoint; }; /**************************************************************************************/ /**************************************************************************************/ template class TReadLocation : public TLocationTemplate { public: typedef TReadLocation tLocationType; static tLocationType* cast(vfs::IBaseLocation* bl) { if(bl && bl->implementsReadable()) { return static_cast(bl); } return NULL; } public: TReadLocation(vfs::Path const& sLocalPath) : vfs::TLocationTemplate(sLocalPath) {}; virtual ~TReadLocation(){}; }; template class TWriteLocation : public vfs::TLocationTemplate { public: typedef TWriteLocation tLocationType; static tLocationType* cast(vfs::IBaseLocation* bl) { if(bl && bl->implementsWritable()) { return static_cast(bl); } return NULL; } public: TWriteLocation(vfs::Path const& sLocalPath) : vfs::TLocationTemplate(sLocalPath) {}; virtual ~TWriteLocation(){}; }; /**************************************************************************************/ /**************************************************************************************/ typedef TReadLocation tReadLocation; typedef TWriteLocation tWriteLocation; } // end namespace #endif // _VFS_LOCATION_INTERFACE_H_