中间件底层,websocket

SerializeAny.hpp 1.4KB

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_SERIALIZEANY_HPP
  18. #define INCLUDE_SF_SERIALIZEANY_HPP
  19. #include <boost/any.hpp>
  20. namespace SF {
  21. class Archive;
  22. class I_SerializerAny
  23. {
  24. public:
  25. virtual ~I_SerializerAny()
  26. {}
  27. virtual void serialize(
  28. SF::Archive &ar,
  29. boost::any &a) = 0;
  30. };
  31. template<typename T>
  32. class SerializerAny : public I_SerializerAny
  33. {
  34. public:
  35. void serialize(SF::Archive &ar, boost::any &a);
  36. };
  37. } // namespace SF
  38. #include <SF/Archive.hpp>
  39. namespace SF {
  40. template<typename T>
  41. void SerializerAny<T>::serialize(SF::Archive &ar, boost::any &a)
  42. {
  43. if (ar.isWrite())
  44. {
  45. ar & boost::any_cast<T>(a);
  46. }
  47. else
  48. {
  49. T t;
  50. ar & t;
  51. a = t;
  52. }
  53. }
  54. } // namespace SF
  55. #endif // ! INCLUDE_SF_SERIALIZEANY_HPP