CppEnum.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <memory>
27 #include <vector>
28 
29 #include "MetaEnum.h"
30 
31 #include <boost/format/format_fwd.hpp>
32 
33 #include "CppWriter.h"
34 
35 namespace armarx
36 {
37  class CppEnumField;
38  using CppEnumFieldPtr = std::shared_ptr<CppEnumField>;
39 
41  {
42  public:
43  CppEnumField(const std::string& name);
44  CppEnumField(const std::string& name, int value);
45 
46  void writeCpp(const CppWriterPtr& writer, bool addComma = false);
47 
48  private:
49  std::string name;
50  int value = -1;
51  bool hasValue = false;
52  };
53 
54  class CppEnum;
55  using CppEnumPtr = std::shared_ptr<CppEnum>;
56 
57  class CppEnum : public MetaEnum
58  {
59  public:
60  CppEnum(const std::vector<std::string> namespaces, const std::string& name);
61  CppEnum(const std::vector<std::string> namespaces, const std::string& name, const std::vector<CppEnumFieldPtr>& fields);
62 
63  void addField(const CppEnumFieldPtr&);
64 
65  std::vector<std::string> getNamespaces() const;
66 
67  void write(const MetaWriterPtr& writer) override;
68  void writeCpp(const CppWriterPtr& writer);
69 
70  private:
71  std::vector<std::string> namespaces;
72  std::vector<CppEnumFieldPtr> fields;
73  };
74 }
armarx::CppEnumFieldPtr
std::shared_ptr< CppEnumField > CppEnumFieldPtr
Definition: CppEnum.h:38
armarx::CppEnumField
Definition: CppEnum.h:40
armarx::CppEnumField::writeCpp
void writeCpp(const CppWriterPtr &writer, bool addComma=false)
Definition: CppEnum.cpp:44
MetaEnum.h
armarx::CppEnum::getNamespaces
std::vector< std::string > getNamespaces() const
Definition: CppEnum.cpp:77
CppWriter.h
armarx::CppEnum::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppEnum.cpp:82
armarx::CppEnumPtr
std::shared_ptr< CppEnum > CppEnumPtr
Definition: CppEnum.h:55
armarx::CppEnum::addField
void addField(const CppEnumFieldPtr &)
Definition: CppEnum.cpp:72
armarx::CppEnum::CppEnum
CppEnum(const std::vector< std::string > namespaces, const std::string &name)
Definition: CppEnum.cpp:53
armarx::MetaEnum
Definition: MetaEnum.h:35
armarx::MetaWriterPtr
std::shared_ptr< MetaWriter > MetaWriterPtr
Definition: MetaWriter.h:37
armarx::CppEnum
Definition: CppEnum.h:57
armarx::MetaEnum::name
std::string name
Definition: MetaEnum.h:48
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
armarx::CppEnumField::CppEnumField
CppEnumField(const std::string &name)
Definition: CppEnum.cpp:32
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::CppEnum::write
void write(const MetaWriterPtr &writer) override
Definition: CppEnum.cpp:66