AronDTOWriter.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25// STD/STL
26#include <map>
27#include <optional>
28#include <string>
29#include <vector>
30
31// ArmarX
33
35{
36 /**
37 * @brief Writes the ice representation (data::dto::*) directly.
38 *
39 * VariantWriter builds a full navigator graph -- a Variant object, its Path and its
40 * children container per node -- and populates the ice objects alongside it. Code that
41 * only wants the ice representation, which is everything that sends data to a memory
42 * server, pays for that graph and then throws it away.
43 *
44 * This writer emits the ice objects and nothing else. It is the writer behind
45 * AronGeneratedObject::toAronDTO().
46 *
47 * The Path arguments are accepted to satisfy the writer interface and are ignored:
48 * paths exist for navigation and error reporting on the variant representation, and
49 * the ice objects carry no path.
50 */
51 class AronDTOWriter : public WriterInterface<data::dto::GenericDataPtr>
52 {
53 public:
54 AronDTOWriter() = default;
55
57
58 data::dto::GenericDataPtr writeList(const std::vector<data::dto::GenericDataPtr>& elements,
59 const Path& p = Path()) override;
60
61 data::dto::GenericDataPtr
62 writeDict(const std::map<std::string, data::dto::GenericDataPtr>& elements,
63 const std::optional<data::dto::GenericDataPtr>& extends = std::nullopt,
64 const Path& p = Path()) override;
65
66 /// Takes ownership of `elements` instead of copying it into the dict.
67 data::dto::GenericDataPtr
68 writeDict(std::map<std::string, data::dto::GenericDataPtr>&& elements,
69 const std::optional<data::dto::GenericDataPtr>& extends,
70 const Path& p) override;
71
72 data::dto::GenericDataPtr writeNDArray(const std::vector<int>& shape,
73 const std::string& typeAsString,
74 const unsigned char* data,
75 const Path& p = Path()) override;
76
77 data::dto::GenericDataPtr writeInt(const int i, const Path& p = Path()) override;
78 data::dto::GenericDataPtr writeLong(const long i, const Path& p = Path()) override;
79 data::dto::GenericDataPtr writeFloat(const float i, const Path& p = Path()) override;
80 data::dto::GenericDataPtr writeDouble(const double i, const Path& p = Path()) override;
81 data::dto::GenericDataPtr writeString(const std::string& i,
82 const Path& p = Path()) override;
83 data::dto::GenericDataPtr writeBool(const bool i, const Path& p = Path()) override;
84
85 using WriterInterface<data::dto::GenericDataPtr>::writeDict;
86
87 /// Narrow the generic result of write() to a dict, throwing if it is not one.
88 ///
89 /// The variant representation offers this as Dict::DynamicCastAndCheck; the ice
90 /// classes have no such helper, and generated code needs one to type its
91 /// toAronDTO() return value.
92 static data::dto::DictPtr DictCastAndCheck(const data::dto::GenericDataPtr& data);
93
94 /// As DictCastAndCheck(), for generated int enums.
95 static data::dto::AronIntPtr IntCastAndCheck(const data::dto::GenericDataPtr& data);
96 };
97} // namespace armarx::aron::data::writer
The Path class.
Definition Path.h:36
typename std::add_const< ReturnType >::type ReturnTypeConst
Definition Writer.h:45
data::dto::GenericDataPtr writeInt(const int i, const Path &p=Path()) override
data::dto::GenericDataPtr writeString(const std::string &i, const Path &p=Path()) override
data::dto::GenericDataPtr writeDict(const std::map< std::string, data::dto::GenericDataPtr > &elements, const std::optional< data::dto::GenericDataPtr > &extends=std::nullopt, const Path &p=Path()) override
static data::dto::DictPtr DictCastAndCheck(const data::dto::GenericDataPtr &data)
Narrow the generic result of write() to a dict, throwing if it is not one.
data::dto::GenericDataPtr writeBool(const bool i, const Path &p=Path()) override
data::dto::GenericDataPtr writeFloat(const float i, const Path &p=Path()) override
data::dto::GenericDataPtr writeLong(const long i, const Path &p=Path()) override
data::dto::GenericDataPtr writeDouble(const double i, const Path &p=Path()) override
static data::dto::AronIntPtr IntCastAndCheck(const data::dto::GenericDataPtr &data)
As DictCastAndCheck(), for generated int enums.
data::Descriptor getDescriptor(ReturnTypeConst &input) final
data::dto::GenericDataPtr writeNDArray(const std::vector< int > &shape, const std::string &typeAsString, const unsigned char *data, const Path &p=Path()) override
data::dto::GenericDataPtr writeList(const std::vector< data::dto::GenericDataPtr > &elements, const Path &p=Path()) override
::IceInternal::Handle< Dict > DictPtr
Definition Commit.h:18
A convenience header to include all aron files (full include, not forward declared)