Skip to content

Commit

Permalink
Merge pull request #32 from project-tsurugi/wip/schema-maybe-shared
Browse files Browse the repository at this point in the history
fix: make schema descriptor hold `maybe_shared_ptr`.
  • Loading branch information
kuron99 authored Jun 25, 2024
2 parents a2bdea8 + d7f83ed commit 862a296
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/yugawara/binding/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct descriptor_extract<::takatori::descriptor::schema, schema::declaration> :
using descriptor_type = ::takatori::descriptor::schema;
using entity_type = schema::declaration;
using result_type = ::takatori::util::optional_ptr<entity_type const>;
using pointer_type = std::shared_ptr<entity_type const>;
using pointer_type = ::takatori::util::maybe_shared_ptr<entity_type const>;
[[nodiscard]] static result_type extract(descriptor_type const& desc, bool fail_if_mismatch);
[[nodiscard]] static pointer_type extract_shared(descriptor_type const& desc, bool fail_if_mismatch);
};
Expand Down
13 changes: 7 additions & 6 deletions include/yugawara/binding/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <takatori/plan/exchange.h>

#include <takatori/util/maybe_shared_ptr.h>
#include <takatori/util/optional_ptr.h>

#include <yugawara/variable/declaration.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ class factory {
* @brief creates a new index descriptor.
* @param declaration the original declaration
*/
[[nodiscard]] ::takatori::descriptor::relation index(std::shared_ptr<storage::index const> declaration);
[[nodiscard]] ::takatori::descriptor::relation index(::takatori::util::maybe_shared_ptr<storage::index const> declaration);

/**
* @brief creates a new exchange descriptor.
Expand Down Expand Up @@ -145,7 +146,7 @@ class factory {
* @brief creates a new schema descriptor.
* @param declaration the original declaration
*/
[[nodiscard]] ::takatori::descriptor::schema schema(std::shared_ptr<schema::declaration const> declaration);
[[nodiscard]] ::takatori::descriptor::schema schema(::takatori::util::maybe_shared_ptr<schema::declaration const> declaration);

/**
* @brief creates a new schema descriptor.
Expand All @@ -170,8 +171,8 @@ class factory {
/// @copydoc index(storage::index const&)
[[nodiscard]] ::takatori::descriptor::relation operator()(storage::index const& declaration);

/// @copydoc index(std::shared_ptr<storage::index const>)
[[nodiscard]] ::takatori::descriptor::relation operator()(std::shared_ptr<storage::index const> declaration);
/// @copydoc index(::takatori::util::maybe_shared_ptr<storage::index const>)
[[nodiscard]] ::takatori::descriptor::relation operator()(::takatori::util::maybe_shared_ptr<storage::index const> declaration);

/// @copydoc exchange()
[[nodiscard]] ::takatori::descriptor::relation operator()(::takatori::plan::exchange const& declaration);
Expand All @@ -197,8 +198,8 @@ class factory {
/// @copydoc aggregate_function(aggregate::declaration&&)
[[nodiscard]] ::takatori::descriptor::aggregate_function operator()(aggregate::declaration&& declaration);

/// @copydoc schema(std::shared_ptr<schema::declaration const>)
[[nodiscard]] ::takatori::descriptor::schema operator()(std::shared_ptr<schema::declaration const> declaration);
/// @copydoc schema(::takatori::util::maybe_shared_ptr<schema::declaration const>)
[[nodiscard]] ::takatori::descriptor::schema operator()(::takatori::util::maybe_shared_ptr<schema::declaration const> declaration);

/// @copydoc schema(schema::declaration&&)
[[nodiscard]] ::takatori::descriptor::schema operator()(schema::declaration&& declaration);
Expand Down
3 changes: 2 additions & 1 deletion include/yugawara/binding/schema_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <takatori/descriptor/schema.h>
#include <takatori/util/object.h>
#include <takatori/util/maybe_shared_ptr.h>

#include <yugawara/schema/declaration.h>

Expand All @@ -18,7 +19,7 @@ class schema_info : public ::takatori::descriptor::schema::entity_type {
using descriptor_type = ::takatori::descriptor::schema;

/// @brief the pointer type of schema declaration.
using declaration_pointer = std::shared_ptr<schema::declaration const>;
using declaration_pointer = ::takatori::util::maybe_shared_ptr<schema::declaration const>;

/**
* @brief creates a new instance.
Expand Down
10 changes: 6 additions & 4 deletions src/yugawara/binding/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

namespace yugawara::binding {

using ::takatori::util::maybe_shared_ptr;

::takatori::descriptor::relation factory::index(storage::index const& declaration) {
return wrap(std::make_shared<index_info>(declaration));
}

::takatori::descriptor::relation factory::index(std::shared_ptr<storage::index const> declaration) {
::takatori::descriptor::relation factory::index(maybe_shared_ptr<storage::index const> declaration) {
return wrap(std::make_shared<index_info>(std::move(declaration)));
}

Expand Down Expand Up @@ -89,7 +91,7 @@ ::takatori::descriptor::aggregate_function factory::aggregate_function(aggregate
return aggregate_function(std::make_shared<aggregate::declaration>(std::move(declaration)));
}

::takatori::descriptor::schema factory::schema(std::shared_ptr<schema::declaration const> declaration) {
::takatori::descriptor::schema factory::schema(maybe_shared_ptr<schema::declaration const> declaration) {
return wrap(std::make_shared<schema_info>(std::move(declaration)));
}

Expand All @@ -109,7 +111,7 @@ ::takatori::descriptor::relation factory::operator()(storage::index const& decla
return index(declaration);
}

::takatori::descriptor::relation factory::operator()(std::shared_ptr<storage::index const> declaration) {
::takatori::descriptor::relation factory::operator()(maybe_shared_ptr<storage::index const> declaration) {
return index(std::move(declaration));
}

Expand Down Expand Up @@ -146,7 +148,7 @@ ::takatori::descriptor::aggregate_function factory::operator()(aggregate::declar
return aggregate_function(std::move(declaration));
}

::takatori::descriptor::schema factory::operator()(std::shared_ptr<schema::declaration const> declaration) {
::takatori::descriptor::schema factory::operator()(maybe_shared_ptr<schema::declaration const> declaration) {
return schema(std::move(declaration));
}

Expand Down

0 comments on commit 862a296

Please sign in to comment.