Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix bad DB initialization

  • Loading branch information...
commit d1bf40fc687c4cbb34f9769426bfd57c83d4d8a0 1 parent e8650ad
@vrabaud vrabaud authored
Showing with 29 additions and 14 deletions.
  1. +18 −5 include/object_recognition_core/db/db_parameters.h
  2. +11 −9 src/db/db.cpp
View
23 include/object_recognition_core/db/db_parameters.h
@@ -36,6 +36,8 @@
#ifndef DB_PARAMETERS_H_
#define DB_PARAMETERS_H_
+#include <object_recognition_core/common/json.hpp>
+
namespace object_recognition_core
{
namespace db
@@ -68,7 +70,7 @@ namespace object_recognition_core
* @param params A map between some db parameters and their value
*/
explicit
- ObjectDbParameters(const or_json::mObject& params);
+ ObjectDbParameters(const ObjectDbParametersRaw& params);
static ObjectDbType
StringToType(const std::string & type);
@@ -76,7 +78,7 @@ namespace object_recognition_core
static std::string
TypeToString(const ObjectDbParameters::ObjectDbType & type);
- ObjectDbType
+ inline ObjectDbType
type() const
{
return type_;
@@ -84,21 +86,31 @@ namespace object_recognition_core
template<typename T>
void
- set_parameter(const std::string & key, const T & value)
+ set_parameter(const std::string& key, const T& value)
{
if (key == "type")
set_type(value);
else
+ {
+ if ((type() != NONCORE) && (raw_.find(key) == raw_.end()))
+ throw std::runtime_error("Key \"" + key + "\" not a default key in db of type " + TypeToString(type()));
+
raw_[key] = or_json::mValue(value);
+ }
}
void
- set_parameter(const std::string & key, const or_json::mValue & value)
+ set_parameter(const std::string& key, const or_json::mValue& value)
{
if (key == "type")
set_type(value.get_str());
else
+ {
+ if ((type() != NONCORE) && (raw_.find(key) == raw_.end()))
+ throw std::runtime_error("Key \"" + key + "\" not a default key in db of type " + TypeToString(type()));
+
raw_[key] = value;
+ }
}
void
@@ -131,10 +143,11 @@ namespace object_recognition_core
protected:
/** The type of the collection 'CouchDB' ... */
ObjectDbType type_;
- /** All the raw parameters: they are of integral types */
+ /** All the raw parameters: they are of integral types. 'type' is there */
or_json::mObject raw_;
};
}
}
#endif /* DB_PARAMETERS_H_ */
+
View
20 src/db/db.cpp
@@ -102,7 +102,7 @@ namespace object_recognition_core
}
}
- ObjectDbParameters::ObjectDbParameters(const or_json::mObject& parameters)
+ ObjectDbParameters::ObjectDbParameters(const ObjectDbParametersRaw& parameters)
{
if (parameters.find("type") == parameters.end())
{
@@ -157,23 +157,25 @@ namespace object_recognition_core
}
void
- ObjectDb::set_parameters(const ObjectDbParameters &in_params)
+ ObjectDb::set_parameters(const ObjectDbParameters& in_params)
{
- ObjectDbParametersRaw params_raw = parameters_.raw();
- switch (parameters_.type())
+ ObjectDbParametersRaw params_raw = in_params.raw();
+
+ switch (in_params.type())
{
case ObjectDbParameters::COUCHDB:
db_ = boost::shared_ptr<ObjectDbBase>(new ObjectDbCouch(params_raw));
- return;
+ break;
case ObjectDbParameters::EMPTY:
- return;
+ break;
case ObjectDbParameters::FILESYSTEM:
db_ = boost::shared_ptr<ObjectDbBase>(new ObjectDbFilesystem(params_raw));
- return;
+ break;
default:
- return;
+ break;
}
- parameters_ = in_params;
+
+ parameters_ = ObjectDbParameters(params_raw);
}
void
Please sign in to comment.
Something went wrong with that request. Please try again.