PObject.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact: http://www.digitalbarriers.com/
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
10 
15 #pragma once
16 #include <PapillonCommon.h>
17 #include <PRtti.h>
18 
19 PAPILLON_BEGIN_NAMESPACE
20 
21 class PObjectImpl;
22 class PByteArray;
23 
27 class PAPILLON_API_CORE PObject
28 {
29 public:
33  PObject();
34 
38  PObject(const PObject& obj) { m_pimpl = obj.m_pimpl; }
39 
45  PObject& operator=(const PObject& obj) { m_pimpl = obj.m_pimpl; return *this; }
46 
50  virtual ~PObject();
51 
55  bool IsNullReference() const;
56 
60  classid GetClassId() const;
61 
66  PResult CastTo(PObject& obj);
67 
72  PResult CastTo(PObject& obj) const;
73 
89  papillon::uint32 GetHashCode() const;
90 
94  bool IsSerialisable() const;
95 
99  bool IsSame(const PObject &obj) const;
100 
101 
108  PResult Write(PByteStream& os, ESerialisationFormat format = papillon::E_BINARY_FORMAT) const;
109 
118  PResult Read(PByteStream& is, ESerialisationFormat format = papillon::E_BINARY_FORMAT);
119 
126  PObject ReadObject(PByteStream& is, PResult& result) const;
127 
132  PResult FromString(const PString& s);
133 
137  PString ToString() const;
138 
142  PByteArray ToByteArray() const;
143 
147  PString ToBase64() const;
148 
155  PResult FromBase64(const PString& base64representation);
156 
160  PString DebugInternalPointer() const;
161 
165  papillon::uint32 DebugCounter() const;
166 
172  void Swap(PObject& other);
173 
177  bool Equal(const PObject& e) const;
178 
182  friend PAPILLON_API_CORE std::ostream& operator<<(std::ostream& os, const PObject& obj);
183 
184 protected:
185  friend class PObjectImpl;
186 #ifdef _MSC_VER
187 # pragma warning(push)
188 # pragma warning(disable: 4251)
189 #endif
190  mutable std::shared_ptr<PObjectImpl> m_pimpl;
191 #ifdef _MSC_VER
192 # pragma warning(pop)
193 #endif
194  /*
195  * Access to shared pointer to implementation
196  */
197  template <typename T>
198  std::shared_ptr<const T> ObjPimpl() const {return std::const_pointer_cast<const T>(m_pimpl);}
199 
200  template <typename T>
201  std::shared_ptr<T> ObjPimpl() {return std::dynamic_pointer_cast<T>(m_pimpl);}
202 
203  /*
204  * Fast Access to shared pointer to implementation without type check (extra care should be taken)
205  */
206  template <typename T>
207  std::shared_ptr<T> ObjPimplS() {return std::static_pointer_cast<T>(m_pimpl);}
208 
209  /*
210  * Access implementation object
211  */
212  template <typename T>
213  const T& ObjImpl() const {return *(dynamic_cast<T*>(m_pimpl.get()));}
214  template <typename T>
215  T& ObjImpl() {return *(dynamic_cast<T*>(m_pimpl.get()));}
216 
217  /*
218  * Fast access of implementation without type check (extra care should be taken)
219  */
220  template <typename T>
221  const T& ObjImplS() const {return *(static_cast<T*>(m_pimpl.get()));}
222  template <typename T>
223  T& ObjImplS() {return *(static_cast<T*>(m_pimpl.get()));}
224 };
225 
227 
228 PAPILLON_END_NAMESPACE
T & ObjImpl()
Definition: PObject.h:215
The PString class provides an Unicode character strings.
Definition: PString.h:38
const PLogStream & operator<<(const PLogStream &os, void *ptr)
Definition: PLog.h:279
The PResult class represents the result returned by most of Papillon functions; this class is used to...
Definition: PResult.h:159
Papillon Run-Time Type Information.
The PByteArray class represents a resizable array of bytes.
Definition: PByteArray.h:40
std::shared_ptr< T > ObjPimplS()
Definition: PObject.h:207
std::shared_ptr< T > ObjPimpl()
Definition: PObject.h:201
std::shared_ptr< PObjectImpl > m_pimpl
Definition: PObject.h:190
The PObject class is the root class of all Papillon classes; all PObject behaves like shared referenc...
Definition: PObject.h:27
std::shared_ptr< const T > ObjPimpl() const
Definition: PObject.h:198
PString ToString(const T &t)
Definition: PString.h:788
The PByteStream class is a generic byte stream (can be a memory stream or a file stream).
Definition: PByteStream.h:69
T & ObjImplS()
Definition: PObject.h:223
PObject & operator=(const PObject &obj)
Performs a shared copy of other to this object.
Definition: PObject.h:45
PObject(const PObject &obj)
Constructs a shared copy of other.
Definition: PObject.h:38
PAPILLON_BEGIN_NAMESPACE typedef uint16_t classid
Definition: PRtti.h:21
const T & ObjImplS() const
Definition: PObject.h:221
const T & ObjImpl() const
Definition: PObject.h:213