Documentation for OpenFLUID 2.2.0
ProgressiveChronFileReader.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file ProgressiveChronFileReader.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  @author Armel THÖNI <armel.thoni@inrae.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_TOOLS_PROGRESSIVECHRONFILEREADER_HPP__
42 #define __OPENFLUID_TOOLS_PROGRESSIVECHRONFILEREADER_HPP__
43 
44 
48 #include <openfluid/dllexport.hpp>
49 
50 
51 namespace openfluid { namespace tools {
52 
53 
54 template<class DataType>
56 {
57  private:
58 
59  std::string m_DateFormat;
60 
61 
62  public:
63 
64  ProgressiveChronFileReader(const std::string& FileName,
65  const std::string& DateFormat = "%Y-%m-%dT%H:%M:%S",
66  const std::string& ColSeparators = " \t\r\n") :
67  ProgressiveColumnFileReader(FileName,ColSeparators), m_DateFormat(DateFormat)
68  {
69  }
70 
72  {
73  }
74 
75 
77 
78 };
79 
80 
81 // =====================================================================
82 // =====================================================================
83 
84 
85 template<>
87 {
88  std::vector<std::string> Values;
90  double Val;
91 
92  while (getNextLine(Values))
93  {
94  if (Values.size() == 2)
95  {
96  if (DT.setFromString(Values.front(),m_DateFormat) &&
97  openfluid::tools::toNumeric(Values.back(),Val))
98  {
99  Value.first = DT;
100  Value.second = Val;
101  return true;
102  }
103  else
104  {
105  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
106  "wrong data in " + m_FileName);
107  }
108  }
109  }
110 
111  return false;
112 }
113 
114 
115 // =====================================================================
116 // =====================================================================
117 
118 
119 template<>
121  ChronItem_t<std::vector<std::string>>& Value)
122 {
123  std::vector<std::string> Values;
125 
126  while (getNextLine(Values))
127  {
128  if (Values.size() >= 2)
129  {
130  if (DT.setFromString(Values.front(),m_DateFormat) )
131  {
132  Value.first = DT;
133  Value.second.clear();
134  for (std::size_t i=1;i<Values.size();i++)
135  {
136  Value.second.push_back(Values[i]);
137  }
138  return true;
139  }
140  else
141  {
142  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,
143  "wrong data in " + m_FileName);
144  }
145  }
146  }
147 
148  return false;
149 }
150 
151 
152 } } // namespaces
153 
154 
155 #endif /* __OPENFLUID_TOOLS_PROGRESSIVECHRONFILEREADER_HPP__ */
Definition: FrameworkException.hpp:51
Class for management of date and time information.
Definition: DateTime.hpp:88
bool setFromString(const std::string &DateTimeStr, const std::string &FormatStr)
Definition: ProgressiveChronFileReader.hpp:56
virtual ~ProgressiveChronFileReader()
Definition: ProgressiveChronFileReader.hpp:71
ProgressiveChronFileReader(const std::string &FileName, const std::string &DateFormat="%Y-%m-%dT%H:%M:%S", const std::string &ColSeparators=" \t\r\n")
Definition: ProgressiveChronFileReader.hpp:64
bool getNextValue(ChronItem_t< DataType > &Value)
Definition: ProgressiveColumnFileReader.hpp:58
#define OPENFLUID_API
Definition: dllexport.hpp:86
bool toNumeric(const std::string &Str, T &Num)
Definition: StringHelpers.hpp:113
std::pair< openfluid::core::DateTime, DataType > ChronItem_t
Definition: ChronologicalSerie.hpp:55
Definition: ApplicationException.hpp:47