1 #ifndef CASM_Database_impl
2 #define CASM_Database_impl
15 template <
typename ValueType>
16 std::pair<typename ValDatabase<ValueType>::iterator,
bool>
18 const std::string &
alias) {
19 auto it =
find(name_or_alias);
24 return std::make_pair(it,
false);
27 else if (m_alias_to_name.find(
alias) != m_alias_to_name.end()) {
29 return std::make_pair(it,
false);
36 if (m_alias_to_name.find(name_or_alias) == m_alias_to_name.end()) {
39 auto old_alias_it = m_name_to_alias.find(
name);
41 if (old_alias_it != m_name_to_alias.end()) {
42 m_alias_to_name.erase(old_alias_it->second);
48 name = m_alias_to_name[name_or_alias];
49 m_alias_to_name.erase(name_or_alias);
56 return std::make_pair(it,
true);
64 template <
typename ValueType>
66 const std::string &name_or_alias)
const {
67 auto it = m_alias_to_name.find(name_or_alias);
68 if (it == m_alias_to_name.end()) {
82 template <
typename ValueType>
84 const std::string &name_or_alias)
const {
85 auto it = m_alias_to_name.find(name_or_alias);
88 if (it != m_alias_to_name.end()) {
92 auto name_it = m_name_to_alias.find(name_or_alias);
97 if (name_it == m_name_to_alias.end()) {
98 return std::string(
"");
102 return name_it->second;
105 template <
typename ValueType>
110 fs::path p =
primclex().dir().template aliases<ValueType>();
114 for (
const auto &val : m_name_to_alias) {
115 m_alias_to_name[val.second] = val.first;
120 template <
typename ValueType>
123 throw std::runtime_error(
124 "Error in write_aliases: CASM project has no root directory.");
126 fs::path p =
primclex().dir().template aliases<ValueType>();
127 fs::create_directories(p.parent_path());
std::string name(const std::string &name_or_alias) const
std::string alias(const std::string &name_or_alias) const
Get alias from name_or_alias.
std::pair< iterator, bool > set_alias(const std::string &name_or_alias, const std::string &alias)
For setting an alias.
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.
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
jsonParser const & from_json(ImportSettings &_set, jsonParser const &_json)
GenericDatumFormatter< std::string, DataObject > alias()
GenericDatumFormatter< std::string, DataObject > name()
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.