Input.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef input_hh
00028 #define input_hh
00029
00030 #include <string>
00031 #include <vector>
00032
00033 #include "Params.h"
00034
00035
00040 class SizeName {
00041 public:
00042 SizeName( const std::string id, const Params::Size_t size ):
00043 m_name( id ), m_size( size ) {}
00047 Params::Size_t Size() const { return m_size; }
00051 const std::string& Name() const { return m_name; }
00052
00053 public:
00054
00055
00059 static bool CmpSize(const SizeName* a, const SizeName* b)
00060 {
00061 return a->Size() < b->Size();
00062 }
00066 static bool CmpSizeRev(const SizeName* a, const SizeName* b)
00067 {
00068 return a->Size() > b->Size();
00069 }
00073 static bool CmpName(const SizeName* a, const SizeName* b)
00074 {
00075 return a->Name() < b->Name();
00076 }
00080 static bool CmpNameRev(const SizeName* a, const SizeName* b)
00081 {
00082 return a->Name() > b->Name();
00083 }
00087 static bool CmpNameNocase(const SizeName* a, const SizeName* b)
00088 {
00089 std::string::const_iterator p = a->Name().begin(), q = b->Name().begin();
00090
00091 while (p != a->Name().end() && q != b->Name().end() && toupper(*p)
00092 == toupper(*q))
00093 {
00094 ++p; ++q;
00095 }
00096
00097 if (p == a->Name().end()) return q != b->Name().end();
00098 if (q == b->Name().end()) return false;
00099
00100 return toupper(*p) < toupper(*q);
00101 }
00105 static bool CmpNameRevNocase(const SizeName* a, const SizeName* b)
00106 {
00107 return !CmpNameNocase(a,b);
00108 }
00109
00110 private:
00111 const std::string m_name;
00112 const Params::Size_t m_size;
00113 };
00114
00115
00116 class Input {
00117 public:
00122 Input( Params& );
00123
00124 ~Input() { for( unsigned i = 0; i < m_files.size(); ++i ) delete m_files[i]; }
00125 private:
00131 void Initialize();
00136 void ReadInput();
00140 void LoadFiles();
00144 void AddFile(const std::string&);
00149 void StringToSizeID(const std::string&);
00154 bool CheckRange(const std::string&, Params::Size_t) const;
00155
00156 public:
00162 std::vector<const SizeName*> m_files;
00163 Params::Size_t m_total_size;
00168 Params& m_params;
00169 };
00170
00171
00172 #endif