ArMemError.cpp
Go to the documentation of this file.
1 #include "ArMemError.h"
2 
3 #include <sstream>
4 
5 #include <SimoxUtility/algorithm/string/string_tools.h>
6 
7 #include "../MemoryID.h"
8 
10 {
11 
12 
13  ArMemError::ArMemError(const std::string& msg) : std::runtime_error(msg)
14  {
15  }
16 
17  InvalidArgument::InvalidArgument(const std::string& argument,
18  const std::string& function,
19  const std::string& message) :
20  ArMemError(makeMsg(argument, function, message))
21  {
22  }
23 
24  std::string
25  InvalidArgument::makeMsg(const std::string& argument,
26  const std::string& function,
27  const std::string& message)
28  {
29  std::stringstream ss;
30  ss << "Invalid value for argument '" << argument << "' in function " << function << "()";
31  if (message.empty())
32  {
33  ss << ".";
34  }
35  else
36  {
37  ss << ":\n" << message;
38  }
39  return ss.str();
40  }
41 
42  ContainerNameMismatch::ContainerNameMismatch(const std::string& gottenName,
43  const std::string& ownTerm,
44  const std::string& containerName) :
45  ArMemError(makeMsg(gottenName, ownTerm, containerName))
46  {
47  }
48 
49  std::string
50  ContainerNameMismatch::makeMsg(const std::string& gottenName,
51  const std::string& containerTerm,
52  const std::string& containerName)
53  {
54  std::stringstream ss;
55  ss << "Name '" << gottenName << "' does not match name of " << containerTerm << " '"
56  << containerName << "'.";
57  return ss.str();
58  }
59 
61  const std::string& existingName,
62  const std::string& ownTerm,
63  const std::string& ownName) :
64  ArMemError(makeMsg(existingTerm, existingName, ownTerm, ownName))
65  {
66  }
67 
68  std::string
69  ContainerEntryAlreadyExists::makeMsg(const std::string& existingTerm,
70  const std::string& existingName,
71  const std::string& ownTerm,
72  const std::string& ownName)
73  {
74  std::stringstream ss;
75  ss << simox::alg::capitalize_words(existingTerm) << " with name '" << existingName << "' "
76  << "already exists in " << ownTerm << " '" << ownName << "'.";
77  return ss.str();
78  }
79 
80  MissingEntry::MissingEntry(const std::string& missingTerm,
81  const std::string& missingName,
82  const std::string& containerTerm,
83  const std::string& containerName,
84  size_t size) :
85  ArMemError(makeMsg(missingTerm, missingName, containerTerm, containerName, size))
86  {
87  }
88 
89  std::string
90  MissingEntry::makeMsg(const std::string& missingTerm,
91  const std::string& missingName,
92  const std::string& containerTerm,
93  const std::string& containerName,
94  size_t size)
95  {
96  std::stringstream ss;
97  ss << "No " << missingTerm << " with name '" << missingName << "' "
98  << "in " << containerTerm << " '" << containerName << "' (with size " << size << ").";
99  return ss.str();
100  }
101 
102  NoSuchEntries::NoSuchEntries(const std::string& missingTerm,
103  const std::string& containerTerm,
104  const MemoryID& containerID,
105  const std::string& message) :
106  ArMemError(makeMsg(missingTerm, containerTerm, containerID, message))
107  {
108  }
109 
110  std::string
111  NoSuchEntries::makeMsg(const std::string& missingTerm,
112  const std::string& containerTerm,
113  const MemoryID& containerID,
114  const std::string& message)
115  {
116  std::stringstream ss;
117  ss << "No " << missingTerm << " in " << containerTerm << " " << containerID << ".";
118  return ss.str();
119  }
120 
121  MissingData::MissingData(const std::string& missingTerm,
122  const std::string& missingName,
123  const std::string& ownTerm,
124  const std::string& ownName) :
125  ArMemError(makeMsg(missingTerm, missingName, ownTerm, ownName))
126  {
127  }
128 
129  std::string
130  MissingData::makeMsg(const std::string& missingTerm,
131  const std::string& missingName,
132  const std::string& ownTerm,
133  const std::string& ownName)
134  {
135  std::stringstream ss;
136  ss << "No " << missingTerm << " data at '" << missingName << "' "
137  << "in " << ownTerm << " '" << ownName << "'.";
138  return ss.str();
139  }
140 
141  ParseIntegerError::ParseIntegerError(std::string string, std::string semanticName) :
142  ArMemError(makeMsg(string, semanticName))
143  {
144  }
145 
146  std::string
147  ParseIntegerError::makeMsg(std::string string, std::string semanticName)
148  {
149  std::stringstream ss;
150  ss << "Failed to parse " << semanticName << " '" << string << "' as integer.";
151  return ss.str();
152  }
153 
154  InvalidMemoryID::InvalidMemoryID(const MemoryID& id, const std::string& message) :
155  ArMemError(makeMsg(id, message))
156  {
157  }
158 
159  std::string
160  InvalidMemoryID::makeMsg(const MemoryID& id, const std::string& message)
161  {
162  std::stringstream ss;
163  ss << "Invalid memory ID " << id << ": " << message;
164  return ss.str();
165  }
166 
167  EntityHistoryEmpty::EntityHistoryEmpty(const std::string& entityName,
168  const std::string& message) :
169  ArMemError(makeMsg(entityName, message))
170  {
171  }
172 
173  std::string
174  EntityHistoryEmpty::makeMsg(const std::string& entityName, const std::string& message)
175  {
176  std::stringstream ss;
177  ss << "History of entity '" << entityName << "' is empty";
178  if (message.size() > 0)
179  {
180  ss << " " << message;
181  }
182  else
183  {
184  ss << ".";
185  }
186  return ss.str();
187  }
188 
189  UnknownQueryType::UnknownQueryType(const std::string& term, const std::string& typeName) :
190  ArMemError(makeMsg(term, typeName))
191  {
192  }
193 
194  std::string
195  UnknownQueryType::makeMsg(const std::string& term, const std::string& typeName)
196  {
197  std::stringstream ss;
198  ss << "Unknown " << term << " query type '" << typeName << "'.";
199  return ss.str();
200  }
201 
202  QueryFailed::QueryFailed(const std::string& memory, const std::string& message) :
203  ArMemError(makeMsg(memory, message))
204  {
205  }
206 
207  std::string
208  QueryFailed::makeMsg(const std::string& memory, const std::string& message)
209  {
210  std::stringstream ss;
211  ss << "Query from memory " << memory << " failed with message: " << message;
212  return ss.str();
213  }
214 
215  IOError::IOError(const std::string& path, const std::string& message) :
216  ArMemError(makeMsg(path, message)), path(path)
217  {
218  }
219 
220  std::string
221  IOError::makeMsg(const std::string& path, const std::string& message)
222  {
223  std::stringstream ss;
224  ss << "IOError on path \"" << path << "\".";
225  if (message.size() > 0)
226  {
227  ss << "\n" << message;
228  }
229  return ss.str();
230  }
231 
232  ProxyNotSet::ProxyNotSet(const std::string& proxyName, const std::string& message) :
233  ArMemError(makeMsg(proxyName, message))
234  {
235  }
236 
237  std::string
238  ProxyNotSet::makeMsg(const std::string& proxyName, const std::string& message)
239  {
240  std::stringstream sstream;
241  sstream << "Proxy \"" << proxyName << "\" not set.";
242  if (!message.empty())
243  {
244  sstream << "\n" << message;
245  }
246  return sstream.str();
247  }
248 
250  const std::string& calledFunction) :
251  ArMemError(makeMsg(queriedId, calledFunction))
252  {
253  }
254 
255  std::string
256  ReadStreamAlreadyPolling::makeMsg(const MemoryID& queriedId, const std::string& calledFunction)
257  {
258  std::stringstream ss;
259  ss << "The ReadStream for " << queriedId << " was already running when " << calledFunction
260  << " was called.";
261  return ss.str();
262  }
263 
264 } // namespace armarx::armem::error
armarx::armem::error::InvalidArgument::makeMsg
static std::string makeMsg(const std::string &argument, const std::string &function, const std::string &message)
Definition: ArMemError.cpp:25
armarx::armem::error::ContainerNameMismatch::makeMsg
static std::string makeMsg(const std::string &gottenName, const std::string &containerTerm, const std::string &containerName)
Definition: ArMemError.cpp:50
armarx::armem::error::NoSuchEntries::makeMsg
static std::string makeMsg(const std::string &missingTerm, const std::string &containerTerm, const MemoryID &containerID, const std::string &message="")
Definition: ArMemError.cpp:111
armarx::armem::error::ContainerEntryAlreadyExists::ContainerEntryAlreadyExists
ContainerEntryAlreadyExists(const std::string &existingTerm, const std::string &existingName, const std::string &ownTerm, const std::string &ownName)
Definition: ArMemError.cpp:60
armarx::armem::error::ParseIntegerError::ParseIntegerError
ParseIntegerError(std::string string, std::string semanticName)
Definition: ArMemError.cpp:141
armarx::armem::error::IOError::makeMsg
static std::string makeMsg(const std::string &path, const std::string &message="")
Definition: ArMemError.cpp:221
armarx::armem::MemoryID::str
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition: MemoryID.cpp:102
armarx::armem::error::ProxyNotSet::makeMsg
static std::string makeMsg(const std::string &proxyName, const std::string &message="")
Definition: ArMemError.cpp:238
armarx::armem::error::InvalidMemoryID::makeMsg
static std::string makeMsg(const MemoryID &id, const std::string &message)
Definition: ArMemError.cpp:160
armarx::armem::error::ArMemError::ArMemError
ArMemError(const std::string &msg)
Definition: ArMemError.cpp:13
armarx::armem::error::IOError::path
std::string path
Definition: ArMemError.h:209
armarx::armem::error::ArMemError
Base class for all exceptions thrown by the armem library.
Definition: ArMemError.h:18
armarx::armem::error::MissingEntry::MissingEntry
MissingEntry(const std::string &missingTerm, const std::string &missingName, const std::string &containerTerm, const std::string &containerName, size_t containerSize)
Definition: ArMemError.cpp:80
armarx::armem::error::InvalidArgument::InvalidArgument
InvalidArgument(const std::string &argument, const std::string &function, const std::string &message)
Definition: ArMemError.cpp:17
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
armarx::armem::error::MissingEntry::makeMsg
static std::string makeMsg(const std::string &missingTerm, const std::string &missingName, const std::string &containerTerm, const std::string &containerName, size_t size)
Definition: ArMemError.cpp:90
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::error::ContainerEntryAlreadyExists::makeMsg
static std::string makeMsg(const std::string &existingTerm, const std::string &existingName, const std::string &ownTerm, const std::string &ownName)
Definition: ArMemError.cpp:69
armarx::armem::error::EntityHistoryEmpty::EntityHistoryEmpty
EntityHistoryEmpty(const std::string &entityName, const std::string &message="")
Definition: ArMemError.cpp:167
ArMemError.h
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::error::QueryFailed::makeMsg
static std::string makeMsg(const std::string &memory, const std::string &message="")
Definition: ArMemError.cpp:208
armarx::armem::error::MissingData::makeMsg
static std::string makeMsg(const std::string &missingTerm, const std::string &missingName, const std::string &ownTerm, const std::string &ownName)
Definition: ArMemError.cpp:130
armarx::armem::error::MissingData::MissingData
MissingData(const std::string &missingTerm, const std::string &missingName, const std::string &ownTerm, const std::string &ownName)
Definition: ArMemError.cpp:121
armarx::armem::error::ContainerNameMismatch::ContainerNameMismatch
ContainerNameMismatch(const std::string &gottenName, const std::string &containerTerm, const std::string &containerName)
Definition: ArMemError.cpp:42
armarx::armem::error::QueryFailed::QueryFailed
QueryFailed(const std::string &memory, const std::string &message="")
Definition: ArMemError.cpp:202
armarx::armem::error::IOError::IOError
IOError(const std::string &path, const std::string &message="")
Definition: ArMemError.cpp:215
std
Definition: Application.h:66
armarx::armem::error::ParseIntegerError::makeMsg
static std::string makeMsg(std::string string, std::string semanticName)
Definition: ArMemError.cpp:147
armarx::armem::error::EntityHistoryEmpty::makeMsg
static std::string makeMsg(const std::string &entityName, const std::string &message="")
Definition: ArMemError.cpp:174
armarx::armem::error::NoSuchEntries::NoSuchEntries
NoSuchEntries(const std::string &missingTerm, const std::string &containerTerm, const MemoryID &containerID, const std::string &message="")
Definition: ArMemError.cpp:102
armarx::armem::error::ReadStreamAlreadyPolling::makeMsg
static std::string makeMsg(const MemoryID &queriedId, const std::string &calledFunction)
Definition: ArMemError.cpp:256
armarx::armem::error::UnknownQueryType::makeMsg
static std::string makeMsg(const std::string &term, const std::string &typeName)
Definition: ArMemError.cpp:195
armarx::armem::error::ProxyNotSet::ProxyNotSet
ProxyNotSet(const std::string &proxyName, const std::string &message="")
Definition: ArMemError.cpp:232
armarx::armem::error::InvalidMemoryID::InvalidMemoryID
InvalidMemoryID(const MemoryID &id, const std::string &message)
Definition: ArMemError.cpp:154
armarx::armem::error::ReadStreamAlreadyPolling::ReadStreamAlreadyPolling
ReadStreamAlreadyPolling(const MemoryID &queriedId, const std::string &calledFunction)
Definition: ArMemError.cpp:249
armarx::armem::error
Definition: ArMemError.cpp:9
armarx::armem::error::UnknownQueryType::UnknownQueryType
UnknownQueryType(const std::string &term, const QueryType &query)
Definition: ArMemError.h:177