Skip to content

Commit

Permalink
Instances should make valueFeature available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcohol committed Jul 21, 2024
1 parent fa1f5c5 commit c8c520d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions BabelWiresLib/Instance/instanceTemplates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
**/
#pragma once

#include <BabelWiresLib/TypeSystem/valueHolder.hpp>
#include <BabelWiresLib/Features/valueFeature.hpp>
#include <BabelWiresLib/TypeSystem/valueHolder.hpp>

namespace babelwires {
/// The default approach to finding the appropriate instance class is this template.
/// For record-style types it "despatches to" (i.e. inherits from) a corresponding inner-class
/// in the type's class. However, some types (e.g. built-ins) specialize the template instead.
template <typename VALUE_FEATURE, typename VALUE_TYPE> class Instance : public VALUE_TYPE::template Instance<VALUE_FEATURE> {
template <typename VALUE_FEATURE, typename VALUE_TYPE>
class Instance : public VALUE_TYPE::template Instance<VALUE_FEATURE> {
public:
Instance(VALUE_FEATURE& valueFeature)
: VALUE_TYPE::template Instance<VALUE_FEATURE>(valueFeature) {}
Expand All @@ -28,6 +29,11 @@ namespace babelwires {
: m_valueFeature(valueFeature) {
assert(valueFeature.getType().template as<VALUE_TYPE>());
}
VALUE_FEATURE& getValueFeature() const { return m_valueFeature; }
template <typename VALUE_FEATURE_M = VALUE_FEATURE>
std::enable_if_t<!std::is_const_v<VALUE_FEATURE_M>, VALUE_FEATURE> getValueFeature() {
return m_valueFeature;
}
const VALUE_TYPE& getInstanceType() const { return m_valueFeature.getType().template is<VALUE_TYPE>(); }
const babelwires::ValueHolder& getInstanceValue() const { return m_valueFeature.getValue(); }

Expand All @@ -36,13 +42,13 @@ namespace babelwires {
};

/// Can be specialized to make additional methods available for inner-class defined instances of particular types.
/// For example, RecordWithVariantType classes use this to have common methods (for variant handling) while having bespoke
/// fields defined by the instanceDSL macros.
/// For example, RecordWithVariantType classes use this to have common methods (for variant handling) while having
/// bespoke fields defined by the instanceDSL macros.
template <typename VALUE_FEATURE, typename VALUE_TYPE>
class InstanceParent : public InstanceCommonBase<VALUE_FEATURE, VALUE_TYPE> {
public:
InstanceParent(VALUE_FEATURE& valueFeature)
: InstanceCommonBase<VALUE_FEATURE, VALUE_TYPE>(valueFeature) {}
};

}
} // namespace babelwires

0 comments on commit c8c520d

Please sign in to comment.