home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / uint_t_array.h < prev    next >
C/C++ Source or Header  |  2008-11-07  |  3KB  |  134 lines

  1. #ifndef K3DSDK_UINT_T_ARRAY_H
  2. #define K3DSDK_UINT_T_ARRAY_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2008, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. #include "almost_equal.h"
  24. #include "array.h"
  25.  
  26. #include <algorithm>
  27. #include <vector>
  28.  
  29. namespace k3d
  30. {
  31.  
  32. /// Strongly-typed dynamic array of k3d::uint_t values, based on std::vector.
  33. /// We declare this is a special-type to prevent conflicts with k3d::typed_array.
  34. class uint_t_array :
  35.     public std::vector<uint_t>,
  36.     public array
  37. {
  38.     typedef std::vector<uint_t> base_type;
  39.     typedef uint_t_array this_type;
  40.  
  41. public:
  42.     uint_t_array() :
  43.         base_type()
  44.     {
  45.     }
  46.  
  47.     explicit uint_t_array(const uint_t count) :
  48.         base_type(count)
  49.     {
  50.     }
  51.  
  52.     uint_t_array(const uint_t count, const uint_t& val) :
  53.         base_type(count, val)
  54.     {
  55.     }
  56.  
  57.     uint_t_array(const this_type& right) :
  58.         base_type(right),
  59.         array(right.metadata)
  60.     {
  61.     }
  62.  
  63.     template<class IteratorT>
  64.     uint_t_array(const IteratorT first, const IteratorT last) :
  65.         base_type(first, last)
  66.     {
  67.     }
  68.  
  69.     array* clone_type() const
  70.     {
  71.         this_type* const result = new this_type();
  72.         result->metadata = metadata;
  73.         return result;
  74.     }
  75.  
  76.     array* clone() const
  77.     {
  78.         this_type* const result = new this_type(*this);
  79.         return result;
  80.     }
  81.  
  82.     array* clone(const uint_t Begin, const uint_t End) const
  83.     {
  84.         this_type* const result = new this_type(this->begin() + Begin, this->begin() + End);
  85.         result->metadata = metadata;
  86.         return result;
  87.     }
  88.  
  89.     void resize(const uint_t NewSize)
  90.     {
  91.         base_type::resize(NewSize);
  92.     }
  93.  
  94.     void resize(const uint_t NewSize, const uint_t& Value)
  95.     {
  96.         base_type::resize(NewSize, Value);
  97.     }
  98.  
  99.     const uint_t size() const
  100.     {
  101.         return base_type::size();
  102.     }
  103.  
  104.     const bool_t empty() const
  105.     {
  106.         return base_type::empty();
  107.     }
  108.  
  109.     const bool_t almost_equal(const array& Other, const uint64_t Threshold) const
  110.     {
  111.         const this_type* const other = dynamic_cast<const this_type*>(&Other);
  112.         if(!other)
  113.             return false;
  114.  
  115.         return almost_equal(*other, Threshold);
  116.     }
  117.  
  118.     const bool_t almost_equal(const this_type& Other, const uint64_t Threshold) const
  119.     {
  120.         if(base_type::size() != Other.size())
  121.             return false;
  122.  
  123.         if(metadata != Other.metadata)
  124.             return false;
  125.  
  126.         return std::equal(base_type::begin(), base_type::end(), Other.begin(), k3d::almost_equal<uint_t>(Threshold));
  127.     }
  128. };
  129.  
  130. } // namespace k3d
  131.  
  132. #endif // !K3DSDK_UINT_T_ARRAY_H
  133.  
  134.