Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jun 17, 2024
1 parent d9d4361 commit e88a048
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 167 deletions.
4 changes: 2 additions & 2 deletions cmake/toolchain_clang.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SET(CMAKE_C_COMPILER clang)
SET(CMAKE_CXX_COMPILER clang++)
SET(CMAKE_C_COMPILER clang-15)
SET(CMAKE_CXX_COMPILER clang++-15)
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
161 changes: 161 additions & 0 deletions include/ariles2/visitors/aggregate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
@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 ParametersWraper
{
public:
typename t_Visitor::Parameters parameters_;

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

ParametersWraper(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 ParametersWraper<t_Visitor>,
public Parameters<t_Visitors...>
{
public:
Parameters(const bool override_parameters = true)
: ParametersWraper<t_Visitor>(override_parameters), Parameters<t_Visitors...>(override_parameters)
{
}

template <class... t_Parameters>
Parameters(const typename t_Visitor::Parameters &parameters, t_Parameters &&...other_parameters)
: ParametersWraper<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)
: ParametersWraper<t_Visitor>(override_parameters)
, Parameters<t_Visitors...>(parameters, override_parameters)
{
}

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

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



/*
template <class t_Visitor>
class ARILES2_VISIBILITY_ATTRIBUTE BaseVisitorWraper
{
public:
t_Visitor visitor_;
public:
BaseVisitorWraper() {};
template<class... t_Args>
BaseVisitorWraper(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 BaseVisitorWraper<t_Visitor>,
public BaseVisitor<t_Visitors...>
{
};


template <class... t_Visitors>
class ARILES2_VISIBILITY_ATTRIBUTE Visitor
: public BaseVisitor<t_Visitors...>,
public visitor::Base<visitor::GenericVisitor, Parameters<t_Visitors...>>
{
public:
using Parameters = aggregate::Parameters<t_Visitors...>;

public:
using visitor::Base<visitor::GenericVisitor, Parameters>::getDefaultParameters;
};
} // namespace aggregate
} // namespace ariles2
Loading

0 comments on commit e88a048

Please sign in to comment.