xref: /haiku/headers/libs/agg/agg_span_allocator.h (revision 39241fe22890fb958b6ba32d6ab9526da98be187)
1*39241fe2SDarkWyrm //----------------------------------------------------------------------------
2*39241fe2SDarkWyrm // Anti-Grain Geometry - Version 2.2
3*39241fe2SDarkWyrm // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
4*39241fe2SDarkWyrm //
5*39241fe2SDarkWyrm // Permission to copy, use, modify, sell and distribute this software
6*39241fe2SDarkWyrm // is granted provided this copyright notice appears in all copies.
7*39241fe2SDarkWyrm // This software is provided "as is" without express or implied
8*39241fe2SDarkWyrm // warranty, and with no claim as to its suitability for any purpose.
9*39241fe2SDarkWyrm //
10*39241fe2SDarkWyrm //----------------------------------------------------------------------------
11*39241fe2SDarkWyrm // Contact: mcseem@antigrain.com
12*39241fe2SDarkWyrm //          mcseemagg@yahoo.com
13*39241fe2SDarkWyrm //          http://www.antigrain.com
14*39241fe2SDarkWyrm //----------------------------------------------------------------------------
15*39241fe2SDarkWyrm 
16*39241fe2SDarkWyrm #ifndef AGG_SPAN_ALLOCATOR_INCLUDED
17*39241fe2SDarkWyrm #define AGG_SPAN_ALLOCATOR_INCLUDED
18*39241fe2SDarkWyrm 
19*39241fe2SDarkWyrm #include "agg_basics.h"
20*39241fe2SDarkWyrm 
21*39241fe2SDarkWyrm namespace agg
22*39241fe2SDarkWyrm {
23*39241fe2SDarkWyrm     //----------------------------------------------------------span_allocator
24*39241fe2SDarkWyrm     template<class ColorT> class span_allocator
25*39241fe2SDarkWyrm     {
26*39241fe2SDarkWyrm     public:
27*39241fe2SDarkWyrm         typedef ColorT color_type;
28*39241fe2SDarkWyrm 
29*39241fe2SDarkWyrm         //--------------------------------------------------------------------
30*39241fe2SDarkWyrm         ~span_allocator()
31*39241fe2SDarkWyrm         {
32*39241fe2SDarkWyrm             delete [] m_span;
33*39241fe2SDarkWyrm         }
34*39241fe2SDarkWyrm 
35*39241fe2SDarkWyrm         //--------------------------------------------------------------------
36*39241fe2SDarkWyrm         span_allocator() :
37*39241fe2SDarkWyrm             m_max_span_len(0),
38*39241fe2SDarkWyrm             m_span(0)
39*39241fe2SDarkWyrm         {
40*39241fe2SDarkWyrm         }
41*39241fe2SDarkWyrm 
42*39241fe2SDarkWyrm         //--------------------------------------------------------------------
43*39241fe2SDarkWyrm         color_type* allocate(unsigned max_span_len)
44*39241fe2SDarkWyrm         {
45*39241fe2SDarkWyrm             if(max_span_len > m_max_span_len)
46*39241fe2SDarkWyrm             {
47*39241fe2SDarkWyrm                 delete [] m_span;
48*39241fe2SDarkWyrm                 m_span = new color_type[m_max_span_len = max_span_len];
49*39241fe2SDarkWyrm             }
50*39241fe2SDarkWyrm             return m_span;
51*39241fe2SDarkWyrm         }
52*39241fe2SDarkWyrm 
53*39241fe2SDarkWyrm         //--------------------------------------------------------------------
54*39241fe2SDarkWyrm         color_type* span()
55*39241fe2SDarkWyrm         {
56*39241fe2SDarkWyrm             return m_span;
57*39241fe2SDarkWyrm         }
58*39241fe2SDarkWyrm 
59*39241fe2SDarkWyrm     private:
60*39241fe2SDarkWyrm         //--------------------------------------------------------------------
61*39241fe2SDarkWyrm         span_allocator(const span_allocator<ColorT>&);
62*39241fe2SDarkWyrm         const span_allocator<ColorT>& operator = (const span_allocator<ColorT>&);
63*39241fe2SDarkWyrm 
64*39241fe2SDarkWyrm         unsigned    m_max_span_len;
65*39241fe2SDarkWyrm         color_type* m_span;
66*39241fe2SDarkWyrm     };
67*39241fe2SDarkWyrm }
68*39241fe2SDarkWyrm 
69*39241fe2SDarkWyrm 
70*39241fe2SDarkWyrm #endif
71*39241fe2SDarkWyrm 
72*39241fe2SDarkWyrm 
73