00001 /* 00002 wdb 00003 00004 Copyright (C) 2007 met.no 00005 00006 Contact information: 00007 Norwegian Meteorological Institute 00008 Box 43 Blindern 00009 0313 OSLO 00010 NORWAY 00011 E-mail: wdb@met.no 00012 00013 This program is free software; you can redistribute it and/or modify 00014 it under the terms of the GNU General Public License as published by 00015 the Free Software Foundation; either version 2 of the License, or 00016 (at your option) any later version. 00017 00018 This program is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 along with this program; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00026 MA 02110-1301, USA 00027 */ 00028 00029 #ifndef FELTFILE_H_ 00030 #define FELTFILE_H_ 00031 00032 #include "FeltConstants.h" 00033 #include "FeltTypes.h" 00034 #include <boost/shared_ptr.hpp> 00035 #include <boost/weak_ptr.hpp> 00036 #include <boost/filesystem/path.hpp> 00037 #include <boost/date_time/posix_time/posix_time_types.hpp> 00038 #include <boost/shared_array.hpp> 00039 #include <boost/noncopyable.hpp> 00040 00041 00042 #include <iterator> 00043 #include <vector> 00044 #include <iosfwd> 00045 00046 namespace felt 00047 { 00048 00049 class FeltFile : boost::noncopyable 00050 { 00051 public: 00052 explicit FeltFile(const boost::filesystem::path & file); 00053 ~FeltFile(); 00054 00055 typedef size_t size_type; 00056 size_type size() const; 00057 bool empty() const { return size() == 0; } 00058 00059 const boost::filesystem::path & fileName() const { return fileName_; } 00060 00061 std::string information() const; 00062 00063 boost::posix_time::ptime lastUpdateTime() const; 00064 boost::posix_time::ptime referenceTime() const; 00065 boost::posix_time::ptime firstTime() const; 00066 boost::posix_time::ptime lastTime() const; 00067 00068 typedef boost::shared_ptr<FeltField> FeltFieldPtr; 00069 00070 typedef std::vector<FeltFieldPtr>::const_iterator iterator; 00071 // class iterator; 00072 iterator begin(); 00073 iterator end(); 00074 00075 typedef iterator const_iterator; 00076 const_iterator begin() const; 00077 const_iterator end() const; 00078 00080 const FeltField & at(size_t idx) const; 00081 00082 00083 00084 // simple log facility 00085 static void log(const std::string& msg); 00086 static void setLogStream(std::ostream& o); 00087 static void setLogging(bool enableLogging); 00088 static bool isLogging(); 00089 private: 00090 00092 bool complete() const; 00093 00094 typedef boost::shared_array<word> Block; 00095 00096 Block getBlock_(size_type blockNo) const; 00097 00105 void get_(std::vector<word> & out, size_type fromWord, size_type noOfWords) const; 00106 00107 const boost::filesystem::path fileName_; 00108 00113 bool changeEndianness_; 00114 00115 Block block1_; 00116 00117 typedef std::vector<FeltFieldPtr> Fields; 00118 mutable Fields fields_; 00119 00120 mutable std::istream * feltFile_; 00121 00122 friend class FeltField; 00123 // friend class iterator; 00124 }; 00125 00126 00127 00128 //class FeltFile::iterator : public std::iterator<std::input_iterator_tag, FeltField> 00129 //{ 00130 //public: 00131 // iterator & operator ++ (); 00132 // iterator operator ++ (int); 00133 // const reference operator * () const; 00134 // const pointer operator -> () const; 00135 // 00136 // bool operator == ( const iterator & i ) const; 00137 // bool operator != ( const iterator & i ) const; 00138 // 00139 //private: 00140 // value_type & data_; 00141 // const FeltFile * ff_; 00142 // int index_; 00143 // iterator(const FeltFile & ff); 00144 // iterator(); 00145 // friend class FeltFile; 00146 //}; 00147 00148 00149 } 00150 #endif /*FELTFILE_H_*/