CppBlock.cpp
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 #include "CppBlock.h"
25 
26 #include <boost/format.hpp>
27 
28 using namespace armarx;
29 
31 {
32 }
33 
34 CppBlockStringEntry::CppBlockStringEntry(const std::string& s) : line(s)
35 {
36 }
37 
39 {
40 }
41 
42 void
44 {
45  writer->body.line(line);
46 }
47 
48 void
50 {
51  nestedBlock->writeCpp(writer);
52 }
53 
54 void
56 {
57  writer->body.startBlock();
58  for (const auto& entry : entries)
59  {
60  entry->writeCpp(writer);
61  }
62  writer->body.endBlock();
63 }
64 
65 std::string
67 {
68  return line;
69 }
70 
71 std::string
73 {
74  return nestedBlock->getAsSingleLine();
75 }
76 
77 std::string
79 {
80  std::stringstream ss;
81  ss << "{ ";
82 
83  for (const auto& entry : entries)
84  {
85  ss << entry->getAsSingleLine() << " ";
86  }
87 
88  ss << "}";
89  return ss.str();
90 }
91 
92 void
93 CppBlock::addLine(const std::string& line)
94 {
96  entries.push_back(t);
97 }
98 
99 void
100 CppBlock::addLine(const boost::basic_format<char>& line)
101 {
102  addLine(boost::str(line));
103 }
104 
105 size_t
107 {
108  return entries.size();
109 }
110 
111 void
112 CppBlock::addCommentLine(const std::string& line)
113 {
114  addLine("//" + line);
115 }
116 
117 void
118 CppBlock::addCommentLine(const boost::basic_format<char>& line)
119 {
120  addLine("//" + boost::str(line));
121 }
122 
123 void
124 CppBlock::addCommentLines(const std::vector<std::string>& lines)
125 {
126  addLine("/*");
127  for (const auto& line : lines)
128  {
129  addLine(" * " + line);
130  }
131  addLine(" */");
132 }
133 
134 void
135 CppBlock::addCommentLines(const std::vector<boost::basic_format<char>>& lines)
136 {
137  addLine("/*");
138  for (const auto& line : lines)
139  {
140  addLine(" * " + boost::str(line));
141  }
142  addLine(" */");
143 }
144 
145 void
147 {
149  entries.push_back(t);
150 }
151 
152 void
154 {
155  for (const auto& entry : block->entries)
156  {
157  addEntry(entry);
158  }
159 }
160 
161 void
162 CppBlock::addLineAsBlock(const std::string& line)
163 {
164  CppBlockPtr b = std::make_shared<CppBlock>();
165  b->addLine(line);
166  this->addBlock(b);
167 }
168 
169 void
171 {
172  entries.push_back(entry);
173 }
174 
176 CppBlock::MergeBlocks(const CppBlockPtr& block1, const CppBlockPtr& block2)
177 {
179  for (const auto& entry : block1->entries)
180  {
181  ret->addEntry(entry);
182  }
183 
184  for (const auto& entry : block2->entries)
185  {
186  ret->addEntry(entry);
187  }
188  return ret;
189 }
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:43
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
CppBlock.h
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:37
armarx::CppBlockEntryPtr
std::shared_ptr< CppBlockEntry > CppBlockEntryPtr
Definition: CppBlock.h:40
armarx::CppBlock::getAsSingleLine
std::string getAsSingleLine()
Definition: CppBlock.cpp:78
armarx::CppBlock::size
size_t size() const
Definition: CppBlock.cpp:106
armarx::CppBlock::MergeBlocks
static CppBlockPtr MergeBlocks(const CppBlockPtr &block1, const CppBlockPtr &block2)
Definition: CppBlock.cpp:176
armarx::CppBlock::addEntry
void addEntry(const CppBlockEntryPtr &entry)
Definition: CppBlock.cpp:170
armarx::CppBlock::addBlock
void addBlock(const CppBlockPtr &block)
Definition: CppBlock.cpp:146
armarx::CppBlockBlockEntry::getAsSingleLine
virtual std::string getAsSingleLine() override
Definition: CppBlock.cpp:72
armarx::CppBlock::entries
std::vector< CppBlockEntryPtr > entries
Definition: CppBlock.h:99
armarx::CppBlock::CppBlock
CppBlock()
Definition: CppBlock.cpp:30
armarx::CppBlockBlockEntry
Definition: CppBlock.h:61
armarx::CppBlock::addCommentLine
void addCommentLine(const std::string &line)
Definition: CppBlock.cpp:112
armarx::CppBlock::addLine
void addLine(const std::string &line)
Definition: CppBlock.cpp:93
armarx::CppBlockStringEntry::getAsSingleLine
virtual std::string getAsSingleLine() override
Definition: CppBlock.cpp:66
armarx::CppBlockStringEntry
Definition: CppBlock.h:50
armarx::CppBlockStringEntry::CppBlockStringEntry
CppBlockStringEntry(const std::string &)
Definition: CppBlock.cpp:34
armarx::CppBlock::appendBlock
void appendBlock(const CppBlockPtr &block)
Definition: CppBlock.cpp:153
armarx::CppBlockBlockEntry::CppBlockBlockEntry
CppBlockBlockEntry(const CppBlockPtr &)
Definition: CppBlock.cpp:38
armarx::CppBlock::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppBlock.cpp:55
armarx::CppBlock::addLineAsBlock
void addLineAsBlock(const std::string &line)
Definition: CppBlock.cpp:162
armarx::CppBlockStringEntry::writeCpp
virtual void writeCpp(const CppWriterPtr &writer) override
Definition: CppBlock.cpp:43
armarx::CppBlockBlockEntry::writeCpp
virtual void writeCpp(const CppWriterPtr &writer) override
Definition: CppBlock.cpp:49
armarx::CppBlock::addCommentLines
void addCommentLines(const std::vector< std::string > &lines)
Definition: CppBlock.cpp:124
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27