Commit a5d43998 by Maarten L. Hekkelman

replace tag with item or item_name

parent 2792caec
...@@ -957,32 +957,32 @@ class category ...@@ -957,32 +957,32 @@ class category
{ return prefix + std::to_string(nr + 1); }); { return prefix + std::to_string(nr + 1); });
} }
/// @brief Generate a new, unique value for a item named @a tag /// @brief Generate a new, unique value for a item named @a item_name
/// @param tag The name of the item /// @param item_name The name of the item
/// @return a new unique value /// @return a new unique value
std::string get_unique_value(std::string_view tag); std::string get_unique_value(std::string_view item_name);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/// \brief Update a single item named @a tag in the rows that match \a cond to value \a value /// \brief Update a single item named @a item_name in the rows that match \a cond to value \a value
/// making sure the linked categories are updated according to the link. /// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute /// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split. /// and unique. If they are not, the child category rows are split.
void update_value(condition &&cond, std::string_view tag, std::string_view value) void update_value(condition &&cond, std::string_view item_name, std::string_view value)
{ {
auto rs = find(std::move(cond)); auto rs = find(std::move(cond));
std::vector<row_handle> rows; std::vector<row_handle> rows;
std::copy(rs.begin(), rs.end(), std::back_inserter(rows)); std::copy(rs.begin(), rs.end(), std::back_inserter(rows));
update_value(rows, tag, value); update_value(rows, item_name, value);
} }
/// \brief Update a single item named @a tag in @a rows to value \a value /// \brief Update a single item named @a item_name in @a rows to value \a value
/// making sure the linked categories are updated according to the link. /// making sure the linked categories are updated according to the link.
/// That means, child categories are updated if the links are absolute /// That means, child categories are updated if the links are absolute
/// and unique. If they are not, the child category rows are split. /// and unique. If they are not, the child category rows are split.
void update_value(const std::vector<row_handle> &rows, std::string_view tag, std::string_view value); void update_value(const std::vector<row_handle> &rows, std::string_view item_name, std::string_view value);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Naming used to be very inconsistent. For backward compatibility, // Naming used to be very inconsistent. For backward compatibility,
...@@ -1140,7 +1140,15 @@ class category ...@@ -1140,7 +1140,15 @@ class category
/// This function returns effectively the list of fully qualified item /// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item /// names, that is category_name + '.' + item_name for each item
std::vector<std::string> get_tag_order() const; [[deprecated("use get_item_order instead")]]
std::vector<std::string> get_tag_order() const
{
return get_item_order();
}
/// This function returns effectively the list of fully qualified item
/// names, that is category_name + '.' + item_name for each item
std::vector<std::string> get_item_order() const;
/// Write the contents of the category to the std::ostream @a os /// Write the contents of the category to the std::ostream @a os
void write(std::ostream &os) const; void write(std::ostream &os) const;
......
...@@ -314,14 +314,14 @@ namespace detail ...@@ -314,14 +314,14 @@ namespace detail
{ {
struct key_is_empty_condition_impl : public condition_impl struct key_is_empty_condition_impl : public condition_impl
{ {
key_is_empty_condition_impl(const std::string &item_tag) key_is_empty_condition_impl(const std::string &item_name)
: m_item_tag(item_tag) : m_item_name(item_name)
{ {
} }
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
{ {
m_item_ix = get_item_ix(c, m_item_tag); m_item_ix = get_item_ix(c, m_item_name);
return this; return this;
} }
...@@ -332,23 +332,23 @@ namespace detail ...@@ -332,23 +332,23 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << m_item_tag << " IS NULL"; os << m_item_name << " IS NULL";
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix = 0; uint16_t m_item_ix = 0;
}; };
struct key_is_not_empty_condition_impl : public condition_impl struct key_is_not_empty_condition_impl : public condition_impl
{ {
key_is_not_empty_condition_impl(const std::string &item_tag) key_is_not_empty_condition_impl(const std::string &item_name)
: m_item_tag(item_tag) : m_item_name(item_name)
{ {
} }
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
{ {
m_item_ix = get_item_ix(c, m_item_tag); m_item_ix = get_item_ix(c, m_item_name);
return this; return this;
} }
...@@ -359,17 +359,17 @@ namespace detail ...@@ -359,17 +359,17 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << m_item_tag << " IS NOT NULL"; os << m_item_name << " IS NOT NULL";
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix = 0; uint16_t m_item_ix = 0;
}; };
struct key_equals_condition_impl : public condition_impl struct key_equals_condition_impl : public condition_impl
{ {
key_equals_condition_impl(item &&i) key_equals_condition_impl(item &&i)
: m_item_tag(i.name()) : m_item_name(i.name())
, m_value(i.value()) , m_value(i.value())
{ {
} }
...@@ -383,7 +383,7 @@ namespace detail ...@@ -383,7 +383,7 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << m_item_tag << (m_icase ? "^ " : " ") << " == " << m_value; os << m_item_name << (m_icase ? "^ " : " ") << " == " << m_value;
} }
virtual std::optional<row_handle> single() const override virtual std::optional<row_handle> single() const override
...@@ -399,13 +399,13 @@ namespace detail ...@@ -399,13 +399,13 @@ namespace detail
if (m_single_hit.has_value() or ri->m_single_hit.has_value()) if (m_single_hit.has_value() or ri->m_single_hit.has_value())
return m_single_hit == ri->m_single_hit; return m_single_hit == ri->m_single_hit;
else else
// watch out, both m_item_ix might be the same while tags might be diffent (in case they both do not exist in the category) // watch out, both m_item_ix might be the same while item_names might be diffent (in case they both do not exist in the category)
return m_item_ix == ri->m_item_ix and m_value == ri->m_value and m_item_tag == ri->m_item_tag; return m_item_ix == ri->m_item_ix and m_value == ri->m_value and m_item_name == ri->m_item_name;
} }
return this == rhs; return this == rhs;
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix = 0; uint16_t m_item_ix = 0;
bool m_icase = false; bool m_icase = false;
std::string m_value; std::string m_value;
...@@ -415,7 +415,7 @@ namespace detail ...@@ -415,7 +415,7 @@ namespace detail
struct key_equals_or_empty_condition_impl : public condition_impl struct key_equals_or_empty_condition_impl : public condition_impl
{ {
key_equals_or_empty_condition_impl(key_equals_condition_impl *equals) key_equals_or_empty_condition_impl(key_equals_condition_impl *equals)
: m_item_tag(equals->m_item_tag) : m_item_name(equals->m_item_name)
, m_value(equals->m_value) , m_value(equals->m_value)
, m_icase(equals->m_icase) , m_icase(equals->m_icase)
, m_single_hit(equals->m_single_hit) , m_single_hit(equals->m_single_hit)
...@@ -424,8 +424,8 @@ namespace detail ...@@ -424,8 +424,8 @@ namespace detail
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
{ {
m_item_ix = get_item_ix(c, m_item_tag); m_item_ix = get_item_ix(c, m_item_name);
m_icase = is_item_type_uchar(c, m_item_tag); m_icase = is_item_type_uchar(c, m_item_name);
return this; return this;
} }
...@@ -441,7 +441,7 @@ namespace detail ...@@ -441,7 +441,7 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << '(' << m_item_tag << (m_icase ? "^ " : " ") << " == " << m_value << " OR " << m_item_tag << " IS NULL)"; os << '(' << m_item_name << (m_icase ? "^ " : " ") << " == " << m_value << " OR " << m_item_name << " IS NULL)";
} }
virtual std::optional<row_handle> single() const override virtual std::optional<row_handle> single() const override
...@@ -457,13 +457,13 @@ namespace detail ...@@ -457,13 +457,13 @@ namespace detail
if (m_single_hit.has_value() or ri->m_single_hit.has_value()) if (m_single_hit.has_value() or ri->m_single_hit.has_value())
return m_single_hit == ri->m_single_hit; return m_single_hit == ri->m_single_hit;
else else
// watch out, both m_item_ix might be the same while tags might be diffent (in case they both do not exist in the category) // watch out, both m_item_ix might be the same while item_names might be diffent (in case they both do not exist in the category)
return m_item_ix == ri->m_item_ix and m_value == ri->m_value and m_item_tag == ri->m_item_tag; return m_item_ix == ri->m_item_ix and m_value == ri->m_value and m_item_name == ri->m_item_name;
} }
return this == rhs; return this == rhs;
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix = 0; uint16_t m_item_ix = 0;
std::string m_value; std::string m_value;
bool m_icase = false; bool m_icase = false;
...@@ -473,8 +473,8 @@ namespace detail ...@@ -473,8 +473,8 @@ namespace detail
struct key_compare_condition_impl : public condition_impl struct key_compare_condition_impl : public condition_impl
{ {
template <typename COMP> template <typename COMP>
key_compare_condition_impl(const std::string &item_tag, COMP &&comp, const std::string &s) key_compare_condition_impl(const std::string &item_name, COMP &&comp, const std::string &s)
: m_item_tag(item_tag) : m_item_name(item_name)
, m_compare(std::move(comp)) , m_compare(std::move(comp))
, m_str(s) , m_str(s)
{ {
...@@ -482,8 +482,8 @@ namespace detail ...@@ -482,8 +482,8 @@ namespace detail
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
{ {
m_item_ix = get_item_ix(c, m_item_tag); m_item_ix = get_item_ix(c, m_item_name);
m_icase = is_item_type_uchar(c, m_item_tag); m_icase = is_item_type_uchar(c, m_item_name);
return this; return this;
} }
...@@ -494,10 +494,10 @@ namespace detail ...@@ -494,10 +494,10 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << m_item_tag << (m_icase ? "^ " : " ") << m_str; os << m_item_name << (m_icase ? "^ " : " ") << m_str;
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix = 0; uint16_t m_item_ix = 0;
bool m_icase = false; bool m_icase = false;
std::function<bool(row_handle, bool)> m_compare; std::function<bool(row_handle, bool)> m_compare;
...@@ -506,8 +506,8 @@ namespace detail ...@@ -506,8 +506,8 @@ namespace detail
struct key_matches_condition_impl : public condition_impl struct key_matches_condition_impl : public condition_impl
{ {
key_matches_condition_impl(const std::string &item_tag, const std::regex &rx) key_matches_condition_impl(const std::string &item_name, const std::regex &rx)
: m_item_tag(item_tag) : m_item_name(item_name)
, m_item_ix(0) , m_item_ix(0)
, mRx(rx) , mRx(rx)
{ {
...@@ -515,7 +515,7 @@ namespace detail ...@@ -515,7 +515,7 @@ namespace detail
condition_impl *prepare(const category &c) override condition_impl *prepare(const category &c) override
{ {
m_item_ix = get_item_ix(c, m_item_tag); m_item_ix = get_item_ix(c, m_item_name);
return this; return this;
} }
...@@ -527,10 +527,10 @@ namespace detail ...@@ -527,10 +527,10 @@ namespace detail
void str(std::ostream &os) const override void str(std::ostream &os) const override
{ {
os << m_item_tag << " =~ expression"; os << m_item_name << " =~ expression";
} }
std::string m_item_tag; std::string m_item_name;
uint16_t m_item_ix; uint16_t m_item_ix;
std::regex mRx; std::regex mRx;
}; };
...@@ -873,7 +873,7 @@ inline condition operator or(condition &&a, condition &&b) ...@@ -873,7 +873,7 @@ inline condition operator or(condition &&a, condition &&b)
auto ci = static_cast<detail::key_equals_condition_impl *>(a.m_impl); auto ci = static_cast<detail::key_equals_condition_impl *>(a.m_impl);
auto ce = static_cast<detail::key_is_empty_condition_impl *>(b.m_impl); auto ce = static_cast<detail::key_is_empty_condition_impl *>(b.m_impl);
if (ci->m_item_tag == ce->m_item_tag) if (ci->m_item_name == ce->m_item_name)
return condition(new detail::key_equals_or_empty_condition_impl(ci)); return condition(new detail::key_equals_or_empty_condition_impl(ci));
} }
else if (typeid(*b.m_impl) == typeid(detail::key_equals_condition_impl) and else if (typeid(*b.m_impl) == typeid(detail::key_equals_condition_impl) and
...@@ -882,7 +882,7 @@ inline condition operator or(condition &&a, condition &&b) ...@@ -882,7 +882,7 @@ inline condition operator or(condition &&a, condition &&b)
auto ci = static_cast<detail::key_equals_condition_impl *>(b.m_impl); auto ci = static_cast<detail::key_equals_condition_impl *>(b.m_impl);
auto ce = static_cast<detail::key_is_empty_condition_impl *>(a.m_impl); auto ce = static_cast<detail::key_is_empty_condition_impl *>(a.m_impl);
if (ci->m_item_tag == ce->m_item_tag) if (ci->m_item_name == ce->m_item_name)
return condition(new detail::key_equals_or_empty_condition_impl(ci)); return condition(new detail::key_equals_or_empty_condition_impl(ci));
} }
...@@ -924,39 +924,39 @@ inline constexpr empty_type null = empty_type(); ...@@ -924,39 +924,39 @@ inline constexpr empty_type null = empty_type();
struct key struct key
{ {
/** /**
* @brief Construct a new key object using @a itemTag as name * @brief Construct a new key object using @a item_name as name
* *
* @param itemTag * @param item_name
*/ */
explicit key(const std::string &itemTag) explicit key(const std::string &item_name)
: m_item_tag(itemTag) : m_item_name(item_name)
{ {
} }
/** /**
* @brief Construct a new key object using @a itemTag as name * @brief Construct a new key object using @a item_name as name
* *
* @param itemTag * @param item_name
*/ */
explicit key(const char *itemTag) explicit key(const char *item_name)
: m_item_tag(itemTag) : m_item_name(item_name)
{ {
} }
/** /**
* @brief Construct a new key object using @a itemTag as name * @brief Construct a new key object using @a item_name as name
* *
* @param itemTag * @param item_name
*/ */
explicit key(std::string_view itemTag) explicit key(std::string_view item_name)
: m_item_tag(itemTag) : m_item_name(item_name)
{ {
} }
key(const key &) = delete; key(const key &) = delete;
key &operator=(const key &) = delete; key &operator=(const key &) = delete;
std::string m_item_tag; ///< The item name std::string m_item_name; ///< The item name
}; };
/** /**
...@@ -965,7 +965,7 @@ struct key ...@@ -965,7 +965,7 @@ struct key
template <typename T> template <typename T>
condition operator==(const key &key, const T &v) condition operator==(const key &key, const T &v)
{ {
return condition(new detail::key_equals_condition_impl({ key.m_item_tag, v })); return condition(new detail::key_equals_condition_impl({ key.m_item_name, v }));
} }
/** /**
...@@ -974,9 +974,9 @@ condition operator==(const key &key, const T &v) ...@@ -974,9 +974,9 @@ condition operator==(const key &key, const T &v)
inline condition operator==(const key &key, std::string_view value) inline condition operator==(const key &key, std::string_view value)
{ {
if (not value.empty()) if (not value.empty())
return condition(new detail::key_equals_condition_impl({ key.m_item_tag, value })); return condition(new detail::key_equals_condition_impl({ key.m_item_name, value }));
else else
return condition(new detail::key_is_empty_condition_impl(key.m_item_tag)); return condition(new detail::key_is_empty_condition_impl(key.m_item_name));
} }
/** /**
...@@ -1006,8 +1006,8 @@ condition operator>(const key &key, const T &v) ...@@ -1006,8 +1006,8 @@ condition operator>(const key &key, const T &v)
s << " > " << v; s << " > " << v;
return condition(new detail::key_compare_condition_impl( return condition(new detail::key_compare_condition_impl(
key.m_item_tag, [tag = key.m_item_tag, v](row_handle r, bool icase) key.m_item_name, [item_name = key.m_item_name, v](row_handle r, bool icase)
{ return r[tag].template compare<T>(v, icase) > 0; }, { return r[item_name].template compare<T>(v, icase) > 0; },
s.str())); s.str()));
} }
...@@ -1021,8 +1021,8 @@ condition operator>=(const key &key, const T &v) ...@@ -1021,8 +1021,8 @@ condition operator>=(const key &key, const T &v)
s << " >= " << v; s << " >= " << v;
return condition(new detail::key_compare_condition_impl( return condition(new detail::key_compare_condition_impl(
key.m_item_tag, [tag = key.m_item_tag, v](row_handle r, bool icase) key.m_item_name, [item_name = key.m_item_name, v](row_handle r, bool icase)
{ return r[tag].template compare<T>(v, icase) >= 0; }, { return r[item_name].template compare<T>(v, icase) >= 0; },
s.str())); s.str()));
} }
...@@ -1036,8 +1036,8 @@ condition operator<(const key &key, const T &v) ...@@ -1036,8 +1036,8 @@ condition operator<(const key &key, const T &v)
s << " < " << v; s << " < " << v;
return condition(new detail::key_compare_condition_impl( return condition(new detail::key_compare_condition_impl(
key.m_item_tag, [tag = key.m_item_tag, v](row_handle r, bool icase) key.m_item_name, [item_name = key.m_item_name, v](row_handle r, bool icase)
{ return r[tag].template compare<T>(v, icase) < 0; }, { return r[item_name].template compare<T>(v, icase) < 0; },
s.str())); s.str()));
} }
...@@ -1051,8 +1051,8 @@ condition operator<=(const key &key, const T &v) ...@@ -1051,8 +1051,8 @@ condition operator<=(const key &key, const T &v)
s << " <= " << v; s << " <= " << v;
return condition(new detail::key_compare_condition_impl( return condition(new detail::key_compare_condition_impl(
key.m_item_tag, [tag = key.m_item_tag, v](row_handle r, bool icase) key.m_item_name, [item_name = key.m_item_name, v](row_handle r, bool icase)
{ return r[tag].template compare<T>(v, icase) <= 0; }, { return r[item_name].template compare<T>(v, icase) <= 0; },
s.str())); s.str()));
} }
...@@ -1061,7 +1061,7 @@ condition operator<=(const key &key, const T &v) ...@@ -1061,7 +1061,7 @@ condition operator<=(const key &key, const T &v)
*/ */
inline condition operator==(const key &key, const std::regex &rx) inline condition operator==(const key &key, const std::regex &rx)
{ {
return condition(new detail::key_matches_condition_impl(key.m_item_tag, rx)); return condition(new detail::key_matches_condition_impl(key.m_item_name, rx));
} }
/** /**
...@@ -1069,7 +1069,7 @@ inline condition operator==(const key &key, const std::regex &rx) ...@@ -1069,7 +1069,7 @@ inline condition operator==(const key &key, const std::regex &rx)
*/ */
inline condition operator==(const key &key, const empty_type &) inline condition operator==(const key &key, const empty_type &)
{ {
return condition(new detail::key_is_empty_condition_impl(key.m_item_tag)); return condition(new detail::key_is_empty_condition_impl(key.m_item_name));
} }
/** /**
...@@ -1077,7 +1077,7 @@ inline condition operator==(const key &key, const empty_type &) ...@@ -1077,7 +1077,7 @@ inline condition operator==(const key &key, const empty_type &)
*/ */
inline condition operator!=(const key &key, const empty_type &) inline condition operator!=(const key &key, const empty_type &)
{ {
return condition(new detail::key_is_not_empty_condition_impl(key.m_item_tag)); return condition(new detail::key_is_not_empty_condition_impl(key.m_item_name));
} }
/** /**
...@@ -1088,9 +1088,9 @@ template <typename T> ...@@ -1088,9 +1088,9 @@ template <typename T>
condition operator==(const key &key, const std::optional<T> &v) condition operator==(const key &key, const std::optional<T> &v)
{ {
if (v.has_value()) if (v.has_value())
return condition(new detail::key_equals_condition_impl({ key.m_item_tag, *v })); return condition(new detail::key_equals_condition_impl({ key.m_item_name, *v }));
else else
return condition(new detail::key_is_empty_condition_impl(key.m_item_tag)); return condition(new detail::key_is_empty_condition_impl(key.m_item_name));
} }
/** /**
......
...@@ -169,7 +169,16 @@ class datablock : public std::list<category> ...@@ -169,7 +169,16 @@ class datablock : public std::list<category>
/** /**
* @brief Get the preferred order of the categories when writing them * @brief Get the preferred order of the categories when writing them
*/ */
std::vector<std::string> get_tag_order() const; [[deprecated("use get_item_order instead")]]
std::vector<std::string> get_tag_order() const
{
return get_item_order();
}
/**
* @brief Get the preferred order of the categories when writing them
*/
std::vector<std::string> get_item_order() const;
/** /**
* @brief Write out the contents to @a os * @brief Write out the contents to @a os
...@@ -177,9 +186,9 @@ class datablock : public std::list<category> ...@@ -177,9 +186,9 @@ class datablock : public std::list<category>
void write(std::ostream &os) const; void write(std::ostream &os) const;
/** /**
* @brief Write out the contents to @a os using the order defined in @a tag_order * @brief Write out the contents to @a os using the order defined in @a item_name_order
*/ */
void write(std::ostream &os, const std::vector<std::string> &tag_order); void write(std::ostream &os, const std::vector<std::string> &item_name_order);
/** /**
* @brief Friend operator<< to write datablock @a db to std::ostream @a os * @brief Friend operator<< to write datablock @a db to std::ostream @a os
......
...@@ -143,9 +143,9 @@ class sac_parser ...@@ -143,9 +143,9 @@ class sac_parser
enum class CIFToken enum class CIFToken
{ {
Unknown, UNKNOWN,
Eof, END_OF_FILE,
DATA, DATA,
LOOP, LOOP,
...@@ -153,24 +153,24 @@ class sac_parser ...@@ -153,24 +153,24 @@ class sac_parser
SAVE_, SAVE_,
SAVE_NAME, SAVE_NAME,
STOP, STOP,
Tag, ITEM_NAME,
Value VALUE
}; };
static constexpr const char *get_token_name(CIFToken token) static constexpr const char *get_token_name(CIFToken token)
{ {
switch (token) switch (token)
{ {
case CIFToken::Unknown: return "Unknown"; case CIFToken::UNKNOWN: return "Unknown";
case CIFToken::Eof: return "Eof"; case CIFToken::END_OF_FILE: return "Eof";
case CIFToken::DATA: return "DATA"; case CIFToken::DATA: return "DATA";
case CIFToken::LOOP: return "LOOP"; case CIFToken::LOOP: return "LOOP";
case CIFToken::GLOBAL: return "GLOBAL"; case CIFToken::GLOBAL: return "GLOBAL";
case CIFToken::SAVE_: return "SAVE"; case CIFToken::SAVE_: return "SAVE";
case CIFToken::SAVE_NAME: return "SAVE+name"; case CIFToken::SAVE_NAME: return "SAVE+name";
case CIFToken::STOP: return "STOP"; case CIFToken::STOP: return "STOP";
case CIFToken::Tag: return "Tag"; case CIFToken::ITEM_NAME: return "Tag";
case CIFToken::Value: return "Value"; case CIFToken::VALUE: return "Value";
default: return "Invalid token parameter"; default: return "Invalid token parameter";
} }
} }
...@@ -267,7 +267,7 @@ class sac_parser ...@@ -267,7 +267,7 @@ class sac_parser
QuotedString, QuotedString,
QuotedStringQuote, QuotedStringQuote,
UnquotedString, UnquotedString,
Tag, ItemName,
TextItem, TextItem,
TextItemNL, TextItemNL,
Reserved, Reserved,
......
...@@ -317,7 +317,7 @@ inline char tolower(int ch) ...@@ -317,7 +317,7 @@ inline char tolower(int ch)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** \brief return a tuple consisting of the category and item name for @a tag /** \brief return a tuple consisting of the category and item name for @a item_name
* *
* The category name is stripped of its leading underscore character. * The category name is stripped of its leading underscore character.
* *
...@@ -325,7 +325,19 @@ inline char tolower(int ch) ...@@ -325,7 +325,19 @@ inline char tolower(int ch)
* cif 1.0 formatted data. * cif 1.0 formatted data.
*/ */
std::tuple<std::string, std::string> split_tag_name(std::string_view tag); [[deprecated("use split_item_name instead")]]
std::tuple<std::string, std::string> split_tag_name(std::string_view item_name);
/** \brief return a tuple consisting of the category and item name for @a item_name
*
* The category name is stripped of its leading underscore character.
*
* If no dot character was found, the category name is empty. That's for
* cif 1.0 formatted data.
*/
std::tuple<std::string, std::string> split_item_name(std::string_view item_name);
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -266,7 +266,7 @@ struct item_alias ...@@ -266,7 +266,7 @@ struct item_alias
*/ */
struct item_validator struct item_validator
{ {
std::string m_tag; ///< The item name std::string m_item_name; ///< The item name
bool m_mandatory; ///< Flag indicating this item is mandatory bool m_mandatory; ///< Flag indicating this item is mandatory
const type_validator *m_type; ///< The type for this item const type_validator *m_type; ///< The type for this item
cif::iset m_enums; ///< If filled, the set of allowed values cif::iset m_enums; ///< If filled, the set of allowed values
...@@ -277,13 +277,13 @@ struct item_validator ...@@ -277,13 +277,13 @@ struct item_validator
/// @brief Compare based on the name /// @brief Compare based on the name
bool operator<(const item_validator &rhs) const bool operator<(const item_validator &rhs) const
{ {
return icompare(m_tag, rhs.m_tag) < 0; return icompare(m_item_name, rhs.m_item_name) < 0;
} }
/// @brief Compare based on the name /// @brief Compare based on the name
bool operator==(const item_validator &rhs) const bool operator==(const item_validator &rhs) const
{ {
return iequals(m_tag, rhs.m_tag); return iequals(m_item_name, rhs.m_item_name);
} }
/// @brief Validate the value in @a value for this item /// @brief Validate the value in @a value for this item
...@@ -317,11 +317,11 @@ struct category_validator ...@@ -317,11 +317,11 @@ struct category_validator
/// @brief Add item_validator @a v to the list of item validators /// @brief Add item_validator @a v to the list of item validators
void add_item_validator(item_validator &&v); void add_item_validator(item_validator &&v);
/// @brief Return the item_validator for item @a tag, may return nullptr /// @brief Return the item_validator for item @a item_name, may return nullptr
const item_validator *get_validator_for_item(std::string_view tag) const; const item_validator *get_validator_for_item(std::string_view item_name) const;
/// @brief Return the item_validator for an item that has as alias name @a tag, may return nullptr /// @brief Return the item_validator for an item that has as alias name @a item_name, may return nullptr
const item_validator *get_validator_for_aliased_item(std::string_view tag) const; const item_validator *get_validator_for_aliased_item(std::string_view item_name) const;
}; };
/** /**
......
...@@ -648,7 +648,7 @@ iset category::key_items() const ...@@ -648,7 +648,7 @@ iset category::key_items() const
iset result; iset result;
for (auto &iv : m_cat_validator->m_item_validators) for (auto &iv : m_cat_validator->m_item_validators)
result.insert(iv.m_tag); result.insert(iv.m_item_name);
return result; return result;
} }
...@@ -1280,17 +1280,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator) ...@@ -1280,17 +1280,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
std::string result = generator(static_cast<int>(m_last_unique_num++)); std::string result = generator(static_cast<int>(m_last_unique_num++));
std::string id_tag = "id"; std::string id_name = "id";
if (m_cat_validator != nullptr and m_cat_validator->m_keys.size() == 1) if (m_cat_validator != nullptr and m_cat_validator->m_keys.size() == 1)
{ {
id_tag = m_cat_validator->m_keys.front(); id_name = m_cat_validator->m_keys.front();
if (m_index == nullptr and m_cat_validator != nullptr) if (m_index == nullptr and m_cat_validator != nullptr)
m_index = new category_index(*this); m_index = new category_index(*this);
for (;;) for (;;)
{ {
if (m_index->find_by_value(*this, { { id_tag, result } }) == nullptr) if (m_index->find_by_value(*this, { { id_name, result } }) == nullptr)
break; break;
result = generator(static_cast<int>(m_last_unique_num++)); result = generator(static_cast<int>(m_last_unique_num++));
} }
...@@ -1299,7 +1299,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator) ...@@ -1299,7 +1299,7 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
{ {
for (;;) for (;;)
{ {
if (not contains(key(id_tag) == result)) if (not contains(key(id_name) == result))
break; break;
result = generator(static_cast<int>(m_last_unique_num++)); result = generator(static_cast<int>(m_last_unique_num++));
...@@ -1309,17 +1309,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator) ...@@ -1309,17 +1309,17 @@ std::string category::get_unique_id(std::function<std::string(int)> generator)
return result; return result;
} }
std::string category::get_unique_value(std::string_view tag) std::string category::get_unique_value(std::string_view item_name)
{ {
std::string result; std::string result;
if (m_validator and m_cat_validator) if (m_validator and m_cat_validator)
{ {
auto iv = m_cat_validator->get_validator_for_item(tag); auto iv = m_cat_validator->get_validator_for_item(item_name);
if (iv and iv->m_type and iv->m_type->m_primitive_type == DDL_PrimitiveType::Numb) if (iv and iv->m_type and iv->m_type->m_primitive_type == DDL_PrimitiveType::Numb)
{ {
uint64_t v = find_max<uint64_t>(tag); uint64_t v = find_max<uint64_t>(item_name);
result = std::to_string(v + 1); result = std::to_string(v + 1);
} }
} }
...@@ -1331,7 +1331,7 @@ std::string category::get_unique_value(std::string_view tag) ...@@ -1331,7 +1331,7 @@ std::string category::get_unique_value(std::string_view tag)
{ {
// result = m_name + "-" + std::to_string(ix); // result = m_name + "-" + std::to_string(ix);
result = cif_id_for_number(ix); result = cif_id_for_number(ix);
if (not contains(key(tag) == result)) if (not contains(key(item_name) == result))
break; break;
} }
} }
...@@ -1339,14 +1339,14 @@ std::string category::get_unique_value(std::string_view tag) ...@@ -1339,14 +1339,14 @@ std::string category::get_unique_value(std::string_view tag)
return result; return result;
} }
void category::update_value(const std::vector<row_handle> &rows, std::string_view tag, std::string_view value) void category::update_value(const std::vector<row_handle> &rows, std::string_view item_name, std::string_view value)
{ {
using namespace std::literals; using namespace std::literals;
if (rows.empty()) if (rows.empty())
return; return;
auto colIx = get_item_ix(tag); auto colIx = get_item_ix(item_name);
if (colIx >= m_items.size()) if (colIx >= m_items.size())
throw std::runtime_error("Invalid item " + std::string{ value } + " for " + m_name); throw std::runtime_error("Invalid item " + std::string{ value } + " for " + m_name);
...@@ -1357,10 +1357,10 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie ...@@ -1357,10 +1357,10 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
(*col.m_validator)(value); (*col.m_validator)(value);
// first some sanity checks, what was the old value and is it the same for all rows? // first some sanity checks, what was the old value and is it the same for all rows?
std::string oldValue{ rows.front()[tag].text() }; std::string oldValue{ rows.front()[item_name].text() };
for (auto row : rows) for (auto row : rows)
{ {
if (oldValue != row[tag].text()) if (oldValue != row[item_name].text())
throw std::runtime_error("Inconsistent old values in update_value"); throw std::runtime_error("Inconsistent old values in update_value");
} }
...@@ -1376,20 +1376,20 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie ...@@ -1376,20 +1376,20 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
{ {
for (auto &&[childCat, linked] : m_child_links) for (auto &&[childCat, linked] : m_child_links)
{ {
if (std::find(linked->m_parent_keys.begin(), linked->m_parent_keys.end(), tag) == linked->m_parent_keys.end()) if (std::find(linked->m_parent_keys.begin(), linked->m_parent_keys.end(), item_name) == linked->m_parent_keys.end())
continue; continue;
condition cond; condition cond;
std::string childTag; std::string childItemName;
for (size_t ix = 0; ix < linked->m_parent_keys.size(); ++ix) for (size_t ix = 0; ix < linked->m_parent_keys.size(); ++ix)
{ {
std::string pk = linked->m_parent_keys[ix]; std::string pk = linked->m_parent_keys[ix];
std::string ck = linked->m_child_keys[ix]; std::string ck = linked->m_child_keys[ix];
if (pk == tag) if (pk == item_name)
{ {
childTag = ck; childItemName = ck;
cond = std::move(cond) && key(ck) == oldValue; cond = std::move(cond) && key(ck) == oldValue;
} }
else else
...@@ -1436,7 +1436,7 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie ...@@ -1436,7 +1436,7 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
std::string pk = linked->m_parent_keys[ix]; std::string pk = linked->m_parent_keys[ix];
std::string ck = linked->m_child_keys[ix]; std::string ck = linked->m_child_keys[ix];
if (pk == tag) if (pk == item_name)
check = std::move(check) && key(ck) == value; check = std::move(check) && key(ck) == value;
else else
check = std::move(check) && key(ck) == parent[pk].text(); check = std::move(check) && key(ck) == parent[pk].text();
...@@ -1458,12 +1458,12 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie ...@@ -1458,12 +1458,12 @@ void category::update_value(const std::vector<row_handle> &rows, std::string_vie
// cannot update this... // cannot update this...
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::cerr << "Cannot update child " << childCat->m_name << "." << childTag << " with value " << value << '\n'; std::cerr << "Cannot update child " << childCat->m_name << "." << childItemName << " with value " << value << '\n';
} }
// finally, update the children // finally, update the children
if (not process.empty()) if (not process.empty())
childCat->update_value(process, childTag, value); childCat->update_value(process, childItemName, value);
} }
} }
} }
...@@ -1521,11 +1521,11 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo ...@@ -1521,11 +1521,11 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
for (auto &&[childCat, linked] : m_child_links) for (auto &&[childCat, linked] : m_child_links)
{ {
if (std::find(linked->m_parent_keys.begin(), linked->m_parent_keys.end(), iv->m_tag) == linked->m_parent_keys.end()) if (std::find(linked->m_parent_keys.begin(), linked->m_parent_keys.end(), iv->m_item_name) == linked->m_parent_keys.end())
continue; continue;
condition cond; condition cond;
std::string childTag; std::string childItemName;
for (size_t ix = 0; ix < linked->m_parent_keys.size(); ++ix) for (size_t ix = 0; ix < linked->m_parent_keys.size(); ++ix)
{ {
...@@ -1534,9 +1534,9 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo ...@@ -1534,9 +1534,9 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
// TODO: add code to *NOT* test mandatory items for Empty // TODO: add code to *NOT* test mandatory items for Empty
if (pk == iv->m_tag) if (pk == iv->m_item_name)
{ {
childTag = ck; childItemName = ck;
cond = std::move(cond) and key(ck) == oldStrValue; cond = std::move(cond) and key(ck) == oldStrValue;
} }
else else
...@@ -1569,7 +1569,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo ...@@ -1569,7 +1569,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
std::string pk = linked->m_parent_keys[ix]; std::string pk = linked->m_parent_keys[ix];
std::string ck = linked->m_child_keys[ix]; std::string ck = linked->m_child_keys[ix];
if (pk == iv->m_tag) if (pk == iv->m_item_name)
cond_n = std::move(cond_n) and key(ck) == value; cond_n = std::move(cond_n) and key(ck) == value;
else else
{ {
...@@ -1591,7 +1591,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo ...@@ -1591,7 +1591,7 @@ void category::update_value(row *row, uint16_t item, std::string_view value, boo
} }
for (auto cr : rows) for (auto cr : rows)
cr.assign(childTag, value, false); cr.assign(childItemName, value, false);
} }
} }
} }
...@@ -1884,7 +1884,7 @@ namespace detail ...@@ -1884,7 +1884,7 @@ namespace detail
} // namespace detail } // namespace detail
std::vector<std::string> category::get_tag_order() const std::vector<std::string> category::get_item_order() const
{ {
std::vector<std::string> result; std::vector<std::string> result;
for (auto &c : m_items) for (auto &c : m_items)
...@@ -2032,10 +2032,10 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool ...@@ -2032,10 +2032,10 @@ void category::write(std::ostream &os, const std::vector<uint16_t> &order, bool
for (auto &col : m_items) for (auto &col : m_items)
{ {
std::string tag = '_' + m_name + '.' + col.m_name; std::string item_name = '_' + m_name + '.' + col.m_name;
if (l < tag.length()) if (l < item_name.length())
l = tag.length(); l = item_name.length();
} }
l += 3; l += 3;
...@@ -2107,9 +2107,9 @@ bool category::operator==(const category &rhs) const ...@@ -2107,9 +2107,9 @@ bool category::operator==(const category &rhs) const
using namespace std::placeholders; using namespace std::placeholders;
// set<std::string> tagsA(a.items()), tagsB(b.items()); // set<std::string> item_namesA(a.items()), item_namesB(b.items());
// //
// if (tagsA != tagsB) // if (item_namesA != item_namesB)
// std::cout << "Unequal number of items\n"; // std::cout << "Unequal number of items\n";
const category_validator *catValidator = nullptr; const category_validator *catValidator = nullptr;
...@@ -2119,40 +2119,40 @@ bool category::operator==(const category &rhs) const ...@@ -2119,40 +2119,40 @@ bool category::operator==(const category &rhs) const
catValidator = validator->get_validator_for_category(a.name()); catValidator = validator->get_validator_for_category(a.name());
typedef std::function<int(std::string_view, std::string_view)> compType; typedef std::function<int(std::string_view, std::string_view)> compType;
std::vector<std::tuple<std::string, compType>> tags; std::vector<std::tuple<std::string, compType>> item_names;
std::vector<std::string> keys; std::vector<std::string> keys;
std::vector<size_t> keyIx; std::vector<size_t> keyIx;
if (catValidator == nullptr) if (catValidator == nullptr)
{ {
for (auto &tag : a.get_items()) for (auto &item_name : a.get_items())
{ {
tags.push_back(std::make_tuple(tag, [](std::string_view va, std::string_view vb) item_names.push_back(std::make_tuple(item_name, [](std::string_view va, std::string_view vb)
{ return va.compare(vb); })); { return va.compare(vb); }));
keyIx.push_back(keys.size()); keyIx.push_back(keys.size());
keys.push_back(tag); keys.push_back(item_name);
} }
} }
else else
{ {
keys = catValidator->m_keys; keys = catValidator->m_keys;
for (auto &tag : a.key_items()) for (auto &item_name : a.key_items())
{ {
auto iv = catValidator->get_validator_for_item(tag); auto iv = catValidator->get_validator_for_item(item_name);
if (iv == nullptr) if (iv == nullptr)
throw std::runtime_error("missing item validator"); throw std::runtime_error("missing item validator");
auto tv = iv->m_type; auto tv = iv->m_type;
if (tv == nullptr) if (tv == nullptr)
throw std::runtime_error("missing type validator"); throw std::runtime_error("missing type validator");
tags.push_back(std::make_tuple(tag, std::bind(&cif::type_validator::compare, tv, std::placeholders::_1, std::placeholders::_2))); item_names.push_back(std::make_tuple(item_name, std::bind(&cif::type_validator::compare, tv, std::placeholders::_1, std::placeholders::_2)));
auto pred = [tag](const std::string &s) -> bool auto pred = [item_name](const std::string &s) -> bool
{ {
return cif::iequals(tag, s) == 0; return cif::iequals(item_name, s) == 0;
}; };
if (find_if(keys.begin(), keys.end(), pred) == keys.end()) if (find_if(keys.begin(), keys.end(), pred) == keys.end())
keyIx.push_back(tags.size() - 1); keyIx.push_back(item_names.size() - 1);
} }
} }
...@@ -2165,12 +2165,12 @@ bool category::operator==(const category &rhs) const ...@@ -2165,12 +2165,12 @@ bool category::operator==(const category &rhs) const
for (auto kix : keyIx) for (auto kix : keyIx)
{ {
std::string tag; std::string item_name;
compType compare; compType compare;
std::tie(tag, compare) = tags[kix]; std::tie(item_name, compare) = item_names[kix];
d = compare(a[tag].text(), b[tag].text()); d = compare(a[item_name].text(), b[item_name].text());
if (d != 0) if (d != 0)
break; break;
...@@ -2192,19 +2192,19 @@ bool category::operator==(const category &rhs) const ...@@ -2192,19 +2192,19 @@ bool category::operator==(const category &rhs) const
std::vector<std::string> missingA, missingB, different; std::vector<std::string> missingA, missingB, different;
for (auto &tt : tags) for (auto &tt : item_names)
{ {
std::string tag; std::string item_name;
compType compare; compType compare;
std::tie(tag, compare) = tt; std::tie(item_name, compare) = tt;
// make it an option to compare unapplicable to empty or something // make it an option to compare unapplicable to empty or something
auto ta = ra[tag].text(); auto ta = ra[item_name].text();
if (ta == "." or ta == "?") if (ta == "." or ta == "?")
ta = ""; ta = "";
auto tb = rb[tag].text(); auto tb = rb[item_name].text();
if (tb == "." or tb == "?") if (tb == "." or tb == "?")
tb = ""; tb = "";
......
...@@ -63,14 +63,14 @@ namespace detail ...@@ -63,14 +63,14 @@ namespace detail
condition_impl *key_equals_condition_impl::prepare(const category &c) condition_impl *key_equals_condition_impl::prepare(const category &c)
{ {
m_item_ix = c.get_item_ix(m_item_tag); m_item_ix = c.get_item_ix(m_item_name);
m_icase = is_item_type_uchar(c, m_item_tag); m_icase = is_item_type_uchar(c, m_item_name);
if (c.get_cat_validator() != nullptr and if (c.get_cat_validator() != nullptr and
c.key_item_indices().contains(m_item_ix) and c.key_item_indices().contains(m_item_ix) and
c.key_item_indices().size() == 1) c.key_item_indices().size() == 1)
{ {
m_single_hit = c[{ { m_item_tag, m_value } }]; m_single_hit = c[{ { m_item_name, m_value } }];
} }
return this; return this;
......
...@@ -159,7 +159,7 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name) ...@@ -159,7 +159,7 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name)
return std::make_tuple(i, is_new); return std::make_tuple(i, is_new);
} }
std::vector<std::string> datablock::get_tag_order() const std::vector<std::string> datablock::get_item_order() const
{ {
std::vector<std::string> result; std::vector<std::string> result;
...@@ -168,7 +168,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -168,7 +168,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ return cat.name() == "entry"; }); { return cat.name() == "entry"; });
if (ci != end()) if (ci != end())
{ {
auto cto = ci->get_tag_order(); auto cto = ci->get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -176,7 +176,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -176,7 +176,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ return cat.name() == "audit_conform"; }); { return cat.name() == "audit_conform"; });
if (ci != end()) if (ci != end())
{ {
auto cto = ci->get_tag_order(); auto cto = ci->get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -184,7 +184,7 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -184,7 +184,7 @@ std::vector<std::string> datablock::get_tag_order() const
{ {
if (cat.name() == "entry" or cat.name() == "audit_conform") if (cat.name() == "entry" or cat.name() == "audit_conform")
continue; continue;
auto cto = cat.get_tag_order(); auto cto = cat.get_item_order();
result.insert(result.end(), cto.begin(), cto.end()); result.insert(result.end(), cto.begin(), cto.end());
} }
...@@ -338,16 +338,16 @@ void datablock::write(std::ostream &os) const ...@@ -338,16 +338,16 @@ void datablock::write(std::ostream &os) const
} }
} }
void datablock::write(std::ostream &os, const std::vector<std::string> &tag_order) void datablock::write(std::ostream &os, const std::vector<std::string> &item_name_order)
{ {
os << "data_" << m_name << '\n' os << "data_" << m_name << '\n'
<< "# \n"; << "# \n";
std::vector<std::string> cat_order; std::vector<std::string> cat_order;
for (auto &o : tag_order) for (auto &o : item_name_order)
{ {
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(o); std::tie(cat_name, item_name) = split_item_name(o);
if (find_if(cat_order.rbegin(), cat_order.rend(), [cat_name](const std::string &s) -> bool if (find_if(cat_order.rbegin(), cat_order.rend(), [cat_name](const std::string &s) -> bool
{ return iequals(cat_name, s); }) == cat_order.rend()) { return iequals(cat_name, s); }) == cat_order.rend())
cat_order.push_back(cat_name); cat_order.push_back(cat_name);
...@@ -360,10 +360,10 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &tag_orde ...@@ -360,10 +360,10 @@ void datablock::write(std::ostream &os, const std::vector<std::string> &tag_orde
continue; continue;
std::vector<std::string> items; std::vector<std::string> items;
for (auto &o : tag_order) for (auto &o : item_name_order)
{ {
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(o); std::tie(cat_name, item_name) = split_item_name(o);
if (cat_name == c) if (cat_name == c)
items.push_back(item_name); items.push_back(item_name);
......
...@@ -50,7 +50,7 @@ class dictionary_parser : public parser ...@@ -50,7 +50,7 @@ class dictionary_parser : public parser
try try
{ {
while (m_lookahead != CIFToken::Eof) while (m_lookahead != CIFToken::END_OF_FILE)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -128,7 +128,7 @@ class dictionary_parser : public parser ...@@ -128,7 +128,7 @@ class dictionary_parser : public parser
datablock::iterator cat = dict.end(); datablock::iterator cat = dict.end();
match(CIFToken::SAVE_NAME); match(CIFToken::SAVE_NAME);
while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::ITEM_NAME)
{ {
if (m_lookahead == CIFToken::LOOP) if (m_lookahead == CIFToken::LOOP)
{ {
...@@ -136,30 +136,30 @@ class dictionary_parser : public parser ...@@ -136,30 +136,30 @@ class dictionary_parser : public parser
match(CIFToken::LOOP); match(CIFToken::LOOP);
std::vector<std::string> tags; std::vector<std::string> item_names;
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
std::string catName, item_name; std::string catName, item_name;
std::tie(catName, item_name) = split_tag_name(m_token_value); std::tie(catName, item_name) = split_item_name(m_token_value);
if (cat == dict.end()) if (cat == dict.end())
std::tie(cat, std::ignore) = dict.emplace(catName); std::tie(cat, std::ignore) = dict.emplace(catName);
else if (not iequals(cat->name(), catName)) else if (not iequals(cat->name(), catName))
error("inconsistent categories in loop_"); error("inconsistent categories in loop_");
tags.push_back(item_name); item_names.push_back(item_name);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
} }
while (m_lookahead == CIFToken::Value) while (m_lookahead == CIFToken::VALUE)
{ {
cat->emplace({}); cat->emplace({});
auto row = cat->back(); auto row = cat->back();
for (auto tag : tags) for (auto item_name : item_names)
{ {
row[tag] = m_token_value; row[item_name] = m_token_value;
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -168,18 +168,18 @@ class dictionary_parser : public parser ...@@ -168,18 +168,18 @@ class dictionary_parser : public parser
else else
{ {
std::string catName, item_name; std::string catName, item_name;
std::tie(catName, item_name) = split_tag_name(m_token_value); std::tie(catName, item_name) = split_item_name(m_token_value);
if (cat == dict.end() or not iequals(cat->name(), catName)) if (cat == dict.end() or not iequals(cat->name(), catName))
std::tie(cat, std::ignore) = dict.emplace(catName); std::tie(cat, std::ignore) = dict.emplace(catName);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
if (cat->empty()) if (cat->empty())
cat->emplace({}); cat->emplace({});
cat->back()[item_name] = m_token_value; cat->back()[item_name] = m_token_value;
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -191,7 +191,7 @@ class dictionary_parser : public parser ...@@ -191,7 +191,7 @@ class dictionary_parser : public parser
std::vector<std::string> keys; std::vector<std::string> keys;
for (auto k : dict["category_key"]) for (auto k : dict["category_key"])
keys.push_back(std::get<1>(split_tag_name(k["name"].as<std::string>()))); keys.push_back(std::get<1>(split_item_name(k["name"].as<std::string>())));
iset groups; iset groups;
for (auto g : dict["category_group"]) for (auto g : dict["category_group"])
...@@ -234,17 +234,17 @@ class dictionary_parser : public parser ...@@ -234,17 +234,17 @@ class dictionary_parser : public parser
// collect the dict from our dataBlock and construct validators // collect the dict from our dataBlock and construct validators
for (auto i : dict["item"]) for (auto i : dict["item"])
{ {
std::string tagName, category, mandatory; std::string item, category, mandatory;
cif::tie(tagName, category, mandatory) = i.get("name", "category_id", "mandatory_code"); cif::tie(item, category, mandatory) = i.get("name", "category_id", "mandatory_code");
std::string cat_name, item_name; std::string cat_name, item_name;
std::tie(cat_name, item_name) = split_tag_name(tagName); std::tie(cat_name, item_name) = split_item_name(item);
if (cat_name.empty() or item_name.empty()) if (cat_name.empty() or item_name.empty())
error("Invalid tag name in _item.name " + tagName); error("Invalid item name in _item.name " + item);
if (not iequals(category, cat_name) and not(category.empty() or category == "?")) if (not iequals(category, cat_name) and not(category.empty() or category == "?"))
error("specified category id does match the implicit category name for tag '" + tagName + '\''); error("specified category id does match the implicit category name for item '" + item + '\'');
else else
category = cat_name; category = cat_name;
...@@ -260,22 +260,22 @@ class dictionary_parser : public parser ...@@ -260,22 +260,22 @@ class dictionary_parser : public parser
{ {
if (VERBOSE > 2) if (VERBOSE > 2)
{ {
std::cerr << "inconsistent mandatory value for " << tagName << " in dictionary\n"; std::cerr << "inconsistent mandatory value for " << item << " in dictionary\n";
if (iequals(tagName, saveFrameName)) if (iequals(item, saveFrameName))
std::cerr << "choosing " << mandatory << '\n'; std::cerr << "choosing " << mandatory << '\n';
else else
std::cerr << "choosing " << (vi->m_mandatory ? "Y" : "N") << '\n'; std::cerr << "choosing " << (vi->m_mandatory ? "Y" : "N") << '\n';
} }
if (iequals(tagName, saveFrameName)) if (iequals(item, saveFrameName))
vi->m_mandatory = (iequals(mandatory, "yes")); vi->m_mandatory = (iequals(mandatory, "yes"));
} }
if (vi->m_type != nullptr and tv != nullptr and vi->m_type != tv) if (vi->m_type != nullptr and tv != nullptr and vi->m_type != tv)
{ {
if (VERBOSE > 1) if (VERBOSE > 1)
std::cerr << "inconsistent type for " << tagName << " in dictionary\n"; std::cerr << "inconsistent type for " << item << " in dictionary\n";
} }
// vi->mMandatory = (iequals(mandatory, "yes")); // vi->mMandatory = (iequals(mandatory, "yes"));
...@@ -358,7 +358,7 @@ class dictionary_parser : public parser ...@@ -358,7 +358,7 @@ class dictionary_parser : public parser
} }
size_t ix = linkIndex.at(key); size_t ix = linkIndex.at(key);
addLink(ix, piv->m_tag, civ->m_tag); addLink(ix, piv->m_item_name, civ->m_item_name);
} }
// Only process inline linked items if the linked group list is absent // Only process inline linked items if the linked group list is absent
...@@ -386,7 +386,7 @@ class dictionary_parser : public parser ...@@ -386,7 +386,7 @@ class dictionary_parser : public parser
} }
size_t ix = linkIndex.at(key); size_t ix = linkIndex.at(key);
addLink(ix, piv->m_tag, civ->m_tag); addLink(ix, piv->m_item_name, civ->m_item_name);
} }
} }
...@@ -417,7 +417,7 @@ class dictionary_parser : public parser ...@@ -417,7 +417,7 @@ class dictionary_parser : public parser
for (auto &iv : cv.m_item_validators) for (auto &iv : cv.m_item_validators)
{ {
if (iv.m_type == nullptr and cif::VERBOSE >= 0) if (iv.m_type == nullptr and cif::VERBOSE >= 0)
std::cerr << "Missing item_type for " << iv.m_tag << '\n'; std::cerr << "Missing item_type for " << iv.m_item_name << '\n';
} }
} }
} }
......
...@@ -163,9 +163,9 @@ int atom::atom_impl::get_charge() const ...@@ -163,9 +163,9 @@ int atom::atom_impl::get_charge() const
// const std::string atom::atom_impl::get_property(const std::string_view name) const // const std::string atom::atom_impl::get_property(const std::string_view name) const
// { // {
// for (auto &&[tag, ref] : mCachedRefs) // for (auto &&[item_name, ref] : mCachedRefs)
// { // {
// if (tag == name) // if (item_name == name)
// return ref.as<std::string>(); // return ref.as<std::string>();
// } // }
...@@ -175,9 +175,9 @@ int atom::atom_impl::get_charge() const ...@@ -175,9 +175,9 @@ int atom::atom_impl::get_charge() const
// void atom::atom_impl::set_property(const std::string_view name, const std::string &value) // void atom::atom_impl::set_property(const std::string_view name, const std::string &value)
// { // {
// for (auto &&[tag, ref] : mCachedRefs) // for (auto &&[item_name, ref] : mCachedRefs)
// { // {
// if (tag != name) // if (item_name != name)
// continue; // continue;
// ref = value; // ref = value;
......
...@@ -269,7 +269,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -269,7 +269,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
const auto kEOF = std::char_traits<char>::eof(); const auto kEOF = std::char_traits<char>::eof();
CIFToken result = CIFToken::Unknown; CIFToken result = CIFToken::UNKNOWN;
int quoteChar = 0; int quoteChar = 0;
State state = State::Start; State state = State::Start;
m_bol = false; m_bol = false;
...@@ -279,7 +279,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -279,7 +279,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
reserved_words_automaton dag; reserved_words_automaton dag;
while (result == CIFToken::Unknown) while (result == CIFToken::UNKNOWN)
{ {
auto ch = get_next_char(); auto ch = get_next_char();
...@@ -287,7 +287,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -287,7 +287,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
case State::Start: case State::Start:
if (ch == kEOF) if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (ch == '\n') else if (ch == '\n')
{ {
m_bol = true; m_bol = true;
...@@ -298,7 +298,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -298,7 +298,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
else if (ch == '#') else if (ch == '#')
state = State::Comment; state = State::Comment;
else if (ch == '_') else if (ch == '_')
state = State::Tag; state = State::ItemName;
else if (ch == ';' and m_bol) else if (ch == ';' and m_bol)
state = State::TextItem; state = State::TextItem;
else if (ch == '?') else if (ch == '?')
...@@ -316,7 +316,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -316,7 +316,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
case State::White: case State::White:
if (ch == kEOF) if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (not is_space(ch)) else if (not is_space(ch))
{ {
state = State::Start; state = State::Start;
...@@ -335,7 +335,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -335,7 +335,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
m_token_buffer.clear(); m_token_buffer.clear();
} }
else if (ch == kEOF) else if (ch == kEOF)
result = CIFToken::Eof; result = CIFToken::END_OF_FILE;
else if (not is_any_print(ch)) else if (not is_any_print(ch))
error("invalid character in comment"); error("invalid character in comment");
break; break;
...@@ -344,7 +344,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -344,7 +344,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
} }
else else
state = State::Value; state = State::Value;
...@@ -366,7 +366,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -366,7 +366,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
{ {
assert(m_token_buffer.size() >= 2); assert(m_token_buffer.size() >= 2);
m_token_value = std::string_view(m_token_buffer.data() + 1, m_token_buffer.size() - 3); m_token_value = std::string_view(m_token_buffer.data() + 1, m_token_buffer.size() - 3);
result = CIFToken::Value; result = CIFToken::VALUE;
} }
else if (ch == kEOF) else if (ch == kEOF)
error("unterminated textfield"); error("unterminated textfield");
...@@ -387,7 +387,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -387,7 +387,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (is_white(ch)) if (is_white(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
if (m_token_buffer.size() < 2) if (m_token_buffer.size() < 2)
error("Invalid quoted string token"); error("Invalid quoted string token");
...@@ -403,11 +403,11 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -403,11 +403,11 @@ sac_parser::CIFToken sac_parser::get_next_token()
error("invalid character in quoted string"); error("invalid character in quoted string");
break; break;
case State::Tag: case State::ItemName:
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Tag; result = CIFToken::ITEM_NAME;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
} }
break; break;
...@@ -422,7 +422,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -422,7 +422,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
} }
else else
...@@ -467,7 +467,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -467,7 +467,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (not is_non_blank(ch)) if (not is_non_blank(ch))
{ {
retract(); retract();
result = CIFToken::Value; result = CIFToken::VALUE;
m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size()); m_token_value = std::string_view(m_token_buffer.data(), m_token_buffer.size());
break; break;
} }
...@@ -483,7 +483,7 @@ sac_parser::CIFToken sac_parser::get_next_token() ...@@ -483,7 +483,7 @@ sac_parser::CIFToken sac_parser::get_next_token()
if (VERBOSE >= 5) if (VERBOSE >= 5)
{ {
std::cerr << get_token_name(result); std::cerr << get_token_name(result);
if (result != CIFToken::Eof) if (result != CIFToken::END_OF_FILE)
std::cerr << " " << std::quoted(m_token_value); std::cerr << " " << std::quoted(m_token_value);
std::cerr << '\n'; std::cerr << '\n';
} }
...@@ -710,7 +710,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data ...@@ -710,7 +710,7 @@ bool sac_parser::parse_single_datablock(const std::string &datablock, const data
void sac_parser::parse_file() void sac_parser::parse_file()
{ {
while (m_lookahead != CIFToken::Eof) while (m_lookahead != CIFToken::END_OF_FILE)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -735,10 +735,10 @@ void sac_parser::parse_file() ...@@ -735,10 +735,10 @@ void sac_parser::parse_file()
void sac_parser::parse_global() void sac_parser::parse_global()
{ {
match(CIFToken::GLOBAL); match(CIFToken::GLOBAL);
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -747,7 +747,7 @@ void sac_parser::parse_datablock() ...@@ -747,7 +747,7 @@ void sac_parser::parse_datablock()
static const std::string kUnitializedCategory("<invalid>"); static const std::string kUnitializedCategory("<invalid>");
std::string cat = kUnitializedCategory; // intial value acts as a guard for empty category names std::string cat = kUnitializedCategory; // intial value acts as a guard for empty category names
while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::Tag or m_lookahead == CIFToken::SAVE_NAME) while (m_lookahead == CIFToken::LOOP or m_lookahead == CIFToken::ITEM_NAME or m_lookahead == CIFToken::SAVE_NAME)
{ {
switch (m_lookahead) switch (m_lookahead)
{ {
...@@ -757,12 +757,12 @@ void sac_parser::parse_datablock() ...@@ -757,12 +757,12 @@ void sac_parser::parse_datablock()
match(CIFToken::LOOP); match(CIFToken::LOOP);
std::vector<std::string> tags; std::vector<std::string> item_names;
while (m_lookahead == CIFToken::Tag) while (m_lookahead == CIFToken::ITEM_NAME)
{ {
std::string catName, itemName; std::string catName, itemName;
std::tie(catName, itemName) = split_tag_name(m_token_value); std::tie(catName, itemName) = split_item_name(m_token_value);
if (cat == kUnitializedCategory) if (cat == kUnitializedCategory)
{ {
...@@ -772,19 +772,19 @@ void sac_parser::parse_datablock() ...@@ -772,19 +772,19 @@ void sac_parser::parse_datablock()
else if (not iequals(cat, catName)) else if (not iequals(cat, catName))
error("inconsistent categories in loop_"); error("inconsistent categories in loop_");
tags.push_back(itemName); item_names.push_back(itemName);
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
} }
while (m_lookahead == CIFToken::Value) while (m_lookahead == CIFToken::VALUE)
{ {
produce_row(); produce_row();
for (auto tag : tags) for (auto item_name : item_names)
{ {
produce_item(cat, tag, m_token_value); produce_item(cat, item_name, m_token_value);
match(CIFToken::Value); match(CIFToken::VALUE);
} }
} }
...@@ -792,10 +792,10 @@ void sac_parser::parse_datablock() ...@@ -792,10 +792,10 @@ void sac_parser::parse_datablock()
break; break;
} }
case CIFToken::Tag: case CIFToken::ITEM_NAME:
{ {
std::string catName, itemName; std::string catName, itemName;
std::tie(catName, itemName) = split_tag_name(m_token_value); std::tie(catName, itemName) = split_item_name(m_token_value);
if (not iequals(cat, catName)) if (not iequals(cat, catName))
{ {
...@@ -804,11 +804,11 @@ void sac_parser::parse_datablock() ...@@ -804,11 +804,11 @@ void sac_parser::parse_datablock()
produce_row(); produce_row();
} }
match(CIFToken::Tag); match(CIFToken::ITEM_NAME);
produce_item(cat, itemName, m_token_value); produce_item(cat, itemName, m_token_value);
match(CIFToken::Value); match(CIFToken::VALUE);
break; break;
} }
......
...@@ -239,18 +239,18 @@ void checkAtomRecords(datablock &db) ...@@ -239,18 +239,18 @@ void checkAtomRecords(datablock &db)
// Rewrite the coordinates and other items that look better in a fixed format // Rewrite the coordinates and other items that look better in a fixed format
// Be careful not to nuke invalidly formatted data here // Be careful not to nuke invalidly formatted data here
for (auto [tag, prec] : std::vector<std::tuple<std::string_view, std::string::size_type>>{ for (auto [item_name, prec] : std::vector<std::tuple<std::string_view, std::string::size_type>>{
{ "cartn_x", 3 }, { "cartn_x", 3 },
{ "cartn_y", 3 }, { "cartn_y", 3 },
{ "cartn_z", 3 }, { "cartn_z", 3 },
{ "occupancy", 2 }, { "occupancy", 2 },
{ "b_iso_or_equiv", 2 } }) { "b_iso_or_equiv", 2 } })
{ {
if (row[tag].empty()) if (row[item_name].empty())
continue; continue;
float v; float v;
auto s = row.get<std::string>(tag); auto s = row.get<std::string>(item_name);
if (auto [ptr, ec] = cif::from_chars(s.data(), s.data() + s.length(), v); ec != std::errc()) if (auto [ptr, ec] = cif::from_chars(s.data(), s.data() + s.length(), v); ec != std::errc())
continue; continue;
...@@ -259,7 +259,7 @@ void checkAtomRecords(datablock &db) ...@@ -259,7 +259,7 @@ void checkAtomRecords(datablock &db)
char b[12]; char b[12];
if (auto [ptr, ec] = cif::to_chars(b, b + sizeof(b), v, cif::chars_format::fixed, prec); ec == std::errc()) if (auto [ptr, ec] = cif::to_chars(b, b + sizeof(b), v, cif::chars_format::fixed, prec); ec == std::errc())
row.assign(tag, { b, static_cast<std::string::size_type>(ptr - b) }, false, false); row.assign(item_name, { b, static_cast<std::string::size_type>(ptr - b) }, false, false);
} }
} }
} }
...@@ -268,21 +268,21 @@ void checkAtomRecords(datablock &db) ...@@ -268,21 +268,21 @@ void checkAtomRecords(datablock &db)
if (cv) if (cv)
{ {
// See if there are items that are no longer known // See if there are items that are no longer known
for (auto tag : atom_site.get_items()) for (auto item_name : atom_site.get_items())
{ {
if (cv->get_validator_for_item(tag) != nullptr) if (cv->get_validator_for_item(item_name) != nullptr)
continue; continue;
auto r = atom_site.find_first(key(tag) != null); auto r = atom_site.find_first(key(item_name) != null);
if (not r) if (not r)
{ {
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Dropping unknown item " << tag << '\n'; std::clog << "Dropping unknown item " << item_name << '\n';
atom_site.remove_item(tag); atom_site.remove_item(item_name);
} }
else if (cif::VERBOSE > 0) else if (cif::VERBOSE > 0)
std::clog << "Keeping unknown item " << std::quoted(tag) << " in atom_site since it is not empty\n"; std::clog << "Keeping unknown item " << std::quoted(item_name) << " in atom_site since it is not empty\n";
} }
} }
} }
...@@ -733,19 +733,19 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -733,19 +733,19 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
// Start by renaming items that may have old names based on alias info // Start by renaming items that may have old names based on alias info
for (auto tag : cat.get_items()) for (auto item_name : cat.get_items())
{ {
auto iv = cv->get_validator_for_item(tag); auto iv = cv->get_validator_for_item(item_name);
if (iv) // know, must be OK then` if (iv) // know, must be OK then`
continue; continue;
iv = cv->get_validator_for_aliased_item(tag); iv = cv->get_validator_for_aliased_item(item_name);
if (not iv) if (not iv)
continue; continue;
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Renaming " << tag << " to " << iv->m_tag << " in category " << cat.name() << '\n'; std::clog << "Renaming " << item_name << " to " << iv->m_item_name << " in category " << cat.name() << '\n';
cat.rename_item(tag, iv->m_tag); cat.rename_item(item_name, iv->m_item_name);
} }
for (auto link : validator.get_links_for_child(cat.name())) for (auto link : validator.get_links_for_child(cat.name()))
...@@ -780,13 +780,13 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -780,13 +780,13 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
} }
// validate all values, and if they do not validate replace the content with an unknown flag // validate all values, and if they do not validate replace the content with an unknown flag
for (auto tag : cat.get_items()) for (auto item_name : cat.get_items())
{ {
auto iv = cv->get_validator_for_item(tag); auto iv = cv->get_validator_for_item(item_name);
if (not iv) if (not iv)
continue; continue;
auto ix = cat.get_item_ix(tag); auto ix = cat.get_item_ix(item_name);
for (auto row : cat) for (auto row : cat)
{ {
...@@ -796,7 +796,7 @@ void reconstruct_pdbx(file &file, std::string_view dictionary) ...@@ -796,7 +796,7 @@ void reconstruct_pdbx(file &file, std::string_view dictionary)
if (not iv->validate_value(value, ec)) if (not iv->validate_value(value, ec))
{ {
if (cif::VERBOSE > 0) if (cif::VERBOSE > 0)
std::clog << "Replacing value (" << std::quoted(value) << ") for item " << tag << " since it does not validate\n"; std::clog << "Replacing value (" << std::quoted(value) << ") for item " << item_name << " since it does not validate\n";
row[ix] = "?"; row[ix] = "?";
} }
......
...@@ -215,19 +215,19 @@ std::string trim_copy(std::string_view s) ...@@ -215,19 +215,19 @@ std::string trim_copy(std::string_view s)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
std::tuple<std::string, std::string> split_tag_name(std::string_view tag) std::tuple<std::string, std::string> split_item_name(std::string_view item_name)
{ {
if (tag.empty()) if (item_name.empty())
throw std::runtime_error("empty tag"); throw std::runtime_error("empty item_name");
if (tag[0] != '_') if (item_name[0] != '_')
throw std::runtime_error("tag '" + std::string { tag } + "' does not start with underscore"); throw std::runtime_error("item_name '" + std::string { item_name } + "' does not start with underscore");
auto s = tag.find('.'); auto s = item_name.find('.');
if (s == std::string::npos) if (s == std::string::npos)
// throw std::runtime_error("tag does not contain dot (" + std::string{ tag } + ')'); // throw std::runtime_error("item_name does not contain dot (" + std::string{ item_name } + ')');
return std::tuple<std::string, std::string>{ "", tag.substr(1) }; return std::tuple<std::string, std::string>{ "", item_name.substr(1) };
else else
return std::tuple<std::string, std::string>{tag.substr(1, s - 1), tag.substr(s + 1)}; return std::tuple<std::string, std::string>{item_name.substr(1, s - 1), item_name.substr(s + 1)};
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -196,31 +196,11 @@ int type_validator::compare(std::string_view a, std::string_view b) const ...@@ -196,31 +196,11 @@ int type_validator::compare(std::string_view a, std::string_view b) const
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// void ValidateItem::addLinked(ValidateItem* parent, const std::string& parentItem, const std::string& childItem)
//{
//// if (mParent != nullptr and VERBOSE)
//// cerr << "replacing parent in " << mCategory->m_name << " from " << mParent->mCategory->m_name << " to " << parent->mCategory->m_name << endl;
//// mParent = parent;
//
// if (m_type == nullptr and parent != nullptr)
// m_type = parent->m_type;
//
// if (parent != nullptr)
// {
// mLinked.push_back({parent, parentItem, childItem});
//
// parent->mChildren.insert(this);
////
//// if (mCategory->mKeys == std::vector<std::string>{mTag})
//// parent->mForeignKeys.insert(this);
// }
//}
void item_validator::operator()(std::string_view value) const void item_validator::operator()(std::string_view value) const
{ {
std::error_code ec; std::error_code ec;
if (not validate_value(value, ec)) if (not validate_value(value, ec))
throw std::system_error(ec, std::string{ value } + " does not match rx for " + m_tag); throw std::system_error(ec, std::string{ value } + " does not match rx for " + m_item_name);
} }
bool item_validator::validate_value(std::string_view value, std::error_code &ec) const noexcept bool item_validator::validate_value(std::string_view value, std::error_code &ec) const noexcept
...@@ -243,27 +223,27 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec) ...@@ -243,27 +223,27 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec)
void category_validator::add_item_validator(item_validator &&v) void category_validator::add_item_validator(item_validator &&v)
{ {
if (v.m_mandatory) if (v.m_mandatory)
m_mandatory_items.insert(v.m_tag); m_mandatory_items.insert(v.m_item_name);
v.m_category = this; v.m_category = this;
auto r = m_item_validators.insert(std::move(v)); auto r = m_item_validators.insert(std::move(v));
if (not r.second and VERBOSE >= 4) if (not r.second and VERBOSE >= 4)
std::cout << "Could not add validator for item " << v.m_tag << " to category " << m_name << '\n'; std::cout << "Could not add validator for item " << v.m_item_name << " to category " << m_name << '\n';
} }
const item_validator *category_validator::get_validator_for_item(std::string_view tag) const const item_validator *category_validator::get_validator_for_item(std::string_view item_name) const
{ {
const item_validator *result = nullptr; const item_validator *result = nullptr;
auto i = m_item_validators.find(item_validator{ std::string(tag) }); auto i = m_item_validators.find(item_validator{ std::string(item_name) });
if (i != m_item_validators.end()) if (i != m_item_validators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
std::cout << "No validator for tag " << tag << '\n'; std::cout << "No validator for item " << item_name << '\n';
return result; return result;
} }
const item_validator *category_validator::get_validator_for_aliased_item(std::string_view tag) const const item_validator *category_validator::get_validator_for_aliased_item(std::string_view item_name) const
{ {
const item_validator *result = nullptr; const item_validator *result = nullptr;
...@@ -271,8 +251,8 @@ const item_validator *category_validator::get_validator_for_aliased_item(std::st ...@@ -271,8 +251,8 @@ const item_validator *category_validator::get_validator_for_aliased_item(std::st
{ {
for (auto &ai : iv.m_aliases) for (auto &ai : iv.m_aliases)
{ {
const auto &[cat, name] = split_tag_name(ai.m_name); const auto &[cat, name] = split_item_name(ai.m_name);
if (iequals(name, tag) and iequals(cat, m_name)) if (iequals(name, item_name) and iequals(cat, m_name))
{ {
result = &iv; result = &iv;
break; break;
...@@ -324,19 +304,19 @@ const category_validator *validator::get_validator_for_category(std::string_view ...@@ -324,19 +304,19 @@ const category_validator *validator::get_validator_for_category(std::string_view
return result; return result;
} }
item_validator *validator::get_validator_for_item(std::string_view tag) const item_validator *validator::get_validator_for_item(std::string_view item_name) const
{ {
item_validator *result = nullptr; item_validator *result = nullptr;
std::string cat, item; std::string cat, item;
std::tie(cat, item) = split_tag_name(tag); std::tie(cat, item) = split_item_name(item_name);
auto *cv = get_validator_for_category(cat); auto *cv = get_validator_for_category(cat);
if (cv != nullptr) if (cv != nullptr)
result = const_cast<item_validator *>(cv->get_validator_for_item(item)); result = const_cast<item_validator *>(cv->get_validator_for_item(item));
if (result == nullptr and VERBOSE > 4) if (result == nullptr and VERBOSE > 4)
std::cout << "No validator for item " << tag << '\n'; std::cout << "No validator for item " << item_name << '\n';
return result; return result;
} }
...@@ -361,11 +341,11 @@ void validator::add_link_validator(link_validator &&v) ...@@ -361,11 +341,11 @@ void validator::add_link_validator(link_validator &&v)
auto piv = pcv->get_validator_for_item(v.m_parent_keys[i]); auto piv = pcv->get_validator_for_item(v.m_parent_keys[i]);
if (piv == nullptr) if (piv == nullptr)
throw std::runtime_error("unknown parent tag _" + v.m_parent_category + '.' + v.m_parent_keys[i]); throw std::runtime_error("unknown parent item _" + v.m_parent_category + '.' + v.m_parent_keys[i]);
auto civ = ccv->get_validator_for_item(v.m_child_keys[i]); auto civ = ccv->get_validator_for_item(v.m_child_keys[i]);
if (civ == nullptr) if (civ == nullptr)
throw std::runtime_error("unknown child tag _" + v.m_child_category + '.' + v.m_child_keys[i]); throw std::runtime_error("unknown child item _" + v.m_child_category + '.' + v.m_child_keys[i]);
if (civ->m_type == nullptr and piv->m_type != nullptr) if (civ->m_type == nullptr and piv->m_type != nullptr)
const_cast<item_validator *>(civ)->m_type = piv->m_type; const_cast<item_validator *>(civ)->m_type = piv->m_type;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment