Anti-Grain Geometry Tutorial
agg_span_allocator.h
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 
16 #ifndef AGG_SPAN_ALLOCATOR_INCLUDED
17 #define AGG_SPAN_ALLOCATOR_INCLUDED
18 
19 #include "agg_array.h"
20 
21 namespace agg
22 {
23  //----------------------------------------------------------span_allocator
24  template<class ColorT> class span_allocator
25  {
26  public:
27  typedef ColorT color_type;
28 
29  //--------------------------------------------------------------------
30  AGG_INLINE color_type* allocate(unsigned span_len)
31  {
32  if(span_len > m_span.size())
33  {
34  // To reduce the number of reallocs we align the
35  // span_len to 256 color elements.
36  // Well, I just like this number and it looks reasonable.
37  //-----------------------
38  m_span.resize(((span_len + 255) >> 8) << 8);
39  }
40  return &m_span[0];
41  }
42 
43  AGG_INLINE color_type* span() { return &m_span[0]; }
44  AGG_INLINE unsigned max_span_len() const { return m_span.size(); }
45 
46  private:
47  pod_array<color_type> m_span;
48  };
49 }
50 
51 
52 #endif
53 
54 
Definition: agg_arc.cpp:24