3 #include <boost/filesystem.hpp>
13 std::string calc_type,
17 m_calc_type(calc_type),
18 m_location(location) {}
41 fs::create_directories(
m_location.parent_path());
46 json_spirit::write_stream((json_spirit::mValue &)json, file.
ofstream(),
64 auto it = json[
"conflict_score"].
begin();
65 auto end = json[
"conflict_score"].
end();
66 for (; it !=
end; ++it) {
73 auto it = json[
"data"].
begin();
74 auto end = json[
"data"].
end();
75 for (; it !=
end; ++it) {
85 "Error in jsonPropertiesDatabase::to_json: Not a JSON object.");
90 json[
"conflict_score"].
put_obj();
94 j[val.first] = val.second.key_comp().score_method();
130 std::string origin)
const {
136 std::set<std::string, PropertiesDatabase::Compare>
160 if (it->second.value_comp().score_method() ==
score) {
166 for (
const auto &origin : it->second) {
179 std::pair<jsonPropertiesDatabase::iterator, bool>
182 return std::make_pair(
_iterator(res.first), res.second);
194 std::string
to_configname,
const std::set<std::string, Compare> &_set) {
209 std::set<std::string, PropertiesDatabase::Compare>
Fully generic database interface for use by DatabaseHandler.
Compare type for std::set<std::string, Compare>, which sorts to determine the 'origin' configname for...
PropertiesDatabaseIterator iterator
double score(std::string origin) const
Score mapping 'origin'->'to'.
std::pair< iterator, bool > insert(const MappedProperties &value)
Insert data.
Wrapper class for specializations PropertiesDatabaseIteratorBase.
PropertiesDatabaseIteratorBase * get() const
std::set< std::string, Compare > _make_set(std::string to_configname, const ScoreMappedProperties &score) const
size_type size() const override
jsonPropertiesDatabase(const PrimClex &_primclex, std::string calc_type, fs::path location)
ScoreMappedProperties m_default_score
void set_score_method(std::string to_configname, const ScoreMappedProperties &score) override
Change the score method for a single configuration.
iterator end() const override
End iterator.
std::map< std::string, std::set< std::string, Compare > > m_origins
std::set< std::string, Compare > all_origins(std::string to_configname) const override
Names of all configurations that relaxed 'origin'->'to'.
iterator find_via_origin(std::string origin) const override
Return iterator to MappedProperties that is from the specified config.
iterator begin() const override
Begin iterator.
iterator find_via_to(std::string to_configname) const override
Return iterator to MappedProperties that is the best mapping to specified config.
DatabaseBase & open() override
std::map< std::string, MappedProperties > m_data
iterator _erase(iterator pos) override
Private _erase MappedProperties, without modifying 'relaxed_from'.
std::pair< iterator, bool > _insert(const MappedProperties &value) override
Private _insert MappedProperties, without modifying 'relaxed_from'.
void from_json(jsonParser const &json)
Clear all and read from JSON.
void _set_all_origins(std::string to_configname, const std::set< std::string, Compare > &_set) override
Names of all configurations that relaxed 'from'->'to'.
jsonParser & to_json(jsonParser &json) const
Export all to JSON.
iterator _iterator(jsonPropertiesDatabaseIterator::base_iterator _it) const
std::map< std::string, MappedProperties >::const_iterator base_iterator
PrimClex is the top-level data structure for a CASM project.
Write to a temporary file to ensure a good write, then rename.
void close()
Closes stream, and if not a failed write, removes "file" and renames "file.tmp" to "file".
void open(fs::path name, std::string tmp_ext="tmp")
Opens "file.tmp" for writing, with intended final target "file".
fs::ofstream & ofstream()
Access underlying stream.
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
iterator end()
Returns iterator to end of JSON object or JSON array.
jsonParser & put_obj()
Puts new empty JSON object.
bool is_obj() const
Check if object type.
GenericDatumFormatter< double, Result > score()
GenericDatumFormatter< std::string, Result > to_configname()
void from_json(ClexDescription &desc, const jsonParser &json)