DoxDoc.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 "DoxDoc.h"
25 
26 #include <SimoxUtility/algorithm/string/string_tools.h>
27 
30 
31 #include "DoxLine.h"
32 #include "DoxTable.h"
33 #include "DoxTransitiongraph.h"
34 
35 
36 using namespace armarx;
37 
39 {
40 }
41 
42 void
44 {
45  entries.push_back(entry);
46 }
47 
48 void
50 {
51  addLine("");
52 }
53 
54 void
56 {
57  writer->body.line("/**");
58 
59  for (DoxEntryPtr entry : entries)
60  {
61  std::string doc = entry->getDoxString();
62  std::string delimiters = "\n";
63  std::vector<std::string> doclines = simox::alg::split(doc, delimiters);
64 
65  for (std::string line : doclines)
66  {
67  writer->body.line(" * " + line);
68  }
69  }
70 
71  writer->body.line("*/");
72 }
73 
74 void
75 armarx::DoxDoc::addLine(const std::string& line)
76 {
77  DoxEntryPtr entry(new DoxLine(line));
78  addEntry(entry);
79 }
80 
81 void
83  VariantInfoPtr variantInfo,
84  Ice::CommunicatorPtr communicator)
85 {
86  std::vector<std::string> header;
87  header.push_back("Name");
88  header.push_back("Type");
89  header.push_back("Default value");
90  header.push_back("Description");
91 
92  DoxTablePtr table = DoxTablePtr(new DoxTable(header));
93 
94 
95  for (RapidXmlReaderNode parameter : parameters.nodes())
96  {
97  std::vector<std::string> row;
98  row.push_back(parameter.attribute_value("name"));
99  std::string nestedType = parameter.attribute_value("type");
100 
101  if (variantInfo->getNestedHumanNameFromBaseName(nestedType).compare("") != 0)
102  {
103  row.push_back(variantInfo->getNestedHumanNameFromBaseName(nestedType));
104  }
105  else
106  {
107  row.push_back(nestedType);
108  }
109 
110  JSONObjectPtr jsonObject = new JSONObject(communicator);
111  std::string defaultValue = parameter.attribute_value_or_default("default", "");
112 
113  if (defaultValue.size() > 0)
114  {
115  try
116  {
117  jsonObject->fromString(defaultValue);
118  SerializablePtr obj = jsonObject->deserializeIceObject();
119  VariantContainerBasePtr result = VariantContainerBasePtr::dynamicCast(obj);
120  std::string resultString = result->toString();
121  resultString = simox::alg::replace_all(resultString, "\n", "<br>");
122  row.push_back(resultString);
123  }
124  catch (Ice::Exception& e)
125  {
126  ARMARX_WARNING_S << "Cannot deserialize defaultValue of parameter "
127  << parameter.attribute_value("name") << ": \"" << defaultValue
128  << "\"\n"
129  << e.ice_id() << ":\n"
130  << e.what() << "\n"
131  << e.ice_stackTrace();
132  row.push_back(" ");
133  }
134  }
135  else
136  {
137  row.push_back(" ");
138  }
139 
140  row.push_back(parameter.attribute_value_or_default("description", " "));
141 
142  table->addRow(row);
143  }
144 
145  addEntry(table);
146 }
147 
148 void
150 {
152 
153  for (RapidXmlReaderNode transition : transitions.nodes())
154  {
155  if (transition.has_attribute("from") && transition.has_attribute("to") &&
156  transition.has_attribute("eventName"))
157  {
158  graph->addTransition(
159  DoxTransitionPtr(new DoxTransition(transition.attribute_value("from"),
160  transition.attribute_value("to"),
161  transition.attribute_value("eventName"))));
162  }
163  }
164 
165  addEntry(graph);
166 }
armarx::DoxTransitionGraphPtr
std::shared_ptr< DoxTransitionGraph > DoxTransitionGraphPtr
Definition: DoxTransitiongraph.h:66
armarx::DoxLine
Definition: DoxLine.h:38
DoxTable.h
JSONObject.h
armarx::DoxDoc::addEntry
void addEntry(DoxEntryPtr entry)
Definition: DoxDoc.cpp:43
armarx::DoxDoc::addLine
void addLine()
Definition: DoxDoc.cpp:49
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
DoxTransitiongraph.h
armarx::DoxTable
Definition: DoxTable.h:37
armarx::DoxTablePtr
std::shared_ptr< DoxTable > DoxTablePtr
Definition: DoxTable.h:35
armarx::DoxEntryPtr
std::shared_ptr< DoxEntry > DoxEntryPtr
Definition: DoxEntry.h:32
IceInternal::Handle<::Ice::Communicator >
DoxLine.h
armarx::DoxDoc::DoxDoc
DoxDoc()
Definition: DoxDoc.cpp:38
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:69
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
armarx::DoxTransitionGraph
Definition: DoxTransitiongraph.h:68
DoxDoc.h
armarx::DoxDoc::addParameterTable
void addParameterTable(const RapidXmlReaderNode &parameters, VariantInfoPtr variantInfo, Ice::CommunicatorPtr communicator)
Definition: DoxDoc.cpp:82
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::RapidXmlReaderNode::nodes
std::vector< RapidXmlReaderNode > nodes(const char *name=nullptr) const
Definition: RapidXmlReader.h:181
armarx::DoxDoc::writeDoc
void writeDoc(CppWriterPtr writer)
Definition: DoxDoc.cpp:55
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
Logging.h
armarx::DoxDoc::addTransitionGraph
void addTransitionGraph(const RapidXmlReaderNode &transitions)
Definition: DoxDoc.cpp:149
armarx::DoxTransitionPtr
std::shared_ptr< DoxTransition > DoxTransitionPtr
Definition: DoxTransitiongraph.h:36
armarx::DoxTransition
Definition: DoxTransitiongraph.h:38
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38