AnCH Framework  0.1
Another C++ Hack Framework
dateFormatter.hpp
1 /*
2  ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3  Copyright (C) 2012 Vincent Lachenal
4 
5  This file is part of ANCH Framework.
6 
7  ANCH Framework is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ANCH Framework is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef _ANCH_DATE_DATE_FORMAT_H_
21 #define _ANCH_DATE_DATE_FORMAT_H_
22 
23 #include <iostream>
24 #include <map>
25 #include <vector>
26 
27 #ifdef ANCH_BOOST_REGEX
28 #include <boost/regex.hpp>
29 #else
30 #include <regex>
31 #endif
32 
33 #include "date/date.hpp"
34 
35 
36 namespace anch {
37  namespace date {
38 
40  typedef anch::date::formatter::IDatePartFormatter* (*getInstance)();
41 
63  class DateFormatter {
64 
65  // Attributes +
66 #ifdef ANCH_BOOST_REGEX
67 
68  const static boost::regex DATE_PATTERN;
69 #else
70 
71  const static std::regex DATE_PATTERN;
72 #endif
73 
75  static std::map<std::string, getInstance> FORMATTERS;
76 
78  std::vector<anch::date::formatter::IDatePartFormatter*> _formatters;
79 
81  size_t _size;
82  // Attributes -
83 
84  // Constructors +
85  public:
91  DateFormatter(const std::string& dateFormat);
92  // Constructors -
93 
94  // Destructor +
95  public:
99  virtual ~DateFormatter();
100  // Destructor -
101 
102  // Methods +
103  public:
110  static void registerFormatterPart(const std::string& pattern,
111  getInstance instGetter);
112 
119  void format(const anch::date::Date& date, std::string& output) const;
120 
127  void format(const anch::date::Date& date, std::ostream& output) const;
128 
136  void parse(const std::string& strDate, anch::date::Date& date) const;
137 
146  anch::date::Date* parse(const std::string& strDate) const;
147 
148  private:
154  void addFormatter(const std::string& strFormatter);
155  // Methods -
156 
157  };
158 
159  }
160 }
161 
162 #endif // _ANCH_DATE_DATE_FORMAT_H_
DateFormatter(const std::string &dateFormat)
Definition: dateFormatter.cpp:89
virtual ~DateFormatter()
Definition: dateFormatter.cpp:111
AnCH framework base namespace.
Definition: base64.hpp:28
Definition: dateFormatter.hpp:63
Definition: iDatePartFormatter.hpp:38
anch::date::formatter::IDatePartFormatter *(* getInstance)()
Definition: dateFormatter.hpp:40
static void registerFormatterPart(const std::string &pattern, getInstance instGetter)
Definition: dateFormatter.cpp:127
void format(const anch::date::Date &date, std::string &output) const
Definition: dateFormatter.cpp:142
Definition: date.hpp:47
void parse(const std::string &strDate, anch::date::Date &date) const
Definition: dateFormatter.cpp:171