Commit 51ccb921 by Maarten L. Hekkelman

small changes in constructors

parent 3cd27f13
...@@ -144,26 +144,34 @@ class category ...@@ -144,26 +144,34 @@ class category
category() = default; ///< Default constructor category() = default; ///< Default constructor
category(std::string_view name); ///< Constructor taking a \a name category(std::string_view name); ///< Constructor taking a \a name
category(const category &rhs); ///< Copy constructor category(const category &rhs); ///< Copy constructor
category(category &&rhs); ///< Move constructor
category &operator=(const category &rhs); ///< Copy assignement operator category(category &&rhs) noexcept ///< Move constructor
category &operator=(category &&rhs); ///< Move assignement operator {
swap(*this, rhs);
}
category &operator=(category rhs) ///< assignement operator
{
swap(*this, rhs);
return *this;
}
/// @brief Destructor /// @brief Destructor
/// @note Please note that the destructor is not virtual. It is assumed that /// @note Please note that the destructor is not virtual. It is assumed that
/// you will not derive from this class. /// you will not derive from this class.
~category(); ~category();
friend void swap(category &a, category &b) noexcept;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
const std::string &name() const { return m_name; } ///< Returns the name of the category const std::string &name() const { return m_name; } ///< Returns the name of the category
[[deprecated("use key_items instead")]] [[deprecated("use key_items instead")]] iset key_fields() const; ///< Returns the cif::iset of key item names. Retrieved from the @ref category_validator for this category
iset key_fields() const; ///< Returns the cif::iset of key item names. Retrieved from the @ref category_validator for this category
iset key_items() const; ///< Returns the cif::iset of key item names. Retrieved from the @ref category_validator for this category iset key_items() const; ///< Returns the cif::iset of key item names. Retrieved from the @ref category_validator for this category
[[deprecated("use key_item_indices instead")]] [[deprecated("use key_item_indices instead")]] std::set<uint16_t> key_field_indices() const; ///< Returns a set of indices for the key items.
std::set<uint16_t> key_field_indices() const; ///< Returns a set of indices for the key items.
std::set<uint16_t> key_item_indices() const; ///< Returns a set of indices for the key items. std::set<uint16_t> key_item_indices() const; ///< Returns a set of indices for the key items.
...@@ -1010,7 +1018,8 @@ class category ...@@ -1010,7 +1018,8 @@ class category
void update_value(const std::vector<row_handle> &rows, std::string_view item_name, std::string_view value) void update_value(const std::vector<row_handle> &rows, std::string_view item_name, std::string_view value)
{ {
update_value(rows, item_name, [value](std::string_view) { return value; }); update_value(rows, item_name, [value](std::string_view)
{ return value; });
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
...@@ -1018,8 +1027,7 @@ class category ...@@ -1018,8 +1027,7 @@ class category
// the old function names are here as deprecated variants. // the old function names are here as deprecated variants.
/// \brief Return the index number for \a column_name /// \brief Return the index number for \a column_name
[[deprecated("Use get_item_ix instead")]] [[deprecated("Use get_item_ix instead")]] uint16_t get_column_ix(std::string_view column_name) const
uint16_t get_column_ix(std::string_view column_name) const
{ {
return get_item_ix(column_name); return get_item_ix(column_name);
} }
...@@ -1027,8 +1035,7 @@ class category ...@@ -1027,8 +1035,7 @@ class category
/// @brief Return the name for column with index @a ix /// @brief Return the name for column with index @a ix
/// @param ix The index number /// @param ix The index number
/// @return The name of the column /// @return The name of the column
[[deprecated("use get_item_name instead")]] [[deprecated("use get_item_name instead")]] std::string_view get_column_name(uint16_t ix) const
std::string_view get_column_name(uint16_t ix) const
{ {
return get_item_name(ix); return get_item_name(ix);
} }
...@@ -1036,8 +1043,7 @@ class category ...@@ -1036,8 +1043,7 @@ class category
/// @brief Make sure a item with name @a item_name is known and return its index number /// @brief Make sure a item with name @a item_name is known and return its index number
/// @param item_name The name of the item /// @param item_name The name of the item
/// @return The index number of the item /// @return The index number of the item
[[deprecated("use add_item instead")]] [[deprecated("use add_item instead")]] uint16_t add_column(std::string_view item_name)
uint16_t add_column(std::string_view item_name)
{ {
return add_item(item_name); return add_item(item_name);
} }
...@@ -1045,15 +1051,13 @@ class category ...@@ -1045,15 +1051,13 @@ class category
/** @brief Remove column name @a colum_name /** @brief Remove column name @a colum_name
* @param column_name The column to be removed * @param column_name The column to be removed
*/ */
[[deprecated("use remove_item instead")]] [[deprecated("use remove_item instead")]] void remove_column(std::string_view column_name)
void remove_column(std::string_view column_name)
{ {
remove_item(column_name); remove_item(column_name);
} }
/** @brief Rename column @a from_name to @a to_name */ /** @brief Rename column @a from_name to @a to_name */
[[deprecated("use rename_item instead")]] [[deprecated("use rename_item instead")]] void rename_column(std::string_view from_name, std::string_view to_name)
void rename_column(std::string_view from_name, std::string_view to_name)
{ {
rename_item(from_name, to_name); rename_item(from_name, to_name);
} }
...@@ -1061,15 +1065,13 @@ class category ...@@ -1061,15 +1065,13 @@ class category
/// @brief Return whether a column with name @a name exists in this category /// @brief Return whether a column with name @a name exists in this category
/// @param name The name of the column /// @param name The name of the column
/// @return True if the column exists /// @return True if the column exists
[[deprecated("use has_item instead")]] [[deprecated("use has_item instead")]] bool has_column(std::string_view name) const
bool has_column(std::string_view name) const
{ {
return has_item(name); return has_item(name);
} }
/// @brief Return the cif::iset of columns in this category /// @brief Return the cif::iset of columns in this category
[[deprecated("use get_items instead")]] [[deprecated("use get_items instead")]] iset get_columns() const
iset get_columns() const
{ {
return get_items(); return get_items();
} }
...@@ -1125,7 +1127,7 @@ class category ...@@ -1125,7 +1127,7 @@ class category
{ {
item_validator = m_cat_validator->get_validator_for_item(item_name); item_validator = m_cat_validator->get_validator_for_item(item_name);
if (item_validator == nullptr) if (item_validator == nullptr)
m_validator->report_error( validation_error::item_not_allowed_in_category, m_name, item_name, false); m_validator->report_error(validation_error::item_not_allowed_in_category, m_name, item_name, false);
} }
m_items.emplace_back(item_name, item_validator); m_items.emplace_back(item_name, item_validator);
...@@ -1169,8 +1171,7 @@ class category ...@@ -1169,8 +1171,7 @@ 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
[[deprecated("use get_item_order instead")]] [[deprecated("use get_item_order instead")]] std::vector<std::string> get_tag_order() const
std::vector<std::string> get_tag_order() const
{ {
return get_item_order(); return get_item_order();
} }
......
...@@ -61,12 +61,26 @@ class datablock : public std::list<category> ...@@ -61,12 +61,26 @@ class datablock : public std::list<category>
/** @cond */ /** @cond */
datablock(const datablock &); datablock(const datablock &);
datablock(datablock &&) = default;
datablock &operator=(const datablock &); datablock(datablock &&db) noexcept
datablock &operator=(datablock &&) = default; {
swap_(*this, db);
}
datablock &operator=(datablock db)
{
swap_(*this, db);
return *this;
}
/** @endcond */ /** @endcond */
friend void swap_(datablock &a, datablock &b) noexcept
{
std::swap(a.m_name, b.m_name);
std::swap(a.m_validator, b.m_validator);
std::swap(static_cast<std::list<category>&>(a), static_cast<std::list<category>&>(b));
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
......
...@@ -288,19 +288,16 @@ struct item_value ...@@ -288,19 +288,16 @@ struct item_value
} }
/** @cond */ /** @cond */
item_value(item_value &&rhs) item_value(item_value &&rhs) noexcept
: m_length(std::exchange(rhs.m_length, 0)) : m_length(std::exchange(rhs.m_length, 0))
, m_storage(std::exchange(rhs.m_storage, 0)) , m_storage(std::exchange(rhs.m_storage, 0))
{ {
} }
item_value &operator=(item_value &&rhs) item_value &operator=(item_value &&rhs) noexcept
{ {
if (this != &rhs) std::swap(m_length, rhs.m_length);
{ std::swap(m_storage, rhs.m_storage);
m_length = std::exchange(rhs.m_length, m_length);
m_storage = std::exchange(rhs.m_storage, m_storage);
}
return *this; return *this;
} }
......
...@@ -521,71 +521,18 @@ category::category(const category &rhs) ...@@ -521,71 +521,18 @@ category::category(const category &rhs)
m_index = new category_index(*this); m_index = new category_index(*this);
} }
category::category(category &&rhs) void swap(category &a, category &b) noexcept
: m_name(std::move(rhs.m_name))
, m_items(std::move(rhs.m_items))
, m_validator(rhs.m_validator)
, m_cat_validator(rhs.m_cat_validator)
, m_parent_links(std::move(rhs.m_parent_links))
, m_child_links(std::move(rhs.m_child_links))
, m_cascade(rhs.m_cascade)
, m_index(rhs.m_index)
, m_head(rhs.m_head)
, m_tail(rhs.m_tail)
{
rhs.m_head = nullptr;
rhs.m_tail = nullptr;
rhs.m_index = nullptr;
}
category &category::operator=(const category &rhs)
{
if (this != &rhs)
{
if (not empty())
clear();
m_name = rhs.m_name;
m_items = rhs.m_items;
m_cascade = rhs.m_cascade;
m_validator = nullptr;
m_cat_validator = nullptr;
delete m_index;
m_index = nullptr;
for (auto r = rhs.m_head; r != nullptr; r = r->m_next)
insert_impl(cend(), clone_row(*r));
m_validator = rhs.m_validator;
m_cat_validator = rhs.m_cat_validator;
if (m_cat_validator != nullptr and m_index == nullptr)
m_index = new category_index(*this);
}
return *this;
}
category &category::operator=(category &&rhs)
{ {
if (this != &rhs) std::swap(a.m_name, b.m_name);
{ std::swap(a.m_items, b.m_items);
m_name = std::move(rhs.m_name); std::swap(a.m_validator, b.m_validator);
m_items = std::move(rhs.m_items); std::swap(a.m_cat_validator, b.m_cat_validator);
m_cascade = rhs.m_cascade; std::swap(a.m_parent_links, b.m_parent_links);
m_validator = rhs.m_validator; std::swap(a.m_child_links, b.m_child_links);
m_cat_validator = rhs.m_cat_validator; std::swap(a.m_cascade, b.m_cascade);
m_parent_links = rhs.m_parent_links; std::swap(a.m_index, b.m_index);
m_child_links = rhs.m_child_links; std::swap(a.m_head, b.m_head);
std::swap(a.m_tail, b.m_tail);
std::swap(m_index, rhs.m_index);
std::swap(m_head, rhs.m_head);
std::swap(m_tail, rhs.m_tail);
}
return *this;
} }
category::~category() category::~category()
......
...@@ -38,21 +38,6 @@ datablock::datablock(const datablock &db) ...@@ -38,21 +38,6 @@ datablock::datablock(const datablock &db)
cat.update_links(*this); cat.update_links(*this);
} }
datablock &datablock::operator=(const datablock &db)
{
if (this != &db)
{
std::list<category>::operator=(db);
m_name = db.m_name;
m_validator = db.m_validator;
for (auto &cat : *this)
cat.update_links(*this);
}
return *this;
}
void datablock::set_validator(const validator *v) void datablock::set_validator(const validator *v)
{ {
m_validator = v; m_validator = v;
......
...@@ -6413,12 +6413,12 @@ file read(std::istream &is) ...@@ -6413,12 +6413,12 @@ file read(std::istream &is)
{ {
std::throw_with_nested(std::runtime_error("Since the file did not start with a valid PDB HEADER line mmCIF was assumed, but that failed.")); std::throw_with_nested(std::runtime_error("Since the file did not start with a valid PDB HEADER line mmCIF was assumed, but that failed."));
} }
}
// Since we're using the cif::pdb way of reading the file, the data may need // Since we're using the cif::pdb way of reading the file, the data may need
// reconstruction // reconstruction
reconstruct_pdbx(result); reconstruct_pdbx(result);
} }
}
// Must be a PDB like file, right? // Must be a PDB like file, right?
if (result.get_validator() == nullptr) if (result.get_validator() == nullptr)
......
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