Input.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // $Id: Input.h 230 2008-08-14 01:45:04Z daaugusto $
00003 //
00004 //   Input.h (created on Tue Aug 23 01:08:35 BRT 2005)
00005 // 
00006 //   Genetic Algorithm File Fitter (gaffitter)
00007 //
00008 //   Copyright (C) 2005-2008 Douglas A. Augusto
00009 // 
00010 // This file is part of gaffitter.
00011 // 
00012 // gaffitter is free software; you can redistribute it and/or modify it
00013 // under the terms of the GNU General Public License as published by the
00014 // Free Software Foundation; either version 3 of the License, or (at
00015 // your option) any later version.
00016 // 
00017 // gaffitter is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // General Public License for more details.
00021 // 
00022 // You should have received a copy of the GNU General Public License
00023 // along with gaffitter; if not, see <http://www.gnu.org/licenses/>.
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    // Comparison functions (for sorting containers)
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