中间件底层,websocket

DataPtr.hpp 1.8KB

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