Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jun 19, 2024
1 parent d9d4361 commit ca96610
Show file tree
Hide file tree
Showing 29 changed files with 280 additions and 304 deletions.
13 changes: 10 additions & 3 deletions extra_visitors/protobuf3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
set (TGT_ARILES_VISITOR_LIB "${PROJECT_NAME}_visitor_${ARILES_VISITOR}")

if(NOT ARILES_DEB_TARGETS)
find_package(Protobuf REQUIRED)
set(protobuf_MODULE_COMPATIBLE ON CACHE STRING "")
find_package(Protobuf CONFIG)

set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${Protobuf_INCLUDE_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${Protobuf_LIBRARIES}")
if(Protobuf_FOUND)
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "protobuf::libprotobuf")
else()
find_package(Protobuf REQUIRED)

set(ARILES_VISITOR_${ARILES_VISITOR}_INCLUDES "${Protobuf_INCLUDE_DIRS}")
set(ARILES_VISITOR_${ARILES_VISITOR}_LIBS "${Protobuf_LIBRARIES}")
endif()
endif()

add_library(${TGT_ARILES_VISITOR_LIB} INTERFACE)
Expand Down
4 changes: 1 addition & 3 deletions extra_visitors/protobuf3/ariles2/visitors/protobuf3/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ namespace ariles2
{
namespace ns_protobuf3
{
class ARILES2_VISIBILITY_ATTRIBUTE Reader : public visitor::Base<visitor::Visitor, visitor::Parameters>
class ARILES2_VISIBILITY_ATTRIBUTE Reader : public visitor::Base<Reader, visitor::Parameters>
{
public:
using Parameters = visitor::Parameters;


public:
using visitor::Base<visitor::Visitor, Parameters>::getDefaultParameters;

template <class t_Ariles>
const Parameters &getParameters(const t_Ariles &ariles_class) const
{
Expand Down
4 changes: 1 addition & 3 deletions extra_visitors/protobuf3/ariles2/visitors/protobuf3/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ namespace ariles2
{
namespace ns_protobuf3
{
class ARILES2_VISIBILITY_ATTRIBUTE Writer : public visitor::Base<visitor::Visitor, visitor::Parameters>
class ARILES2_VISIBILITY_ATTRIBUTE Writer : public visitor::Base<Writer, visitor::Parameters>
{
public:
using Parameters = visitor::Parameters;


public:
using visitor::Base<visitor::Visitor, Parameters>::getDefaultParameters;

template <class t_Ariles>
const Parameters &getParameters(const t_Ariles &ariles_class) const
{
Expand Down
10 changes: 5 additions & 5 deletions include/ariles2/adapters/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace ariles2
const t_Left &left,
const t_Right &right,
const typename t_Visitor::Parameters &param,
ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left))
ARILES2_IS_ARILES_ENABLER(t_Left))
{
ARILES2_TRACE_FUNCTION;
if (param.compare_number_of_entries_)
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace ariles2
const t_Visitor &visitor,
t_Entry &entry,
const typename t_Visitor::Parameters &param,
ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Entry))
ARILES2_IS_ARILES_ENABLER(t_Entry))
{
ARILES2_TRACE_FUNCTION;
entry.arilesVirtualVisit(visitor, param);
Expand All @@ -306,7 +306,7 @@ namespace ariles2
const t_Visitor &,
t_Entry &,
const typename t_Visitor::Parameters &,
ARILES2_IS_BASE_DISABLER(ariles2::Ariles, t_Entry))
ARILES2_IS_ARILES_DISABLER(t_Entry))
{
ARILES2_TRACE_FUNCTION;
}
Expand All @@ -325,7 +325,7 @@ namespace ariles2
t_Left &left,
const t_Right &right,
const typename t_Visitor::Parameters &param,
ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left))
ARILES2_IS_ARILES_ENABLER(t_Left))
{
ARILES2_TRACE_FUNCTION;
ARILES2_TRACE_TYPE(left);
Expand Down Expand Up @@ -371,7 +371,7 @@ namespace ariles2
const t_Left &left,
t_Right &right,
const typename t_Visitor::Parameters &param,
ARILES2_IS_BASE_ENABLER(ariles2::Ariles, t_Left))
ARILES2_IS_ARILES_ENABLER(t_Left))
{
ARILES2_TRACE_FUNCTION;
ARILES2_TRACE_TYPE(left);
Expand Down
14 changes: 10 additions & 4 deletions include/ariles2/internal/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@

#define ARILES2_IS_FLOATING_POINT_ENABLER_TYPE(Real) std::enable_if<(std::is_floating_point<Real>::value)>::type *

#define ARILES2_IS_BASE_OF(Base, Derived) std::is_base_of<Base, Derived>::value

#define ARILES2_IS_BASE_ENABLER(Base, Derived) \
const typename std::enable_if<(ARILES2_IS_BASE_OF(Base, Derived))>::type * = nullptr
const typename std::enable_if<std::is_base_of<Base, Derived>::value>::type * = nullptr

#define ARILES2_IS_BASE_DISABLER(Base, Derived) \
const typename std::enable_if<not(ARILES2_IS_BASE_OF(Base, Derived))>::type * = nullptr
const typename std::enable_if<not std::is_base_of<Base, Derived>::value>::type * = nullptr

#define ARILES2_IS_ANY_OF(Type, Type1, Type2) \
const typename std::enable_if<std::is_base_of<Type1, Type>::value or std::is_base_of<Type2, Type>::value>::type \
* = nullptr

#define ARILES2_IS_VISITOR_ENABLER(Derived) \
const typename std::enable_if<std::is_base_of<ariles2::visitor::Visitor, Derived>::value>::type * = nullptr

#define ARILES2_IS_ARILES_ENABLER(Derived) \
const typename std::enable_if<std::is_base_of<ariles2::Ariles, Derived>::value>::type * = nullptr

#define ARILES2_IS_ARILES_DISABLER(Derived) \
const typename std::enable_if<not std::is_base_of<ariles2::Ariles, Derived>::value>::type * = nullptr


#include "build_config.h"
Expand Down
4 changes: 2 additions & 2 deletions include/ariles2/members/visit_generic_parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
void arilesVisitParents( \
t_Visitor &visitor, \
const typename t_Visitor::Parameters &parameters, \
ARILES2_IS_BASE_ENABLER(ariles2::visitor::GenericVisitor, t_Visitor)) \
ARILES2_IS_VISITOR_ENABLER(t_Visitor)) \
{ \
ARILES2_UNUSED_ARG(visitor); \
ARILES2_UNUSED_ARG(parameters); \
Expand All @@ -25,7 +25,7 @@
void arilesVisitParents( \
t_Visitor &visitor, \
const typename t_Visitor::Parameters &parameters, \
ARILES2_IS_BASE_ENABLER(ariles2::visitor::GenericVisitor, t_Visitor)) const \
ARILES2_IS_VISITOR_ENABLER(t_Visitor)) const \
{ \
ARILES2_UNUSED_ARG(visitor); \
ARILES2_UNUSED_ARG(parameters); \
Expand Down
158 changes: 158 additions & 0 deletions include/ariles2/visitors/aggregate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
@file
@author Alexander Sherikov
@copyright 2017-2024 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
(see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
@brief
*/

#pragma once

#include "common.h"


namespace ariles2
{
/// @ingroup aggregate
namespace aggregate
{
template <class t_Visitor>
class ARILES2_VISIBILITY_ATTRIBUTE ParametersWrapper
{
public:
typename t_Visitor::Parameters parameters_;

public:
ParametersWrapper(const bool override_parameters = true) : parameters_(override_parameters)
{
}

ParametersWrapper(const typename t_Visitor::Parameters &parameters) : parameters_(parameters)
{
}

template <
class t_IdType,
typename = std::enable_if_t<
std::is_same<t_IdType, t_Visitor>::value
or std::is_base_of<t_IdType, typename t_Visitor::Parameters>::value>>
typename t_Visitor::Parameters &get()
{
return (parameters_);
}

template <
class t_IdType,
typename = std::enable_if_t<
std::is_same<t_IdType, t_Visitor>::value
or std::is_base_of<t_IdType, typename t_Visitor::Parameters>::value>>
const typename t_Visitor::Parameters &get() const
{
return (parameters_);
}
};

template <class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE Parameters;

template <>
class ARILES2_VISIBILITY_ATTRIBUTE Parameters<>
{
public:
Parameters(const bool){};
Parameters(){};

void get(){};
};

template <class t_Visitor, class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE Parameters<t_Visitor, t_Visitors...> : public ParametersWrapper<t_Visitor>,
public Parameters<t_Visitors...>
{
public:
Parameters(const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(override_parameters), Parameters<t_Visitors...>(override_parameters)
{
}

template <class... t_Parameters>
Parameters(const typename t_Visitor::Parameters &parameters, t_Parameters &&...other_parameters)
: ParametersWrapper<t_Visitor>(parameters)
, Parameters<t_Visitors...>(std::forward<t_Parameters>(other_parameters)...)
{
}

template <class t_Parameters>
Parameters(const t_Parameters &parameters, const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(override_parameters)
, Parameters<t_Visitors...>(parameters, override_parameters)
{
}

Parameters(const typename t_Visitor::Parameters &parameters, const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(parameters), Parameters<t_Visitors...>(override_parameters)
{
}

using ParametersWrapper<t_Visitor>::get;
using Parameters<t_Visitors...>::get;
};



/*
template <class t_Visitor>
class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitorWrapper
{
public:
t_Visitor visitor_;
public:
BaseVisitorWrapper() {};
template<class... t_Args>
BaseVisitorWrapper(t_Args &&... args) : visitor_(std::forward<t_Args>(args)...)
{
}
template <class t_GetVisitor, typename = std::enable_if_t<std::is_same<t_GetVisitor, t_Visitor>::value>>
t_Visitor &get()
{
return (visitor_);
}
template <class t_GetVisitor, typename = std::enable_if_t<std::is_same<t_GetVisitor, t_Visitor>::value>>
const t_Visitor &get() const
{
return (visitor_);
}
};
*/

template <class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor;

template <>
class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor<>
{
};

template <class t_Visitor, class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitor<t_Visitor, t_Visitors...> : // public BaseVisitorWrapper<t_Visitor>,
public BaseVisitor<t_Visitors...>
{
};


template <class t_Derived, class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE Visitor
: public BaseVisitor<t_Visitors...>,
public visitor::Base<t_Derived, Parameters<t_Visitors...>>
{
public:
using Parameters = aggregate::Parameters<t_Visitors...>;
};
} // namespace aggregate
} // namespace ariles2
Loading

0 comments on commit ca96610

Please sign in to comment.