Ice 3.7 C++11 API Reference
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 
16 namespace Ice
17 {
18 
24 {
25 public:
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 
80 protected:
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 
93 template<typename T, typename Base> class ValueHelper : public Base
94 {
95 public:
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 
111 protected:
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
Ice::InputStream::startSlice
std::string startSlice()
Reads the start of a value or exception slice.
Definition: InputStream.h:547
Ice::Value::ice_clone
std::shared_ptr< Value > ice_clone() const
Returns a shallow copy of the object.
Ice::Value::operator=
Value & operator=(const Value &)=default
Ice::InputStream
Interface for input streams used to extract Slice types from a sequence of bytes.
Definition: InputStream.h:50
Ice::OutputStream::endSlice
void endSlice()
Marks the end of a value or exception slice.
Definition: OutputStream.h:294
Ice::Value::~Value
virtual ~Value()=default
OutputStream.h
Ice::InputStream::endSlice
void endSlice()
Indicates that the end of a value or exception slice has been reached.
Definition: InputStream.h:556
Ice::Value::Value
Value(const Value &)=default
ICE_API
#define ICE_API
Definition: Config.h:197
Ice::Value
The base class for instances of Slice classes.
Definition: Value.h:24
Ice::Value::Value
Value()=default
Ice::Value::Value
Value(Value &&)=default
SlicedDataF.h
Ice::Value::ice_preMarshal
virtual void ice_preMarshal()
The Ice run time invokes this method prior to marshaling an object's data members.
Ice::Value::ice_id
virtual std::string ice_id() const
Obtains the Slice type ID of the most-derived class supported by this object.
Ice::OutputStream
Interface for output streams used to create a sequence of bytes from Slice types.
Definition: OutputStream.h:28
Ice::Value::ice_postUnmarshal
virtual void ice_postUnmarshal()
The Ice run time invokes this method after unmarshaling an object's data members.
Ice::OutputStream::startSlice
void startSlice(const std::string &typeId, int compactId, bool last)
Writes the start of a value or exception slice.
Definition: OutputStream.h:285
Ice
Definition: BuiltinSequences.h:56
Ice::Value::operator=
Value & operator=(Value &&)=default
Ice::Value::ice_staticId
static const std::string & ice_staticId()
Obtains the Slice type ID of this type.
InputStream.h
Ice::Value::ice_getSlicedData
virtual std::shared_ptr< SlicedData > ice_getSlicedData() const
Obtains the sliced data associated with this instance.
ValueF.h