From 7c4133b9e48b930372dae9a91f66d425dda5c8e8 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 9 Mar 2024 21:54:17 +0100 Subject: [PATCH 1/2] Fixed issue #1632 (at least partially): introducing non-const versions of RDB iterators and access methods --- src/rdb/rdb/gsiDeclRdb.cc | 256 +++++++++++++++++++++++++++++++++++++- src/rdb/rdb/rdb.cc | 39 +++++- src/rdb/rdb/rdb.h | 119 ++++++++++-------- testdata/ruby/rdbTest.rb | 72 +++++++++++ 4 files changed, 425 insertions(+), 61 deletions(-) diff --git a/src/rdb/rdb/gsiDeclRdb.cc b/src/rdb/rdb/gsiDeclRdb.cc index 00392affaf..2b467f2edb 100644 --- a/src/rdb/rdb/gsiDeclRdb.cc +++ b/src/rdb/rdb/gsiDeclRdb.cc @@ -88,6 +88,49 @@ class ItemRefUnwrappingIterator rdb::Database::const_item_ref_iterator m_iter; }; +class ItemRefUnwrappingNonConstIterator +{ +public: + typedef rdb::Database::const_item_ref_iterator::iterator_category iterator_category; + typedef rdb::Database::const_item_ref_iterator::difference_type difference_type; + typedef rdb::Item value_type; + typedef rdb::Item &reference; + typedef rdb::Item *pointer; + + ItemRefUnwrappingNonConstIterator (rdb::Database::item_ref_iterator i) + : m_iter (i) + { } + + bool operator== (const ItemRefUnwrappingNonConstIterator &d) const + { + return m_iter == d.m_iter; + } + + bool operator!= (const ItemRefUnwrappingNonConstIterator &d) const + { + return m_iter != d.m_iter; + } + + ItemRefUnwrappingNonConstIterator &operator++ () + { + ++m_iter; + return *this; + } + + rdb::Item &operator* () const + { + return (*m_iter).operator* (); + } + + rdb::Item *operator-> () const + { + return (*m_iter).operator-> (); + } + +private: + rdb::Database::item_ref_iterator m_iter; +}; + // --------------------------------------------------------------- // rdb::Reference binding @@ -105,7 +148,12 @@ Class decl_RdbReference ("rdb", "RdbReference", "\n" "This method has been introduced in version 0.23." ) + - gsi::method ("trans", &rdb::Reference::trans, + gsi::method ("database", (rdb::Database *(rdb::Reference::*)()) &rdb::Reference::database, + "@brief Gets the database object that category is associated with (non-const version)\n" + "\n" + "This method has been introduced in version 0.29." + ) + + gsi::method ("trans", &rdb::Reference::trans, "@brief Gets the transformation for this reference\n" "The transformation describes the transformation of the child cell into the parent cell. In that sense that is the " "usual transformation of a cell reference.\n" @@ -141,6 +189,16 @@ static rdb::References::const_iterator end_references (const rdb::Cell *cell) return cell->references ().end (); } +static rdb::References::iterator begin_references_nc (rdb::Cell *cell) +{ + return cell->references ().begin (); +} + +static rdb::References::iterator end_references_nc (rdb::Cell *cell) +{ + return cell->references ().end (); +} + static void add_reference (rdb::Cell *cell, const rdb::Reference &ref) { cell->references ().insert (ref); @@ -163,6 +221,18 @@ ItemRefUnwrappingIterator cell_items_end (const rdb::Cell *cell) return cell->database ()->items_by_cell (cell->id ()).second; } +ItemRefUnwrappingNonConstIterator cell_items_begin_non_const (rdb::Cell *cell) +{ + tl_assert (cell->database ()); + return cell->database ()->items_by_cell (cell->id ()).first; +} + +ItemRefUnwrappingNonConstIterator cell_items_end_non_const (rdb::Cell *cell) +{ + tl_assert (cell->database ()); + return cell->database ()->items_by_cell (cell->id ()).second; +} + Class decl_RdbCell ("rdb", "RdbCell", gsi::method ("rdb_id", &rdb::Cell::id, "@brief Gets the cell ID\n" @@ -175,12 +245,22 @@ Class decl_RdbCell ("rdb", "RdbCell", "\n" "This method has been introduced in version 0.23." ) + + gsi::method ("database", (rdb::Database *(rdb::Cell::*)()) &rdb::Cell::database, + "@brief Gets the database object that category is associated with (non-const version)\n" + "\n" + "This method has been introduced in version 0.29." + ) + gsi::iterator_ext ("each_item", &cell_items_begin, &cell_items_end, "@brief Iterates over all items inside the database which are associated with this cell\n" "\n" "This method has been introduced in version 0.23." ) + - gsi::method ("name", &rdb::Cell::name, + gsi::iterator_ext ("each_item", &cell_items_begin_non_const, &cell_items_end_non_const, + "@brief Iterates over all items inside the database which are associated with this cell (non-const version)\n" + "\n" + "This method has been introduced in version 0.29." + ) + + gsi::method ("name", &rdb::Cell::name, "@brief Gets the cell name\n" "The cell name is an string that identifies the category in the database. " "Additionally, a cell may carry a variant identifier which is a string that uniquely identifies a cell " @@ -215,6 +295,11 @@ Class decl_RdbCell ("rdb", "RdbCell", ) + gsi::iterator_ext ("each_reference", &begin_references, &end_references, "@brief Iterates over all references\n" + ) + + gsi::iterator_ext ("each_reference", &begin_references_nc, &end_references_nc, + "@brief Iterates over all references (non-const version)\n" + "\n" + "This method has been introduced in version 0.23." ), "@brief A cell inside the report database\n" "This class represents a cell in the report database. There is not necessarily a 1:1 correspondence of RDB cells " @@ -226,12 +311,22 @@ Class decl_RdbCell ("rdb", "RdbCell", // --------------------------------------------------------------- // rdb::Category binding -static rdb::Categories::iterator begin_sub_categories (rdb::Category *cat) +static rdb::Categories::const_iterator begin_sub_categories (const rdb::Category *cat) { return cat->sub_categories ().begin (); } -static rdb::Categories::iterator end_sub_categories (rdb::Category *cat) +static rdb::Categories::const_iterator end_sub_categories (const rdb::Category *cat) +{ + return cat->sub_categories ().end (); +} + +static rdb::Categories::iterator begin_sub_categories_non_const (rdb::Category *cat) +{ + return cat->sub_categories ().begin (); +} + +static rdb::Categories::iterator end_sub_categories_non_const (rdb::Category *cat) { return cat->sub_categories ().end (); } @@ -248,6 +343,18 @@ ItemRefUnwrappingIterator category_items_end (const rdb::Category *cat) return cat->database ()->items_by_category (cat->id ()).second; } +ItemRefUnwrappingNonConstIterator category_items_begin_non_const (rdb::Category *cat) +{ + tl_assert (cat->database ()); + return cat->database ()->items_by_category (cat->id ()).first; +} + +ItemRefUnwrappingNonConstIterator category_items_end_non_const (rdb::Category *cat) +{ + tl_assert (cat->database ()); + return cat->database ()->items_by_category (cat->id ()).second; +} + static void scan_layer (rdb::Category *cat, const db::Layout &layout, unsigned int layer, const db::Cell *from_cell, int levels, bool with_properties) { rdb::scan_layer (cat, layout, layer, from_cell, levels, with_properties); @@ -299,6 +406,11 @@ Class decl_RdbCategory ("rdb", "RdbCategory", "\n" "This method has been introduced in version 0.23." ) + + gsi::iterator_ext ("each_item", &category_items_begin_non_const, &category_items_end_non_const, + "@brief Iterates over all items inside the database which are associated with this category (non-const version)\n" + "\n" + "This method has been introduced in version 0.29." + ) + gsi::method_ext ("scan_shapes", &scan_shapes, gsi::arg ("iter"), gsi::arg ("flat", false), gsi::arg ("with_properties", true), "@brief Scans the polygon or edge shapes from the shape iterator into the category\n" "Creates RDB items for each polygon or edge shape read from the iterator and puts them into this category.\n" @@ -379,12 +491,23 @@ Class decl_RdbCategory ("rdb", "RdbCategory", ) + gsi::iterator_ext ("each_sub_category", &begin_sub_categories, &end_sub_categories, "@brief Iterates over all sub-categories\n" + "\n" + "The const version has been added in version 0.29." + ) + + gsi::iterator_ext ("each_sub_category", &begin_sub_categories_non_const, &end_sub_categories_non_const, + "@brief Iterates over all sub-categories (non-const version)\n" ) + - gsi::method ("parent", (rdb::Category *(rdb::Category::*) ()) &rdb::Category::parent, + gsi::method ("parent", (const rdb::Category *(rdb::Category::*) () const) &rdb::Category::parent, "@brief Gets the parent category of this category\n" "@return The parent category or nil if this category is a top-level category\n" + "\n" + "The const version has been added in version 0.29." + ) + + gsi::method ("parent", (rdb::Category *(rdb::Category::*) ()) &rdb::Category::parent, + "@brief Gets the parent category of this category (non-const version)\n" + "@return The parent category or nil if this category is a top-level category\n" ) + - gsi::method ("num_items", &rdb::Category::num_items, + gsi::method ("num_items", &rdb::Category::num_items, "@brief Gets the number of items in this category\n" "The number of items includes the items in sub-categories of this category.\n" ) + @@ -923,6 +1046,16 @@ rdb::Items::const_iterator database_items_end (const rdb::Database *db) return db->items ().end (); } +rdb::Items::iterator database_items_begin_nc (rdb::Database *db) +{ + return db->items_non_const ().begin (); +} + +rdb::Items::iterator database_items_end_nc (rdb::Database *db) +{ + return db->items_non_const ().end (); +} + ItemRefUnwrappingIterator database_items_begin_cell (const rdb::Database *db, rdb::id_type cell_id) { return db->items_by_cell (cell_id).first; @@ -933,6 +1066,16 @@ ItemRefUnwrappingIterator database_items_end_cell (const rdb::Database *db, rdb: return db->items_by_cell (cell_id).second; } +ItemRefUnwrappingNonConstIterator database_items_begin_cell_nc (rdb::Database *db, rdb::id_type cell_id) +{ + return db->items_by_cell (cell_id).first; +} + +ItemRefUnwrappingNonConstIterator database_items_end_cell_nc (rdb::Database *db, rdb::id_type cell_id) +{ + return db->items_by_cell (cell_id).second; +} + ItemRefUnwrappingIterator database_items_begin_cat (const rdb::Database *db, rdb::id_type cat_id) { return db->items_by_category (cat_id).first; @@ -943,6 +1086,16 @@ ItemRefUnwrappingIterator database_items_end_cat (const rdb::Database *db, rdb:: return db->items_by_category (cat_id).second; } +ItemRefUnwrappingNonConstIterator database_items_begin_cat_nc (rdb::Database *db, rdb::id_type cat_id) +{ + return db->items_by_category (cat_id).first; +} + +ItemRefUnwrappingNonConstIterator database_items_end_cat_nc (rdb::Database *db, rdb::id_type cat_id) +{ + return db->items_by_category (cat_id).second; +} + ItemRefUnwrappingIterator database_items_begin_cc (const rdb::Database *db, rdb::id_type cell_id, rdb::id_type cat_id) { return db->items_by_cell_and_category (cell_id, cat_id).first; @@ -953,6 +1106,16 @@ ItemRefUnwrappingIterator database_items_end_cc (const rdb::Database *db, rdb::i return db->items_by_cell_and_category (cell_id, cat_id).second; } +ItemRefUnwrappingNonConstIterator database_items_begin_cc_nc (rdb::Database *db, rdb::id_type cell_id, rdb::id_type cat_id) +{ + return db->items_by_cell_and_category (cell_id, cat_id).first; +} + +ItemRefUnwrappingNonConstIterator database_items_end_cc_nc (rdb::Database *db, rdb::id_type cell_id, rdb::id_type cat_id) +{ + return db->items_by_cell_and_category (cell_id, cat_id).second; +} + rdb::Categories::const_iterator database_begin_categories (const rdb::Database *db) { return db->categories ().begin (); @@ -963,6 +1126,16 @@ rdb::Categories::const_iterator database_end_categories (const rdb::Database *db return db->categories ().end (); } +rdb::Categories::iterator database_end_categories_nc (rdb::Database *db) +{ + return db->categories_non_const ().end (); +} + +rdb::Categories::iterator database_begin_categories_nc (rdb::Database *db) +{ + return db->categories_non_const ().begin (); +} + rdb::Cells::const_iterator database_begin_cells (const rdb::Database *db) { return db->cells ().begin (); @@ -973,6 +1146,16 @@ rdb::Cells::const_iterator database_end_cells (const rdb::Database *db) return db->cells ().end (); } +rdb::Cells::iterator database_begin_cells_nc (rdb::Database *db) +{ + return db->cells_non_const ().begin (); +} + +rdb::Cells::iterator database_end_cells_nc (rdb::Database *db) +{ + return db->cells_non_const ().end (); +} + const std::string &database_tag_name (const rdb::Database *db, rdb::id_type tag) { return db->tags ().tag (tag).name (); @@ -1121,6 +1304,11 @@ Class decl_ReportDatabase ("rdb", "ReportDatabase", gsi::iterator_ext ("each_category", &database_begin_categories, &database_end_categories, "@brief Iterates over all top-level categories\n" ) + + gsi::iterator_ext ("each_category", &database_begin_categories_nc, &database_end_categories_nc, + "@brief Iterates over all top-level categories (non-const version)\n" + "\n" + "The non-const variant has been added in version 0.29." + ) + gsi::method ("create_category", (rdb::Category *(rdb::Database::*) (const std::string &)) &rdb::Database::create_category, gsi::arg ("name"), "@brief Creates a new top level category\n" "@param name The name of the category\n" @@ -1135,10 +1323,23 @@ Class decl_ReportDatabase ("rdb", "ReportDatabase", "@param path The full path to the category starting from the top level (subcategories separated by dots)\n" "@return The (const) category object or nil if the name is not valid\n" ) + + gsi::method ("category_by_path", &rdb::Database::category_by_name_non_const, gsi::arg ("path"), + "@brief Gets a category by path (non-const version)\n" + "@param path The full path to the category starting from the top level (subcategories separated by dots)\n" + "@return The (const) category object or nil if the name is not valid\n" + "\n" + "This non-const variant has been introduced in version 0.29." + ) + gsi::method ("category_by_id", &rdb::Database::category_by_id, gsi::arg ("id"), "@brief Gets a category by ID\n" "@return The (const) category object or nil if the ID is not valid\n" ) + + gsi::method ("category_by_id", &rdb::Database::category_by_id_non_const, gsi::arg ("id"), + "@brief Gets a category by ID (non-const version)\n" + "@return The (const) category object or nil if the ID is not valid\n" + "\n" + "This non-const variant has been introduced in version 0.29." + ) + gsi::method ("create_cell", (rdb::Cell *(rdb::Database::*) (const std::string &)) &rdb::Database::create_cell, gsi::arg ("name"), "@brief Creates a new cell\n" "@param name The name of the cell\n" @@ -1158,14 +1359,33 @@ Class decl_ReportDatabase ("rdb", "ReportDatabase", "@param qname The qualified name of the cell (name plus variant name optionally)\n" "@return The cell object or nil if no such cell exists\n" ) + + gsi::method ("cell_by_qname", &rdb::Database::cell_by_qname_non_const, gsi::arg ("qname"), + "@brief Returns the cell for a given qualified name (non-const version)\n" + "@param qname The qualified name of the cell (name plus variant name optionally)\n" + "@return The cell object or nil if no such cell exists\n" + "\n" + "This non-const variant has been added version 0.29." + ) + gsi::method ("cell_by_id", &rdb::Database::cell_by_id, gsi::arg ("id"), "@brief Returns the cell for a given ID\n" "@param id The ID of the cell\n" "@return The cell object or nil if no cell with that ID exists\n" ) + + gsi::method ("cell_by_id", &rdb::Database::cell_by_id_non_const, gsi::arg ("id"), + "@brief Returns the cell for a given ID (non-const version)\n" + "@param id The ID of the cell\n" + "@return The cell object or nil if no cell with that ID exists\n" + "\n" + "This non-const variant has been added version 0.29." + ) + gsi::iterator_ext ("each_cell", &database_begin_cells, &database_end_cells, "@brief Iterates over all cells\n" ) + + gsi::iterator_ext ("each_cell", &database_begin_cells_nc, &database_end_cells_nc, + "@brief Iterates over all cells (non-const version)\n" + "\n" + "This non-const variant has been added version 0.29." + ) + gsi::method ("num_items", (size_t (rdb::Database::*) () const) &rdb::Database::num_items, "@brief Returns the number of items inside the database\n" "@return The total number of items\n" @@ -1351,19 +1571,43 @@ Class decl_ReportDatabase ("rdb", "ReportDatabase", gsi::iterator_ext ("each_item", &database_items_begin, &database_items_end, "@brief Iterates over all items inside the database\n" ) + + gsi::iterator_ext ("each_item", &database_items_begin_nc, &database_items_end_nc, + "@brief Iterates over all items inside the database (non-const version)\n" + "\n" + "This non-const variant has been added in version 0.29." + ) + gsi::iterator_ext ("each_item_per_cell", &database_items_begin_cell, &database_items_end_cell, gsi::arg ("cell_id"), "@brief Iterates over all items inside the database which are associated with the given cell\n" "@param cell_id The ID of the cell for which all associated items should be retrieved\n" ) + + gsi::iterator_ext ("each_item_per_cell", &database_items_begin_cell_nc, &database_items_end_cell_nc, gsi::arg ("cell_id"), + "@brief Iterates over all items inside the database which are associated with the given cell (non-const version)\n" + "@param cell_id The ID of the cell for which all associated items should be retrieved\n" + "\n" + "This non-const variant has been added in version 0.29." + ) + gsi::iterator_ext ("each_item_per_category", &database_items_begin_cat, &database_items_end_cat, gsi::arg ("category_id"), "@brief Iterates over all items inside the database which are associated with the given category\n" "@param category_id The ID of the category for which all associated items should be retrieved\n" ) + + gsi::iterator_ext ("each_item_per_category", &database_items_begin_cat_nc, &database_items_end_cat_nc, gsi::arg ("category_id"), + "@brief Iterates over all items inside the database which are associated with the given category (non-const version)\n" + "@param category_id The ID of the category for which all associated items should be retrieved\n" + "\n" + "This non-const variant has been added in version 0.29." + ) + gsi::iterator_ext ("each_item_per_cell_and_category", &database_items_begin_cc, &database_items_end_cc, gsi::arg ("cell_id"), gsi::arg ("category_id"), "@brief Iterates over all items inside the database which are associated with the given cell and category\n" "@param cell_id The ID of the cell for which all associated items should be retrieved\n" "@param category_id The ID of the category for which all associated items should be retrieved\n" ) + + gsi::iterator_ext ("each_item_per_cell_and_category", &database_items_begin_cc_nc, &database_items_end_cc_nc, gsi::arg ("cell_id"), gsi::arg ("category_id"), + "@brief Iterates over all items inside the database which are associated with the given cell and category\n" + "@param cell_id The ID of the cell for which all associated items should be retrieved\n" + "@param category_id The ID of the category for which all associated items should be retrieved\n" + "\n" + "This non-const variant has been added in version 0.29." + ) + gsi::method ("set_item_visited", &rdb::Database::set_item_visited, gsi::arg ("item"), gsi::arg ("visited"), "@brief Modifies the visited state of an item\n" "@param item The item to modify\n" diff --git a/src/rdb/rdb/rdb.cc b/src/rdb/rdb/rdb.cc index 887383198a..464d31409f 100644 --- a/src/rdb/rdb/rdb.cc +++ b/src/rdb/rdb/rdb.cc @@ -1488,7 +1488,18 @@ Database::items_by_cell_and_category (id_type cell_id, id_type category_id) cons } } -std::pair +std::pair +Database::items_by_cell_and_category (id_type cell_id, id_type category_id) +{ + std::map , std::list >::iterator i = m_items_by_cell_and_category_id.find (std::make_pair (cell_id, category_id)); + if (i != m_items_by_cell_and_category_id.end ()) { + return std::make_pair (i->second.begin (), i->second.end ()); + } else { + return std::make_pair (empty_list.begin (), empty_list.end ()); + } +} + +std::pair Database::items_by_cell (id_type cell_id) const { std::map >::const_iterator i = m_items_by_cell_id.find (cell_id); @@ -1499,7 +1510,18 @@ Database::items_by_cell (id_type cell_id) const } } -std::pair +std::pair +Database::items_by_cell (id_type cell_id) +{ + std::map >::iterator i = m_items_by_cell_id.find (cell_id); + if (i != m_items_by_cell_id.end ()) { + return std::make_pair (i->second.begin (), i->second.end ()); + } else { + return std::make_pair (empty_list.begin (), empty_list.end ()); + } +} + +std::pair Database::items_by_category (id_type category_id) const { std::map >::const_iterator i = m_items_by_category_id.find (category_id); @@ -1510,7 +1532,18 @@ Database::items_by_category (id_type category_id) const } } -size_t +std::pair +Database::items_by_category (id_type category_id) +{ + std::map >::iterator i = m_items_by_category_id.find (category_id); + if (i != m_items_by_category_id.end ()) { + return std::make_pair (i->second.begin (), i->second.end ()); + } else { + return std::make_pair (empty_list.begin (), empty_list.end ()); + } +} + +size_t Database::num_items (id_type cell_id, id_type category_id) const { std::map , size_t>::const_iterator n = m_num_items_by_cell_and_category.find (std::make_pair (cell_id, category_id)); diff --git a/src/rdb/rdb/rdb.h b/src/rdb/rdb/rdb.h index a7859f60e9..6b5069bda2 100644 --- a/src/rdb/rdb/rdb.h +++ b/src/rdb/rdb/rdb.h @@ -2082,6 +2082,14 @@ class RDB_PUBLIC Database return *mp_categories; } + /** + * @brief Get the reference to the categories collection (non-const version) + */ + Categories &categories_non_const () + { + return *mp_categories; + } + /** * @brief Import categories * @@ -2129,6 +2137,20 @@ class RDB_PUBLIC Database return const_cast (this)->category_by_id_non_const (id); } + /** + * @brief Get the category pointer for a category name (non-const version) + * + * This method returns 0 if the category name is invalid. + */ + Category *category_by_name_non_const (const std::string &name); + + /** + * @brief Get the category pointer for a category id (non-const version) + * + * This method returns 0 if the category is invalid. + */ + Category *category_by_id_non_const (id_type id); + /** * @brief Access to the cell collection (const) */ @@ -2137,6 +2159,14 @@ class RDB_PUBLIC Database return m_cells; } + /** + * @brief Access to the cell collection + */ + Cells &cells_non_const () + { + return m_cells; + } + /** * @brief Import cells * @@ -2190,6 +2220,20 @@ class RDB_PUBLIC Database return const_cast (this)->cell_by_id_non_const (id); } + /** + * @brief Get the cell pointer for a cell name or name:variant combination (non-const version) + * + * This method returns 0 if the cell name or name:variant combination is invalid. + */ + Cell *cell_by_qname_non_const (const std::string &qname); + + /** + * @brief Get the cell pointer for a cell id (non-const version) + * + * This method returns 0 if the cell id is invalid. + */ + Cell *cell_by_id_non_const (id_type id); + /** * @brief Report the number of items in total */ @@ -2266,6 +2310,14 @@ class RDB_PUBLIC Database return *mp_items; } + /** + * @brief Get the items collection (non-const version) + */ + Items &items_non_const () + { + return *mp_items; + } + /** * @brief Set the items collection * @@ -2279,16 +2331,31 @@ class RDB_PUBLIC Database */ std::pair items_by_cell (id_type cell_id) const; + /** + * @brief Get an iterator pair that delivers the non-const items (ItemRef) for a given cell + */ + std::pair items_by_cell (id_type cell_id); + /** * @brief Get an iterator that delivers the const items (ItemRef) for a given category */ std::pair items_by_category (id_type category_id) const; + /** + * @brief Get an iterator that delivers the non-const items (ItemRef) for a given category + */ + std::pair items_by_category (id_type category_id); + /** * @brief Get an iterator that delivers the const items (ItemRef) for a given cell and category */ std::pair items_by_cell_and_category (id_type cell_id, id_type category_id) const; + /** + * @brief Get an iterator that delivers the non-const items (ItemRef) for a given cell and category + */ + std::pair items_by_cell_and_category (id_type cell_id, id_type category_id); + /** * @brief Returns true, if the database was modified */ @@ -2349,14 +2416,6 @@ class RDB_PUBLIC Database m_modified = true; } - /** - * @brief Get the items collection (non-const version) - */ - Items &items_non_const () - { - return *mp_items; - } - /** * @brief Get the reference to the tags collection (non-const version) */ @@ -2364,50 +2423,6 @@ class RDB_PUBLIC Database { return m_tags; } - - /** - * @brief Get the reference to the categories collection (non-const version) - */ - Categories &categories_non_const () - { - return *mp_categories; - } - - /** - * @brief Get the category pointer for a category name - * - * This method returns 0 if the category name is invalid. - */ - Category *category_by_name_non_const (const std::string &name); - - /** - * @brief Get the category pointer for a category id - * - * This method returns 0 if the category is invalid. - */ - Category *category_by_id_non_const (id_type id); - - /** - * @brief Access to the cell collection - */ - Cells &cells_non_const () - { - return m_cells; - } - - /** - * @brief Get the cell pointer for a cell name or name:variant combination (non-const version) - * - * This method returns 0 if the cell name or name:variant combination is invalid. - */ - Cell *cell_by_qname_non_const (const std::string &qname); - - /** - * @brief Get the cell pointer for a cell id (non-const version) - * - * This method returns 0 if the cell id is invalid. - */ - Cell *cell_by_id_non_const (id_type id); }; } diff --git a/testdata/ruby/rdbTest.rb b/testdata/ruby/rdbTest.rb index e6e1ace7d5..8b1c2b13d8 100644 --- a/testdata/ruby/rdbTest.rb +++ b/testdata/ruby/rdbTest.rb @@ -935,6 +935,78 @@ def test_12 end + def test_13 + + # manipulations + rdb = RBA::ReportDatabase::new("") + + _cell = rdb.create_cell("CELL") + _cat = rdb.create_category("cat") + _subcat = rdb.create_category(_cat, "subcat") + _subcat.description = "subcat_d" + _item1 = rdb.create_item(_cell.rdb_id, _subcat.rdb_id) + _item1.add_value(17.5) + _item1.add_value("string") + _item2 = rdb.create_item(_cell.rdb_id, _subcat.rdb_id) + _item2.add_value("b") + _subsubcat = rdb.create_category(_subcat, "subsubcat") + _cat2 = rdb.create_category("cat2") + + cell = rdb.cell_by_id(_cell.rdb_id) + assert_equal(cell._is_const_object?, false) + assert_equal(rdb.each_cell.first._is_const_object?, false) + + cell = rdb.cell_by_qname("CELL") + assert_equal(cell._is_const_object?, false) + + cat = rdb.category_by_id(_cat.rdb_id) + assert_equal(cat._is_const_object?, false) + + cat = rdb.category_by_path("cat") + assert_equal(cat._is_const_object?, false) + subcat = rdb.category_by_path("cat.subcat") + + assert_equal(rdb.each_category.first._is_const_object?, false) + assert_equal(rdb.each_category.collect { |c| c.name }.join(","), "cat,cat2") + assert_equal(subcat._is_const_object?, false) + assert_equal(subcat.database._is_const_object?, false) + assert_equal(subcat.name, "subcat") + assert_equal(subcat.parent.name, "cat") + + assert_equal(subcat.description, "subcat_d") + subcat.description = "changed" + assert_equal(subcat.description, "changed") + + assert_equal(rdb.each_item_per_category(subcat.rdb_id).collect { |item| item.each_value.collect { |v| v.to_s }.join("/") }.join(";"), "float: 17.5/text: string;text: b") + + item1 = rdb.each_item_per_category(subcat.rdb_id).first + assert_equal(item1._is_const_object?, false) + item1.clear_values + assert_equal(rdb.each_item_per_category(subcat.rdb_id).collect { |item| item.each_value.collect { |v| v.to_s }.join("/") }.join(";"), ";text: b") + item1.add_value("x") + assert_equal(rdb.each_item_per_category(subcat.rdb_id).collect { |item| item.each_value.collect { |v| v.to_s }.join("/") }.join(";"), "text: x;text: b") + item1.add_tag(17) + assert_equal(item1.has_tag?(17), true) + assert_equal(item1.has_tag?(16), false) + + item1 = rdb.each_item.first + assert_equal(item1._is_const_object?, false) + assert_equal(item1.has_tag?(17), true) + + item1 = rdb.each_item_per_cell(cell.rdb_id).first + assert_equal(item1._is_const_object?, false) + assert_equal(item1.has_tag?(17), true) + + item1 = rdb.each_item_per_cell_and_category(cell.rdb_id, subcat.rdb_id).first + assert_equal(item1._is_const_object?, false) + assert_equal(item1.has_tag?(17), true) + + item1 = cell.each_item.first + assert_equal(item1._is_const_object?, false) + assert_equal(item1.has_tag?(17), true) + + end + end load("test_epilogue.rb") From f2d61e1dee6da22720978d63b39e996e8d146836 Mon Sep 17 00:00:00 2001 From: klayoutmatthias Date: Mon, 11 Mar 2024 22:39:59 +0000 Subject: [PATCH 2/2] Fixed a crash with Ruby 2.0.0 on CentOS7 --- testdata/ruby/rdbTest.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testdata/ruby/rdbTest.rb b/testdata/ruby/rdbTest.rb index 8b1c2b13d8..abc40519f6 100644 --- a/testdata/ruby/rdbTest.rb +++ b/testdata/ruby/rdbTest.rb @@ -954,7 +954,7 @@ def test_13 cell = rdb.cell_by_id(_cell.rdb_id) assert_equal(cell._is_const_object?, false) - assert_equal(rdb.each_cell.first._is_const_object?, false) + assert_equal(rdb.each_cell.to_a[0]._is_const_object?, false) cell = rdb.cell_by_qname("CELL") assert_equal(cell._is_const_object?, false) @@ -966,7 +966,7 @@ def test_13 assert_equal(cat._is_const_object?, false) subcat = rdb.category_by_path("cat.subcat") - assert_equal(rdb.each_category.first._is_const_object?, false) + assert_equal(rdb.each_category.to_a[0]._is_const_object?, false) assert_equal(rdb.each_category.collect { |c| c.name }.join(","), "cat,cat2") assert_equal(subcat._is_const_object?, false) assert_equal(subcat.database._is_const_object?, false) @@ -979,7 +979,7 @@ def test_13 assert_equal(rdb.each_item_per_category(subcat.rdb_id).collect { |item| item.each_value.collect { |v| v.to_s }.join("/") }.join(";"), "float: 17.5/text: string;text: b") - item1 = rdb.each_item_per_category(subcat.rdb_id).first + item1 = rdb.each_item_per_category(subcat.rdb_id).to_a[0] assert_equal(item1._is_const_object?, false) item1.clear_values assert_equal(rdb.each_item_per_category(subcat.rdb_id).collect { |item| item.each_value.collect { |v| v.to_s }.join("/") }.join(";"), ";text: b") @@ -989,19 +989,19 @@ def test_13 assert_equal(item1.has_tag?(17), true) assert_equal(item1.has_tag?(16), false) - item1 = rdb.each_item.first + item1 = rdb.each_item.to_a[0] assert_equal(item1._is_const_object?, false) assert_equal(item1.has_tag?(17), true) - item1 = rdb.each_item_per_cell(cell.rdb_id).first + item1 = rdb.each_item_per_cell(cell.rdb_id).to_a[0] assert_equal(item1._is_const_object?, false) assert_equal(item1.has_tag?(17), true) - item1 = rdb.each_item_per_cell_and_category(cell.rdb_id, subcat.rdb_id).first + item1 = rdb.each_item_per_cell_and_category(cell.rdb_id, subcat.rdb_id).to_a[0] assert_equal(item1._is_const_object?, false) assert_equal(item1.has_tag?(17), true) - item1 = cell.each_item.first + item1 = cell.each_item.to_a[0] assert_equal(item1._is_const_object?, false) assert_equal(item1.has_tag?(17), true)