home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / valimp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  6.4 KB  |  252 lines

  1. #ifndef __VALIMP_H
  2. #define __VALIMP_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __RW_VALIMP__
  6. #define __RW_VALIMP__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * valimp - Declarations for the Standard Library valarray
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  15.  *
  16.  * This computer software is owned by Rogue Wave Software, Inc. and is
  17.  * protected by U.S. copyright laws and other laws and by international
  18.  * treaties.  This computer software is furnished by Rogue Wave Software,
  19.  * Inc. pursuant to a written license agreement and may be used, copied,
  20.  * transmitted, and stored only in accordance with the terms of such
  21.  * license and with the inclusion of the above copyright notice.  This
  22.  * computer software or any other copies thereof may not be provided or
  23.  * otherwise made available to any other person.
  24.  *
  25.  * U.S. Government Restricted Rights.  This computer software is provided
  26.  * with Restricted Rights.  Use, duplication, or disclosure by the
  27.  * Government is subject to restrictions as set forth in subparagraph (c)
  28.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  29.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  30.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  31.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  32.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  33.  *
  34.  **************************************************************************/
  35.  
  36. #include <stdcomp.h>
  37. #include <rw/stddefs.h> 
  38.  
  39. #ifndef _RWSTD_NO_NEW_HEADER
  40. #include <cstddef>
  41. #include <cstring>
  42. #else
  43. #include <stddef.h>
  44. #include <string.h>
  45. #endif
  46.  
  47. #include <rw/math.h>
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std { }
  51. namespace __rwstd {
  52. #define _RW_IMP_SPACE(name) ::__rwstd::name
  53. #else
  54. #define _RW_IMP_SPACE(name) name
  55. #endif
  56. /****************************************************************
  57.  *               IMPLEMENTATION FUNCTIONALITIES                  *
  58.  *                                                               *
  59.  *   - valarray memory model                                     *
  60.  *   - valarray optimization on copy and return                  *
  61.  *                                                               *
  62.  ****************************************************************/
  63. // valarray_traits class
  64. // allow memory optimization 
  65. // for builtin types and user types
  66.  
  67.   template <class T> 
  68.   class  valarray_traits_optimize 
  69.   {
  70.   public:
  71.     static bool _RWSTDExportTemplate optimize_copy() { return false; }
  72.   };
  73. #ifndef _RWSTD_NO_BOOL
  74.   _RWSTD_TEMPLATE
  75.   class _RWSTDExport valarray_traits_optimize<bool>
  76.   {
  77.   public:
  78.     static bool optimize_copy() { return true; }
  79.   };
  80. #endif
  81.  
  82.   _RWSTD_TEMPLATE
  83.   class _RWSTDExport valarray_traits_optimize<short>
  84.   {
  85.   public:
  86.     static bool optimize_copy() { return true; }
  87.   };
  88.  
  89.   _RWSTD_TEMPLATE
  90.   class _RWSTDExport valarray_traits_optimize<unsigned short>
  91.   {
  92.   public:
  93.     static bool optimize_copy() { return true; }
  94.   };
  95.  
  96.   _RWSTD_TEMPLATE
  97.   class _RWSTDExport valarray_traits_optimize<int>
  98.   {
  99.   public:
  100.     static bool optimize_copy() { return true; }
  101.   };
  102.  
  103.   _RWSTD_TEMPLATE
  104.   class _RWSTDExport valarray_traits_optimize<unsigned int>
  105.   {
  106.   public:
  107.     static bool optimize_copy() { return true; }
  108.   };
  109.  
  110.   _RWSTD_TEMPLATE
  111.   class _RWSTDExport valarray_traits_optimize<long>
  112.   {
  113.   public:
  114.     static bool optimize_copy() { return true; }
  115.   };
  116.  
  117.   _RWSTD_TEMPLATE
  118.   class _RWSTDExport valarray_traits_optimize<unsigned long>
  119.   {
  120.   public:
  121.     static bool optimize_copy() { return true; }
  122.   };
  123.  
  124.   _RWSTD_TEMPLATE
  125.   class _RWSTDExport valarray_traits_optimize<float>
  126.   {
  127.   public:
  128.     static bool optimize_copy() { return true; }
  129.   };
  130.  
  131.   _RWSTD_TEMPLATE
  132.   class _RWSTDExport valarray_traits_optimize<double>
  133.   {
  134.   public:
  135.     static bool optimize_copy() { return true; }
  136.   };
  137.  
  138.   _RWSTD_TEMPLATE
  139.   class _RWSTDExport valarray_traits_optimize<long double>
  140.   {
  141.   public:
  142.     static bool optimize_copy() { return true; }
  143.   };
  144.  
  145.   _RWSTD_TEMPLATE
  146.   class _RWSTDExport valarray_traits_optimize<char>
  147.   {
  148.   public:
  149.     static bool optimize_copy() { return true; }
  150.   };
  151.  
  152.   _RWSTD_TEMPLATE
  153.   class _RWSTDExport valarray_traits_optimize<unsigned char>
  154.   {
  155.   public:
  156.     static bool optimize_copy() { return true; }
  157.   };
  158. // for optimization on return of
  159. // valarray<T> values
  160.  
  161.   template <class T>
  162.   struct _RW_temporary 
  163.   {
  164.  
  165.     T*      store_adr;
  166.     size_t  length;
  167.   };
  168. // Class _RW_array<T>
  169. // C type array storage class
  170. // responsible for physical representation
  171. // of the valarray in memory and memory operations
  172.  
  173.   template <class T> class _RW_array {
  174.  
  175. public:
  176.  
  177.   _RW_array( )
  178.     : _RW_length(0)
  179. , _RW_storage(0)
  180.   { ; }
  181.  
  182.   ~_RW_array( )
  183.   { if ( _RW_storage ) delete []_RW_storage; }
  184.  
  185.   void _initial_size(size_t size)
  186.   {
  187.     _RW_length = size;
  188.     _RW_storage = new T[_RW_length];
  189.   }
  190.  
  191.   void _initialize_with_value(const T&, size_t);
  192.   void _initialize_with_array(const T*, size_t);
  193.   void _copy_memory_array(const _RW_array<T>&);
  194.  
  195.   size_t _get_length() const { return _RW_length; }
  196.  
  197.   T operator[] (size_t ind) const
  198.   { return _RW_storage[ind]; }
  199.  
  200.   T& operator[] (size_t ind)
  201.   { return _RW_storage[ind]; }
  202.  
  203.   void _replace(T* tmp_adr, size_t tmp_length )
  204.   {
  205.     _RW_storage = tmp_adr;
  206.     _RW_length = tmp_length;
  207.   }
  208.  
  209.   T* _RW_get_storage() const { return _RW_storage; }
  210.  
  211.   void _RW_invalidate()
  212.   {
  213.     _RW_length = 0;
  214.     _RW_storage = 0;
  215.   }
  216.  
  217.   void _RW_copy( T* pointer ) const
  218.   {
  219. #if !defined(_RWSTD_NO_NEW_HEADER) && !defined(_RWSTD_NO_NAMESPACE)
  220.     std::memcpy( (void*)pointer, (void*)_RW_storage,_RW_length*sizeof(T));
  221. #else
  222.     memcpy( (void*)pointer, (void*)_RW_storage,_RW_length*sizeof(T));
  223. #endif
  224.   }
  225.  
  226.   void _RW_resize_without_copy( size_t size)
  227.   {
  228.     if ( _RW_storage )
  229.     {
  230.       delete []_RW_storage;
  231.       _RW_storage = 0;
  232.     }
  233.     _RW_length = size;
  234.     if ( size > 0 ) _RW_storage = new T[_RW_length];
  235.   }
  236.  
  237. private:
  238.   size_t                         _RW_length;
  239.   T*                             _RW_storage;
  240. };
  241. #ifndef _RWSTD_NO_NAMESPACE
  242. }
  243. #endif
  244. #ifdef _RWSTD_NO_TEMPLATE_REPOSITORY
  245. #include <rw/valimp.cc>
  246. #endif
  247.  
  248. #endif /* __RW_VALIMP__ */
  249.  
  250. #pragma option pop
  251. #endif /* __VALIMP_H */
  252.