中间件底层,websocket

any.hpp 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_ANY_HPP
  18. #define INCLUDE_SF_ANY_HPP
  19. #include <string>
  20. #include <boost/any.hpp>
  21. #include <SF/string.hpp>
  22. #include <SF/Registry.hpp>
  23. #include <SF/SerializeAny.hpp>
  24. namespace SF {
  25. class Archive;
  26. inline void serialize(SF::Archive &ar, boost::any &a)
  27. {
  28. if ( ar.isWrite() )
  29. {
  30. std::string which =
  31. SF::Registry::getSingleton().getTypeName(a.type());
  32. if ( which.empty() && !a.empty() )
  33. {
  34. RCF_THROW(RCF::Exception(RCF::RcfError_AnyTypeNotRegistered, a.type().name()));
  35. }
  36. ar & which;
  37. if ( !a.empty() )
  38. {
  39. RCF_ASSERT(which.size() > 0);
  40. SF::I_SerializerAny * serializerAny = SF::Registry::getSingleton().getAnySerializer(which);
  41. if ( serializerAny )
  42. {
  43. serializerAny->serialize(ar, a);
  44. }
  45. }
  46. }
  47. else
  48. {
  49. std::string which;
  50. ar & which;
  51. if ( which.empty() )
  52. {
  53. a = boost::any();
  54. }
  55. else
  56. {
  57. SF::I_SerializerAny * serializerAny = SF::Registry::getSingleton().getAnySerializer(which);
  58. if ( serializerAny )
  59. {
  60. serializerAny->serialize(ar, a);
  61. }
  62. }
  63. }
  64. }
  65. } // namespace SF
  66. #endif // ! INCLUDE_SF_ANY_HPP