Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
Value.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_VALUE_H
6#define ICE_VALUE_H
7
8#ifdef ICE_CPP11_MAPPING // C++11 mapping
9
10#include <Ice/ValueF.h>
11#include <Ice/SlicedDataF.h>
12
13#include <Ice/OutputStream.h>
14#include <Ice/InputStream.h>
15
16namespace Ice
17{
18
24{
25public:
26
27 // See "Rule of zero" at http://en.cppreference.com/w/cpp/language/rule_of_three
28 // The virtual dtor is actually not stricly necessary since Values are always stored
29 // in std::shared_ptr
30
31 Value() = default;
32 Value(const Value&) = default;
33 Value(Value&&) = default;
34 Value& operator=(const Value&) = default;
35 Value& operator=(Value&&) = default;
36 virtual ~Value() = default;
37
42 virtual void ice_preMarshal();
43
48 virtual void ice_postUnmarshal();
49
54 virtual std::string ice_id() const;
55
60 static const std::string& ice_staticId();
61
66 std::shared_ptr<Value> ice_clone() const;
67
73 virtual std::shared_ptr<SlicedData> ice_getSlicedData() const;
74
76 virtual void _iceWrite(Ice::OutputStream*) const;
77 virtual void _iceRead(Ice::InputStream*);
79
80protected:
81
83 virtual std::shared_ptr<Value> _iceCloneImpl() const = 0;
85
87 virtual void _iceWriteImpl(Ice::OutputStream*) const {}
88 virtual void _iceReadImpl(Ice::InputStream*) {}
90};
91
93template<typename T, typename Base> class ValueHelper : public Base
94{
95public:
96
97 using Base::Base;
98
99 ValueHelper() = default;
100
101 std::shared_ptr<T> ice_clone() const
102 {
103 return std::static_pointer_cast<T>(_iceCloneImpl());
104 }
105
106 virtual std::string ice_id() const override
107 {
108 return T::ice_staticId();
109 }
110
111protected:
112
113 virtual std::shared_ptr<Value> _iceCloneImpl() const override
114 {
115 return std::make_shared<T>(static_cast<const T&>(*this));
116 }
117
118 virtual void _iceWriteImpl(Ice::OutputStream* os) const override
119 {
120 os->startSlice(T::ice_staticId(), -1, std::is_same<Base, Ice::Value>::value ? true : false);
121 Ice::StreamWriter<T, Ice::OutputStream>::write(os, static_cast<const T&>(*this));
122 os->endSlice();
123 Base::_iceWriteImpl(os);
124 }
125
126 virtual void _iceReadImpl(Ice::InputStream* is) override
127 {
128 is->startSlice();
129 Ice::StreamReader<T, Ice::InputStream>::read(is, static_cast<T&>(*this));
130 is->endSlice();
131 Base::_iceReadImpl(is);
132 }
133};
135
136}
137#endif // C++11 mapping end
138
139#endif
#define ICE_API
Definition Config.h:197
Interface for input streams used to extract Slice types from a sequence of bytes.
Definition InputStream.h:50
std::string startSlice()
Reads the start of a value or exception slice.
Definition InputStream.h:547
void endSlice()
Indicates that the end of a value or exception slice has been reached.
Definition InputStream.h:556
Interface for output streams used to create a sequence of bytes from Slice types.
Definition OutputStream.h:28
void startSlice(const std::string &typeId, int compactId, bool last)
Writes the start of a value or exception slice.
Definition OutputStream.h:285
void endSlice()
Marks the end of a value or exception slice.
Definition OutputStream.h:294
Value(const Value &)=default
Value()=default
virtual std::shared_ptr< SlicedData > ice_getSlicedData() const
Obtains the sliced data associated with this instance.
virtual ~Value()=default
static const std::string & ice_staticId()
Obtains the Slice type ID of this type.
virtual void ice_preMarshal()
The Ice run time invokes this method prior to marshaling an object's data members.
Value & operator=(const Value &)=default
virtual std::string ice_id() const
Obtains the Slice type ID of the most-derived class supported by this object.
Value & operator=(Value &&)=default
std::shared_ptr< Value > ice_clone() const
Returns a shallow copy of the object.
Value(Value &&)=default
virtual void ice_postUnmarshal()
The Ice run time invokes this method after unmarshaling an object's data members.
Definition BuiltinSequences.h:56