CppBlock.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 <vector>
27 #include <string>
28 #include <memory>
29 #include "CppWriter.h"
30 #include <boost/format/format_fwd.hpp>
31 
32 namespace armarx
33 {
34  class CppBlock;
35  using CppBlockPtr = std::shared_ptr<CppBlock>;
36 
37  class CppBlockEntry;
38  using CppBlockEntryPtr = std::shared_ptr<CppBlockEntry>;
39 
41  {
42  public:
43  CppBlockEntry() = default;
44  virtual void writeCpp(const CppWriterPtr& writer) = 0;
45  virtual std::string getAsSingleLine() = 0;
46 
47  };
48 
50  virtual public CppBlockEntry
51  {
52  public:
53  CppBlockStringEntry(const std::string&);
54  virtual void writeCpp(const CppWriterPtr& writer) override;
55  virtual std::string getAsSingleLine() override;
56 
57  private:
58  std::string line;
59  };
60 
62  virtual public CppBlockEntry
63  {
64  public:
66  virtual void writeCpp(const CppWriterPtr& writer) override;
67  virtual std::string getAsSingleLine() override;
68 
69  private:
70  CppBlockPtr nestedBlock;
71  };
72 
73  class CppBlock
74  {
75  public:
76  CppBlock();
77 
78  void writeCpp(const CppWriterPtr& writer);
79  std::string getAsSingleLine();
80  void addLine(const std::string& line);
81  void addLine(const boost::basic_format<char>& line);
82 
83  size_t size() const;
84 
85  void addCommentLine(const std::string& line);
86  void addCommentLine(const boost::basic_format<char>& line);
87 
88  void addCommentLines(const std::vector<std::string>& lines);
89  void addCommentLines(const std::vector<boost::basic_format<char>>& lines);
90 
91  void addBlock(const CppBlockPtr& block);
92  void appendBlock(const CppBlockPtr& block);
93 
94  void addLineAsBlock(const std::string& line);
95 
96  static CppBlockPtr MergeBlocks(const CppBlockPtr& block1, const CppBlockPtr& block2);
97 
98  protected:
99  void addEntry(const CppBlockEntryPtr& entry);
100  std::vector<CppBlockEntryPtr> entries;
101  };
102 }
103 
armarx::CppBlockEntry::getAsSingleLine
virtual std::string getAsSingleLine()=0
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:35
armarx::CppBlockEntryPtr
std::shared_ptr< CppBlockEntry > CppBlockEntryPtr
Definition: CppBlock.h:38
CppWriter.h
armarx::CppBlock::getAsSingleLine
std::string getAsSingleLine()
Definition: CppBlock.cpp:76
armarx::CppBlock::size
size_t size() const
Definition: CppBlock.cpp:101
armarx::CppBlock
Definition: CppBlock.h:73
armarx::CppBlock::MergeBlocks
static CppBlockPtr MergeBlocks(const CppBlockPtr &block1, const CppBlockPtr &block2)
Definition: CppBlock.cpp:162
armarx::CppBlock::addEntry
void addEntry(const CppBlockEntryPtr &entry)
Definition: CppBlock.cpp:157
armarx::CppBlockEntry
Definition: CppBlock.h:40
armarx::CppBlock::addBlock
void addBlock(const CppBlockPtr &block)
Definition: CppBlock.cpp:136
armarx::CppBlockEntry::writeCpp
virtual void writeCpp(const CppWriterPtr &writer)=0
armarx::CppBlockBlockEntry::getAsSingleLine
virtual std::string getAsSingleLine() override
Definition: CppBlock.cpp:71
armarx::CppBlock::entries
std::vector< CppBlockEntryPtr > entries
Definition: CppBlock.h:100
armarx::CppBlock::CppBlock
CppBlock()
Definition: CppBlock.cpp:30
armarx::CppBlock::addCommentLine
void addCommentLine(const std::string &line)
Definition: CppBlock.cpp:106
armarx::CppBlockBlockEntry
Definition: CppBlock.h:61
armarx::CppBlock::addLine
void addLine(const std::string &line)
Definition: CppBlock.cpp:90
armarx::CppBlockStringEntry::getAsSingleLine
virtual std::string getAsSingleLine() override
Definition: CppBlock.cpp:66
armarx::CppBlockStringEntry
Definition: CppBlock.h:49
armarx::CppBlockStringEntry::CppBlockStringEntry
CppBlockStringEntry(const std::string &)
Definition: CppBlock.cpp:34
armarx::CppBlock::appendBlock
void appendBlock(const CppBlockPtr &block)
Definition: CppBlock.cpp:142
armarx::CppBlockBlockEntry::CppBlockBlockEntry
CppBlockBlockEntry(const CppBlockPtr &)
Definition: CppBlock.cpp:40
armarx::CppBlock::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppBlock.cpp:56
armarx::CppBlock::addLineAsBlock
void addLineAsBlock(const std::string &line)
Definition: CppBlock.cpp:150
armarx::CppBlockStringEntry::writeCpp
virtual void writeCpp(const CppWriterPtr &writer) override
Definition: CppBlock.cpp:46
armarx::CppBlockBlockEntry::writeCpp
virtual void writeCpp(const CppWriterPtr &writer) override
Definition: CppBlock.cpp:51
armarx::CppBlock::addCommentLines
void addCommentLines(const std::vector< std::string > &lines)
Definition: CppBlock.cpp:116
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::CppBlockEntry::CppBlockEntry
CppBlockEntry()=default