array.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef __XIOS_CArray__
  2. #define __XIOS_CArray__
  3. /// boost headers ///
  4. #include <boost/cstdint.hpp>
  5. #include <boost/shared_ptr.hpp>
  6. #include <boost/multi_array.hpp>
  7. /// XIOS headers ///
  8. #include "xios_spl.hpp"
  9. #include "buffer_in.hpp"
  10. #include "buffer_out.hpp"
  11. namespace xios
  12. {
  13. template<size_t numDims>
  14. inline detail::multi_array::extent_gen<numDims> getExtentNull(void) { return getExtentNull<numDims-1>()[0];}
  15. template<>
  16. inline detail::multi_array::extent_gen<1> getExtentNull<1>(void) { return extents[0]; }
  17. /// ////////////////////// Déclarations ////////////////////// ///
  18. template <typename ValueType, StdSize NumDims, typename Allocator = std::allocator<ValueType> >
  19. class CArray : public boost::multi_array<ValueType, NumDims, Allocator>
  20. {
  21. /// Définition de type ///
  22. typedef boost::multi_array<ValueType, NumDims, Allocator> SuperClass;
  23. public:
  24. typedef ValueType ValType;
  25. /// Constructeurs ///
  26. // template <typename ExtentList>
  27. // explicit CArray(const ExtentList & sizes);
  28. template <typename ExtentList> CArray(const ExtentList & sizes)
  29. : boost::multi_array<ValueType, NumDims, Allocator>
  30. (sizes, boost::fortran_storage_order())
  31. { /* Ne rien faire de plus */ }
  32. explicit CArray();
  33. // template <typename ExtentList>
  34. // CArray(const ExtentList & sizes, const boost::general_storage_order<NumDims> & store);
  35. template <typename ExtentList> CArray(const ExtentList & sizes, const boost::general_storage_order<NumDims> & store)
  36. : boost::multi_array<ValueType, NumDims, Allocator> (sizes, store)
  37. { /* Ne rien faire de plus */ }
  38. CArray(const CArray & array); // NEVER IMPLEMENTED.
  39. CArray(const CArray * const array); // NEVER IMPLEMENTED.
  40. public:
  41. /// Flux ///
  42. template <typename U, StdSize V, typename W>
  43. friend StdOStream & operator <<
  44. (StdOStream & os, const CArray<U, V, W> & array);
  45. template <typename U, StdSize V, typename W>
  46. friend StdIStream & operator >>
  47. (StdIStream & is, CArray<U, V, W> & array);
  48. public:
  49. void toBinary (StdOStream & os) const;
  50. void fromBinary(StdIStream & is);
  51. size_t getSize(void) const ;
  52. bool toBuffer (CBufferOut& buffer) const;
  53. bool fromBuffer(CBufferIn& buffer);
  54. /// Destructeur ///
  55. virtual ~CArray(void);
  56. }; // class CArray
  57. ///---------------------------------------------------------------
  58. } // namespace xios
  59. //#include "array_impl.hpp"
  60. #include "array_mac.hpp"
  61. namespace xios
  62. {
  63. template <typename ValueType> void FromBinary(StdIStream & is, ARRAY(ValueType, 1) & array) ;
  64. template <typename ValueType> void FromBinary(StdIStream & is, ARRAY(ValueType, 2) & array) ;
  65. template <typename ValueType> void FromBinary(StdIStream & is, ARRAY(ValueType, 3) & array) ;
  66. }
  67. #endif // __XIOS_CArray__