Ariles
Loading...
Searching...
No Matches
copyfrom.h
Go to the documentation of this file.
1/**
2 @file
3 @author Alexander Sherikov
4
5 @copyright 2017-2020 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6 (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7
8 @brief
9*/
10
11#pragma once
12
13#include "common.h"
14
15/**
16@defgroup copyfrom CopyFrom
17
18@brief Copy data from non-ariles classes.
19*/
20
21namespace ariles2
22{
23 /// @ingroup copyfrom
24 namespace copyfrom
25 {
27 {
28 public:
30
31 public:
32 explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
33 {
34 deep_copy_ = true;
35 }
36 };
37
38
39 class Visitor : public visitor::Base<Visitor, copyfrom::Parameters>
40 {
41 public:
43
44
45 public:
46 template <class t_Left, class t_Right>
47 void visit(t_Left &left, const t_Right &right, const std::string &name, const Parameters &param)
48 {
50 try
51 {
52 this->visitMapEntry(left, right, name, param);
53 }
54 catch (std::exception &e)
55 {
56 CPPUT_THROW("Copying failed: ", e.what());
57 }
58 }
59
60
61 template <class t_Left, class t_Right>
62 void visitMapEntry(t_Left &left, const t_Right &right, const std::string &name, const Parameters &param)
63 {
66 CPPUT_TRACE_TYPE(left);
67 CPPUT_TRACE_TYPE(right);
68
69 try
70 {
71 apply_copyfrom(*this, left, right, param);
72 }
73 catch (const std::exception &e)
74 {
75 CPPUT_THROW("entry: ", name, " // ", e.what());
76 }
77 }
78 };
79
80
81 class Base
82 {
83 };
84
85
86#define ARILES2_NAMED_ENTRY_copyfrom(v, entry, name) visitor.visitMapEntry(entry, other.name, #name, parameters);
87#define ARILES2_PARENT_copyfrom(v, entry) entry::arilesVisit(visitor, other, parameters);
88
89#define ARILES2_VISIT_copyfrom \
90 template <class t_Other> /* cppcheck-suppress duplInheritedMember */ \
91 void arilesVisit( \
92 ariles2::copyfrom::Visitor &visitor, \
93 const t_Other &other, \
94 const typename ariles2::copyfrom::Visitor::Parameters &parameters) \
95 { \
96 CPPUT_UNUSED_ARG(visitor); \
97 CPPUT_UNUSED_ARG(other); \
98 CPPUT_UNUSED_ARG(parameters); \
99 CPPUT_TRACE_FUNCTION; \
100 ARILES2_ENTRIES(copyfrom) \
101 }
102
103#define ARILES2_METHODS_copyfrom \
104 const ariles2::copyfrom::Visitor::Parameters &arilesGetParameters(const ariles2::copyfrom::Visitor &visitor) const \
105 { \
106 CPPUT_TRACE_FUNCTION; \
107 return (visitor.getDefaultParameters()); \
108 }
109#define ARILES2_BASE_METHODS_copyfrom
110 } // namespace copyfrom
111
112
113 /// @ingroup copyfrom
115} // namespace ariles2
Parameters(const bool override_parameters=true)
Definition copyfrom.h:32
void visitMapEntry(t_Left &left, const t_Right &right, const std::string &name, const Parameters &param)
Definition copyfrom.h:62
void visit(t_Left &left, const t_Right &right, const std::string &name, const Parameters &param)
Definition copyfrom.h:47
#define CPPUT_THROW(...)
Definition exception.h:19
void apply_copyfrom(t_Visitor &visitor, t_Left &left, const t_Right &right, const typename t_Visitor::Parameters &param)
Definition basic.h:307
#define CPPUT_TRACE_FUNCTION
Definition trace.h:126
#define CPPUT_TRACE_TYPE(type)
Definition trace.h:128
#define CPPUT_TRACE_VALUE(value)
Definition trace.h:127