KiCad PCB EDA Suite
vertex_container.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef VERTEX_CONTAINER_H_
31 #define VERTEX_CONTAINER_H_
32 
34 
35 namespace KIGFX
36 {
37 class VERTEX_ITEM;
38 class SHADER;
39 
41 {
42 public:
47  static VERTEX_CONTAINER* MakeContainer( bool aCached );
48 
49  virtual ~VERTEX_CONTAINER();
50 
55  virtual void Map() {}
56 
61  virtual void Unmap()
62  {}
63 
69  virtual void SetItem( VERTEX_ITEM* aItem ) = 0;
70 
75  virtual void FinishItem() {};
76 
86  virtual VERTEX* Allocate( unsigned int aSize ) = 0;
87 
94  virtual void Delete( VERTEX_ITEM* aItem ) = 0;
95 
100  virtual void Clear() = 0;
101 
107  inline virtual VERTEX* GetAllVertices() const
108  {
109  return m_vertices;
110  }
111 
117  virtual inline VERTEX* GetVertices( unsigned int aOffset ) const
118  {
119  return &m_vertices[aOffset];
120  }
121 
126  virtual inline unsigned int GetSize() const
127  {
128  return m_currentSize;
129  }
130 
136  inline bool IsDirty()
137  {
138  bool state = m_dirty;
139 
140  m_dirty = false;
141 
142  return state;
143  }
144 
150  inline void SetDirty()
151  {
152  m_dirty = true;
153  }
154 
155 protected:
156  VERTEX_CONTAINER( unsigned int aSize = defaultInitSize );
157 
159  unsigned int m_freeSpace;
160 
162  unsigned int m_currentSize;
163 
165  unsigned int m_initialSize;
166 
169 
171  bool m_failed;
172  bool m_dirty;
173 
179  inline unsigned int usedSpace() const
180  {
181  return m_currentSize - m_freeSpace;
182  }
183 
185  static const unsigned int defaultInitSize = 1048576;
186 };
187 } // namespace KIGFX
188 
189 #endif /* VERTEX_CONTAINER_H_ */
unsigned int usedSpace() const
Function usedSpace() returns size of the used memory space.
unsigned int m_initialSize
Actual storage memory (should be handled using malloc/realloc/free to speed up resizing) ...
static VERTEX_CONTAINER * MakeContainer(bool aCached)
Function MakeContainer() Returns a pointer to a new container of an appropriate type.
virtual void Clear()=0
Function Clear() removes all the data stored in the container and restores its original state...
virtual void Unmap()
Function Unmap() finishes the vertices updates stage.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
virtual VERTEX * GetVertices(unsigned int aOffset) const
Function GetVertices() returns vertices stored at the specific offset.
virtual void Map()
Function Map() prepares the container for vertices updates.
static const unsigned int defaultInitSize
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
VERTEX * m_vertices
State flags.
virtual VERTEX * GetAllVertices() const
Function GetAllVertices() returns all the vertices stored in the container.
virtual void FinishItem()
Function FinishItem() does the cleaning after adding an item.
unsigned int m_freeSpace
How big is the current container, expressed in vertices.
virtual unsigned int GetSize() const
Function GetSize() returns amount of vertices currently stored in the container.
Common defines and consts used in vertex related classes.
VERTEX_CONTAINER(unsigned int aSize=defaultInitSize)
How many vertices we can store in the container.
bool IsDirty()
Function IsDirty() returns information about container cache state.
virtual void SetItem(VERTEX_ITEM *aItem)=0
Function SetItem() sets the item in order to modify or finishes its current modifications.
virtual VERTEX * Allocate(unsigned int aSize)=0
Function Allocate() returns allocated space (possibly resizing the used memory chunk or allocating a ...
void SetDirty()
Function SetDirty() sets the dirty flag, so vertices in the container are going to be reuploaded to t...
virtual void Delete(VERTEX_ITEM *aItem)=0
Function Delete() erases the selected item.