jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
exception_info.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011,2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_COMMON_EXCEPTION_INFO_HPP_
18 #define JUBATUS_CORE_COMMON_EXCEPTION_INFO_HPP_
19 
20 #include <cstring>
21 #include <string>
22 #include <typeinfo>
23 #include "jubatus/util/lang/shared_ptr.h"
24 #include "jubatus/util/lang/cast.h"
25 #include "jubatus/util/lang/demangle.h"
26 
27 namespace jubatus {
28 namespace core {
29 namespace common {
30 namespace exception {
31 
33  public:
34  virtual bool splitter() const {
35  return false;
36  }
37 
38  virtual std::string tag_typeid_name() const = 0;
39  virtual std::string as_string() const = 0;
40 
41  virtual ~error_info_base() throw () {
42  }
43 };
44 
45 template<class Tag, class V>
46 class error_info;
47 
48 template<class Tag, class V>
49 inline std::string to_string(const error_info<Tag, V>& info) {
50  return jubatus::util::lang::lexical_cast<std::string, V>(info.value());
51 }
52 
53 template<>
54 class error_info<struct error_splitter_, void> : public error_info_base {
55  public:
56  bool splitter() const {
57  return true;
58  }
59 
60  std::string tag_typeid_name() const {
61  return jubatus::util::lang::demangle(
62  typeid(struct error_splitter_*).name());
63  }
64 
65  std::string as_string() const {
66  // USE splitter or tag_typeid_name
67  return "-splitter-";
68  }
69 };
70 
71 template<class Tag, class V>
72 class error_info : public error_info_base {
73  public:
74  typedef V value_type;
75  explicit error_info(value_type v);
76  ~error_info() throw ();
77 
78  std::string tag_typeid_name() const;
79  std::string as_string() const;
80 
81  value_type value() const {
82  return value_;
83  }
84 
85  private:
86  value_type value_;
87 };
88 
89 template<class Tag, class V>
91  : value_(v) {
92 }
93 
94 template<class Tag, class V>
96 }
97 
98 template<class Tag, class V>
99 inline std::string error_info<Tag, V>::tag_typeid_name() const {
100  return jubatus::util::lang::demangle(typeid(Tag*).name());
101 }
102 
103 template<class Tag, class V>
104 inline std::string error_info<Tag, V>::as_string() const {
105  return to_string(*this);
106 }
107 
108 } // namespace exception
109 } // namespace common
110 } // namespace core
111 } // namespace jubatus
112 
113 #endif // JUBATUS_CORE_COMMON_EXCEPTION_INFO_HPP_
std::string to_string(const error_errno &info)
Definition: exception.hpp:42
virtual std::string as_string() const =0
std::vector< T > v(size)
virtual std::string tag_typeid_name() const =0