1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
// Copyright (c) 2009-2014 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Triangulation/include/CGAL/Triangulation/internal/Static_or_dynamic_array.h $
// $Id: include/CGAL/Triangulation/internal/Static_or_dynamic_array.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Samuel Hornus
#ifndef CGAL_INTERNAL_STATIC_OR_DYNAMIC_ARRAY_H
#define CGAL_INTERNAL_STATIC_OR_DYNAMIC_ARRAY_H
#include <CGAL/license/Triangulation.h>
#include <CGAL/Compact_container.h>
#include <CGAL/Dimension.h>
#include <CGAL/array.h>
#include <vector>
namespace CGAL {
namespace internal {
// Utility for adding one to an Dimension_tag:
template<typename D>
struct Dimen_plus_one;
template<>
struct Dimen_plus_one<Dynamic_dimension_tag>
{
typedef Dynamic_dimension_tag type;
};
template<int D>
struct Dimen_plus_one<Dimension_tag<D> >
{
typedef Dimension_tag<D+1> type;
};
// A SMALL CONTAINER UTILITY FOR DYNAMIC/STATIC MEMORY MANAGEMENT
// stores an array of static or dynamic size, depending on template parameter <B>.
template< typename Containee, typename D, bool WithCompactContainerHelper = false>
struct S_or_D_array; // S = static, D = dynamic
// The case of static size:
template< typename Containee, int D, bool WithCompactContainerHelper >
struct S_or_D_array< Containee, Dimension_tag< D >, WithCompactContainerHelper >
: public std::array<Containee, D>
{
typedef std::array<Containee, D> Base;
S_or_D_array(const int)
: Base()
{}
S_or_D_array(const int, const Containee & c)
: Base()
{
assign(c);
}
void* for_compact_container() const
{
return (*this)[0].for_compact_container();
}
void for_compact_container(void *p)
{
(*this)[0].for_compact_container(p);
}
};
// The case of dynamic size
template< typename Containee >
struct S_or_D_array< Containee, Dynamic_dimension_tag, false >
: public std::vector<Containee>
{
typedef std::vector<Containee> Base;
// TODO: maybe we should use some "small-vector-optimized" class.
S_or_D_array(const int d)
: Base(d)
{}
S_or_D_array(const int d, const Containee & c)
: Base(d, c)
{}
};
// The case of dynamic size with for_compact_container
template< typename Containee >
struct S_or_D_array< Containee, Dynamic_dimension_tag, true >
: public std::vector<Containee>
{
typedef std::vector<Containee> Base;
S_or_D_array(const int d)
: Base(d), fcc_(nullptr)
{}
S_or_D_array(const int d, const Containee & c)
: Base(d, c), fcc_(nullptr)
{}
void* fcc_;
void* for_compact_container() const { return fcc_; }
void for_compact_container(void* p) { fcc_ = p; }
};
} // end of namespace internal
} // end of namespace CGAL
#endif // CGAL_INTERNAL_STATIC_OR_DYNAMIC_ARRAY_H
|