中间件底层,websocket

SerializeStaticArray.hpp 2.1KB

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_SERIALIZESTATICARRAY_HPP
  18. #define INCLUDE_SF_SERIALIZESTATICARRAY_HPP
  19. #include <SF/Archive.hpp>
  20. namespace SF {
  21. // serialize C-style static arrays
  22. template<typename T, unsigned int N>
  23. inline void serializeFundamentalStaticArray(
  24. Archive & ar,
  25. T (*pt)[N])
  26. {
  27. serializeFundamental(ar, (*pt)[0], N);
  28. }
  29. template<typename T, unsigned int N>
  30. inline void serializeNonfundamentalStaticArray(
  31. Archive & ar,
  32. T (*pt)[N])
  33. {
  34. for (unsigned int i=0; i<N; i++)
  35. ar & (*pt)[i];
  36. }
  37. template<bool IsFundamental>
  38. class SerializeStaticArray;
  39. template<>
  40. class SerializeStaticArray<true>
  41. {
  42. public:
  43. template<typename T, unsigned int N>
  44. void operator()(Archive &ar, T (*pt)[N])
  45. {
  46. serializeFundamentalStaticArray(ar, pt);
  47. }
  48. };
  49. template<>
  50. class SerializeStaticArray<false>
  51. {
  52. public:
  53. template<typename T, unsigned int N>
  54. void operator()(Archive &ar, T (*pt)[N])
  55. {
  56. serializeNonfundamentalStaticArray(ar, pt);
  57. }
  58. };
  59. template<typename T, unsigned int N>
  60. inline void preserialize(SF::Archive &ar, T (*pt)[N], const unsigned int)
  61. {
  62. static const bool IsFundamental = RCF::IsFundamental<T>::value;
  63. SerializeStaticArray<IsFundamental>()(ar, pt);
  64. }
  65. } // namespace SF
  66. #endif // ! INCLUDE_SF_SERIALIZESTATICARRAY_HPP