Remote Call Framework 3.0
DataPtr.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_SF_DATAPTR_HPP
20 #define INCLUDE_SF_DATAPTR_HPP
21 
22 #include <string>
23 
24 #include <RCF/Export.hpp>
25 
26 #include <SF/PortableTypes.hpp>
27 
28 namespace SF {
29 
30  //************************************************************************
31  // DataPtr class holds a pointer to a buffer of data. It includes an internal
32  // buffer in order to avoid dynamic memory allocation for small buffer sizes, < 64bytes.
33 
34  class RCF_EXPORT DataPtr
35  {
36  private:
37  typedef Byte8 T;
38  public:
39  DataPtr();
40  DataPtr(const T *sz);
41  DataPtr(const T *sz, UInt32 length);
42  DataPtr(const DataPtr &rhs);
43  DataPtr &operator=(const DataPtr &rhs);
44  ~DataPtr();
45 
46  void assign(const T *sz, UInt32 length);
47  void assign(const T *sz);
48  void assign(const std::string &s);
49 
50  void release();
51  UInt32 allocate(UInt32 length);
52  T *get() const;
53  UInt32 length() const;
54  bool empty() const;
55  std::string cpp_str() const;
56 
57  private:
58  T *ptr_;
59  UInt32 length_;
60  UInt32 allocatedLength_;
61  int whichDeleter_;
62  void (*pfn_deleter_)(T *);
63  T buffer_[64];
64  UInt32 length(const T *sz);
65  };
66 
67 } // namespace SF
68 
69 #endif // ! INCLUDE_SF_DATAPTR_HPP
Definition: ByteBuffer.hpp:189