jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
exception.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 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 #include "exception.hpp"
18 
19 #include <string>
20 #include <vector>
21 
22 using std::string;
23 using jubatus::util::text::json::json;
24 
25 namespace jubatus {
26 namespace core {
27 namespace common {
28 namespace jsonconfig {
29 
30 config_error::config_error(const std::string& path, const std::string& message)
31  : path_(path),
32  message_(message + " (" + path_ + ")") {
33 }
34 
36 }
37 
38 namespace {
39 
40 const char* TypeToName(json::json_type_t t) {
41  switch (t) {
42  case json::Null:
43  return "Null";
44  case json::Integer:
45  return "Integer";
46  case json::Float:
47  return "Float";
48  case json::Bool:
49  return "Bool";
50  case json::String:
51  return "String";
52  case json::Array:
53  return "Array";
54  case json::Object:
55  return "Object";
56  default:
57  return "Unknown Type";
58  }
59 }
60 
61 std::string MakeTypeErrorMessage(
62  json::json_type_t expect,
63  json::json_type_t actual) {
64  return string(TypeToName(expect)) + " is expected, but " + TypeToName(actual)
65  + " is given.";
66 }
67 
68 std::string MakeOutOfRangeMessage(size_t size, size_t index) {
69  std::ostringstream os;
70  os << "Out of range 0.." << size << ": " << index;
71  return os.str();
72 }
73 
74 std::string MakeNotFoundMessage(const std::string& key) {
75  return "\"" + key + "\" is not found";
76 }
77 
78 std::string MakeRedundantKeyMessage(const std::string& key) {
79  return "\"" + key + "\" is not used";
80 }
81 
82 } // namespace
83 
85  const std::string& path,
86  json::json_type_t expect,
87  json::json_type_t actual)
88  : config_error(path, MakeTypeErrorMessage(expect, actual)),
89  expect_(expect),
90  actual_(actual) {
91 }
92 
94 }
95 
96 out_of_range::out_of_range(const std::string& path, size_t size, size_t index)
97  : config_error(path, MakeOutOfRangeMessage(size, index)),
98  size_(size),
99  index_(index) {
100 }
101 
103 }
104 
105 not_found::not_found(const std::string& path, const std::string& key)
106  : config_error(path, MakeNotFoundMessage(key)),
107  key_(key) {
108 }
109 
111 }
112 
113 redundant_key::redundant_key(const std::string& path, const std::string& key)
114  : config_error(path, MakeRedundantKeyMessage(key)),
115  key_(key) {
116 }
117 
119 }
120 
122  const std::vector<jubatus::util::lang::shared_ptr<config_error> >& errors)
123  : errors_(errors.begin(), errors.end()) {
124 }
125 
127 }
128 
129 } // namespace jsonconfig
130 } // namespace common
131 } // namespace core
132 } // namespace jubatus
out_of_range(const std::string &path, size_t size, size_t index)
Definition: exception.cpp:96
redundant_key(const std::string &path, const std::string &key)
Definition: exception.cpp:113
type_error(const std::string &path, jubatus::util::text::json::json::json_type_t expect, jubatus::util::text::json::json::json_type_t actual)
Definition: exception.cpp:84
not_found(const std::string &path, const std::string &key)
Definition: exception.cpp:105
cast_check_error(const std::vector< jubatus::util::lang::shared_ptr< config_error > > &errors)
Definition: exception.cpp:121
config_error(const std::string &path, const std::string &message)
Definition: exception.cpp:30