zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Common.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef _COMMON_INCLUDED_
8 #define _COMMON_INCLUDED_
9 
10 #include <map>
11 #include <sstream>
12 #include <string>
13 #include <vector>
14 
15 #include "compiler/PoolAlloc.h"
16 
17 struct TSourceLoc {
20  int last_file;
21  int last_line;
22 };
23 
24 //
25 // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
26 //
27 #define POOL_ALLOCATOR_NEW_DELETE() \
28  void* operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \
29  void* operator new(size_t, void *_Where) { return (_Where); } \
30  void operator delete(void*) { } \
31  void operator delete(void *, void *) { } \
32  void* operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \
33  void* operator new[](size_t, void *_Where) { return (_Where); } \
34  void operator delete[](void*) { } \
35  void operator delete[](void *, void *) { }
36 
37 //
38 // Pool version of string.
39 //
41 typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
42 typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream;
43 inline TString* NewPoolTString(const char* s)
44 {
45  void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString));
46  return new(memory) TString(s);
47 }
48 
49 //
50 // Persistent string memory. Should only be used for strings that survive
51 // across compiles.
52 //
53 #define TPersistString std::string
54 #define TPersistStringStream std::ostringstream
55 
56 //
57 // Pool allocator versions of vectors, lists, and maps
58 //
59 template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
60 public:
61  typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
62  TVector() : std::vector<T, pool_allocator<T> >() {}
63  TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
64  TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
65 };
66 
67 template <class K, class D, class CMP = std::less<K> >
68 class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D> > > {
69 public:
71 
72  TMap() : std::map<K, D, CMP, tAllocator>() {}
73  // use correct two-stage name lookup supported in gcc 3.4 and above
74  TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {}
75 };
76 
77 #endif // _COMMON_INCLUDED_
void * allocate(size_t numBytes)
Definition: PoolAlloc.cpp:206
TVector()
Definition: Common.h:62
GLdouble s
Definition: glew.h:1376
TPoolAllocator * GetGlobalPoolAllocator()
Definition: PoolAlloc.cpp:36
TVector(const pool_allocator< T > &a)
Definition: Common.h:63
int last_file
Definition: Common.h:20
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
TVector(size_type i)
Definition: Common.h:64
TMap(const tAllocator &a)
Definition: Common.h:74
std::basic_ostringstream< char, std::char_traits< char >, TStringAllocator > TStringStream
Definition: Common.h:42
TString * NewPoolTString(const char *s)
Definition: Common.h:43
pool_allocator< char > TStringAllocator
Definition: Common.h:40
Definition: Common.h:68
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
int last_line
Definition: Common.h:21
TMap()
Definition: Common.h:72
int first_file
Definition: Common.h:18
Definition: Common.h:59
int first_line
Definition: Common.h:19
pool_allocator< std::pair< const K, D > > tAllocator
Definition: Common.h:70
int i
Definition: pngrutil.c:1377
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum map
Definition: SDL_glfuncs.h:268
std::vector< FunctionNode *, pool_allocator< FunctionNode * > >::size_type size_type
Definition: Common.h:61