Skip to content

Commit

Permalink
Merge pull request #1490 from gwenchee/mapstringmapstringdouble
Browse files Browse the repository at this point in the history
adding a new typesystem: mapstringmapstringdouble
  • Loading branch information
gonuke committed Sep 14, 2019
2 parents c00c37c + d056b95 commit 0e1a5f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions news/typesystem.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Added:** None
added mapstringmapstringdouble typesystem. This can be used with C++ archetypes. But not python archetypes.

**Changed:** None

**Deprecated:** None

**Removed:** None

**Fixed:** None

**Security:** None
25 changes: 25 additions & 0 deletions src/query_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ enum DbTypes {
VL_MAP_PAIR_VL_STRING_STRING_INT, // ["std::map<std::pair<std::string, std::string>, int>", 4, ["HDF5","SQLite"], ["VL_MAP", ["PAIR", "VL_STRING", "STRING"], "INT"], true]
VL_MAP_PAIR_VL_STRING_VL_STRING_INT, // ["std::map<std::pair<std::string, std::string>, int>", 4, ["HDF5","SQLite"], ["VL_MAP", ["PAIR", "VL_STRING", "VL_STRING"], "INT"], true]

// map<string, map<string, double> >
MAP_STRING_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "STRING", ["MAP", "STRING", "DOUBLE"]], false]
MAP_STRING_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "STRING", ["MAP", "VL_STRING", "DOUBLE"]], false]
MAP_STRING_VL_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "STRING", ["VL_MAP", "STRING", "DOUBLE"]], false]
MAP_STRING_VL_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "STRING", ["VL_MAP", "VL_STRING", "DOUBLE"]], false]
MAP_VL_STRING_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "VL_STRING", ["MAP", "STRING", "DOUBLE"]], false]
MAP_VL_STRING_VL_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "VL_STRING", ["VL_MAP", "STRING", "DOUBLE"]], false]
MAP_VL_STRING_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "VL_STRING", ["MAP", "VL_STRING", "DOUBLE"]], false]
MAP_VL_STRING_VL_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["MAP", "VL_STRING", ["VL_MAP", "VL_STRING", "DOUBLE"]], false]
VL_MAP_STRING_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "STRING", ["MAP", "STRING", "DOUBLE"]], true]
VL_MAP_VL_STRING_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "VL_STRING", ["MAP", "STRING", "DOUBLE"]], true]
VL_MAP_STRING_VL_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "STRING", ["VL_MAP", "STRING", "DOUBLE"]], true]
VL_MAP_STRING_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "STRING", ["MAP", "VL_STRING", "DOUBLE"]], true]
VL_MAP_STRING_VL_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "STRING", ["VL_MAP", "VL_STRING", "DOUBLE"]], true]
VL_MAP_VL_STRING_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "VL_STRING", ["MAP", "VL_STRING", "DOUBLE"]], true]
VL_MAP_VL_STRING_VL_MAP_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "VL_STRING", ["VL_MAP", "STRING", "DOUBLE"]], true]
VL_MAP_VL_STRING_VL_MAP_VL_STRING_DOUBLE, // ["std::map<std::string, std::map<std::string, double>>", 4, ["HDF5", "SQLite"], ["VL_MAP", "VL_STRING", ["VL_MAP", "VL_STRING", "DOUBLE"]], true]
// append new types only:
};

Expand Down Expand Up @@ -1058,6 +1075,14 @@ class Sha1 {
}
}

inline void Update(const std::map<std::string, std::map<std::string, double>>& x) {
std::map<std::string, std::map<std::string, double>>::const_iterator it = x.begin();
for(; it != x.end(); ++it) {
hash_.process_bytes(it->first.c_str(), it->first.size());
Update(it->second);
}
}

/// \}

Digest digest() {
Expand Down
11 changes: 11 additions & 0 deletions src/sqlite_back.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ void SqliteBack::Bind(boost::spirit::hold_any v, DbTypes type, SqlStatement::Ptr
MAP_PAIR_STRING_STRING_INT,
std::map<std::pair<std::string CYCLUS_COMMA std::string> CYCLUS_COMMA int > );

CYCLUS_BINDVAL(
MAP_STRING_MAP_STRING_DOUBLE,
std::map<std::string CYCLUS_COMMA std::map<std::string CYCLUS_COMMA double> >);

default: {
throw ValueError("attempted to retrieve unsupported sqlite backend type");
}
Expand Down Expand Up @@ -459,6 +463,10 @@ boost::spirit::hold_any SqliteBack::ColAsVal(SqlStatement::Ptr stmt,
MAP_PAIR_STRING_STRING_INT,
std::map<std::pair<std::string CYCLUS_COMMA std::string> CYCLUS_COMMA int > );

CYCLUS_LOADVAL(
MAP_STRING_MAP_STRING_DOUBLE,
std::map<std::string CYCLUS_COMMA std::map<std::string CYCLUS_COMMA double> >);

default: {
throw ValueError("Attempted to retrieve unsupported backend type");
}}
Expand Down Expand Up @@ -550,6 +558,9 @@ DbTypes SqliteBack::Type(boost::spirit::hold_any v) {
type_map[&typeid(
std::map<std::pair<std::string, std::string>, int > )] =
MAP_PAIR_STRING_STRING_INT;

type_map[&typeid(std::map<std::string, std::map<std::string,double> >)] =
MAP_STRING_MAP_STRING_DOUBLE;
}

const std::type_info* ti = &v.type();
Expand Down

0 comments on commit 0e1a5f0

Please sign in to comment.