Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / common / src / game_share / file_description_container.h
blob508a5f4e54e9aee4ecde056ec22621e43130817f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef FILE_DESCRIPTION_CONTAINER_H
18 #define FILE_DESCRIPTION_CONTAINER_H
20 //-----------------------------------------------------------------------------
21 // Includes
22 //-----------------------------------------------------------------------------
24 #include "nel/misc/types_nl.h"
25 #include "nel/misc/stream.h"
26 #include "nel/misc/sstring.h"
28 #include <vector>
31 //-----------------------------------------------------------------------------
32 // class CFileDescription
33 //-----------------------------------------------------------------------------
35 class CFileDescription
37 public:
38 NLMISC::CSString FileName;
39 uint32 FileTimeStamp;
40 uint32 FileSize;
42 // ctor
43 CFileDescription(const std::string& name=std::string(),uint32 time=0,uint32 size=0);
45 // setup the record for a given file
46 // if file exists then initialises file size and time stamp accordingly and return true
47 // else zeros file size and timestamp and returns false
48 bool set(const std::string& name);
50 // serialise...
51 void serial(NLMISC::IStream& stream);
53 // generate a complete string description of the file
54 // the 'maxFileNameLen' is used to generate padding spaces to allign file lengths nicely
55 NLMISC::CSString toString(uint32 maxFileNameLen=0) const;
57 // remove the provided string if found at the beginning of FileName
58 void stripFilename(const std::string& header) { removeHeaderFromFileName(header); }
60 // comparison operator for use with STL
61 bool operator<(const CFileDescription& other) const;
63 protected:
64 // remove the provided string if found at the beginning of FileName
65 void removeHeaderFromFileName( const std::string& header )
67 uint hdsize = (uint)header.size();
68 if ( FileName.substr( 0, hdsize ) == header )
70 FileName = FileName.substr( hdsize );
76 //-----------------------------------------------------------------------------
77 // class CFileDescriptionContainer
78 //-----------------------------------------------------------------------------
80 class CFileDescriptionContainer
82 public:
83 // add a specific named file to the container
84 void addFile(const CFileDescription& fileDescription);
86 // add a specific named file to the container
87 void addFile(const std::string& fileName, uint32 timeStamp, uint32 size);
89 // add a specific named file to the container
90 // the file size and timestamp are looked up on the disk
91 void addFile(const std::string& fileName);
93 // add all files matching the given file spec to the container
94 void addFileSpec(const std::string& fileSpec, bool Recurse=false);
96 // add all files in a given directory that match any of the supplied wildcards to the container
97 void addFiles(const std::string& directory, const std::vector<std::string>& wildcards, bool recurse=false);
98 void addFiles(const std::string& directory, const NLMISC::CVectorSString& wildcards, bool recurse=false);
100 // add the contents of another fdc to this one
101 void addFiles(const CFileDescriptionContainer& other);
103 // display a list of the files in the container to the named output log
104 void display(NLMISC::CLog* log) const;
106 // serialise...
107 void serial(NLMISC::IStream& stream);
109 // get number of elemnts in the container
110 uint32 size() const;
112 // check whether the container is empty
113 bool empty() const;
115 // clear out the contents of the container
116 void clear();
118 // get the nth element of the container (const)
119 const CFileDescription& operator[](uint32 idx) const;
121 // get the nth element of the container (non-const)
122 CFileDescription& operator[](uint32 idx);
124 // remove the 'n'th element from a file description container
125 void removeFile(uint32 idx);
127 // remove the provided string if found at the beginning of FileName
128 void stripFilename(const std::string& header);
130 private:
131 typedef std::vector<CFileDescription> TFileDescriptions;
132 TFileDescriptions _FileDescriptions;
136 //-------------------------------------------------------------------------------------------------
137 #endif