File: FactoryPlugins.cc

package info (click to toggle)
ignition-plugin 1.2.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 728 kB
  • sloc: cpp: 4,712; ansic: 277; ruby: 128; sh: 38; makefile: 12
file content (176 lines) | stat: -rw-r--r-- 4,143 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright (C) 2018 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

#include <ignition/plugin/Register.hh>

#include "FactoryPlugins.hh"

namespace test
{
namespace util
{
/// \brief An implementation that takes in a std::string and returns that same
/// value.
class DummyNameForward : public DummyNameBase
{
  public: DummyNameForward(const std::string &_name)
    : name(_name)
  {
    // Do nothing
  }

  public: std::string MyNameIs() const override
  {
    return name;
  }

  private: const std::string name;
};
IGNITION_ADD_FACTORY(DummyNameForward, NameFactory)

/// \brief An implementation that takes in a std::string and says hello to it.
class DummyNameSayHello : public DummyNameBase
{
  public: DummyNameSayHello(const std::string &_name)
    : name(_name)
  {
    // Do nothing
  }

  public: std::string MyNameIs() const override
  {
    return "Hello, " + name + "!";
  }

  private: const std::string name;
};
IGNITION_ADD_FACTORY(DummyNameSayHello, NameFactory)

/// \brief An implementation that takes in a double and returns that same value.
class DummyDoubleForward : public DummyDoubleBase
{
  public: DummyDoubleForward(const double _value)
    : value(_value)
  {
    // Do nothing
  }

  public: double MyDoubleValueIs() const override
  {
    return value;
  }

  private: const double value;
};
IGNITION_ADD_FACTORY(DummyDoubleForward, DoubleFactory)

/// \brief An implementation takes in a double and returns that same value plus
/// one-half.
class DummyDoubleAddOneHalf : public DummyDoubleBase
{
  public: DummyDoubleAddOneHalf(const double _value)
    : value(_value + 0.5)
  {
    // Do nothing
  }

  public: double MyDoubleValueIs() const override
  {
    return value;
  }

  private: const double value;
};
IGNITION_ADD_FACTORY(DummyDoubleAddOneHalf, DoubleFactory)

/// \brief An implementation that takes in an int and returns that same value.
class DummyIntForward : public DummyIntBase
{
  public: DummyIntForward(const int _value)
    : value(_value)
  {
    // Do nothing
  }

  public: int MyIntegerValueIs() const override
  {
    return value;
  }

  private: const int value;
};
IGNITION_ADD_FACTORY(DummyIntForward, IntFactory)

/// \brief An implementation takes in an int and returns that same value plus
/// one.
class DummyIntAddOne : public DummyIntBase
{
  public: DummyIntAddOne(const int _value)
    : value(_value + 1)
  {
    // Do nothing
  }

  public: int MyIntegerValueIs() const override
  {
    return value;
  }

  private: const int value;
};
IGNITION_ADD_FACTORY(DummyIntAddOne, IntFactory)

/// \brief An implementation of SomeObject that just sets the values that get
/// passed to it.
class SomeObjectForward : public SomeObject
{
  public: SomeObjectForward(int _intValue, double _doubleValue)
    : SomeObject{_intValue, _doubleValue}
  {
    // Do nothing
  }

  public: double SomeOperation() const override
  {
    return this->someInt + this->someDouble;
  }
};
IGNITION_ADD_FACTORY(SomeObjectForward, SomeObjectFactory)

/// \brief An implementation of SomeObject that adds two to each value that gets
/// passed to it.
class SomeObjectAddTwo : public SomeObject
{
  public: SomeObjectAddTwo(int _intValue, double _doubleValue)
    : SomeObject{_intValue + 2, _doubleValue + 2.0}
  {
    // Do nothing
  }

  public: double SomeOperation() const override
  {
    return this->someInt + this->someDouble + 2;
  }
};
IGNITION_ADD_FACTORY(SomeObjectAddTwo, SomeObjectFactory)

IGNITION_ADD_FACTORY_ALIAS(
    SomeObjectAddTwo, SomeObjectFactory,
    "This factory has an alias", "and also a second alias")

}
}