osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_seamless/AutoBuffer

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2009 Pelican Ventures, Inc.
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #ifndef SEAMLESS_AUTOBUFFER
00021 #define SEAMLESS_AUTOBUFFER 1
00022 
00023 namespace seamless
00024 {
00030 template<typename T, int N>
00031 class AutoBuffer
00032 {
00033 public:
00034     AutoBuffer(int size)
00035         : _heapStore(size > N ? new T[size] : 0),
00036           _ptr(size > N ? _heapStore : &_store[0])
00037     {
00038     }
00039 
00040     ~AutoBuffer()
00041     {
00042         delete [] _heapStore;
00043     }
00044 
00045     T& operator[](int i) const { return _ptr[i]; }
00046     
00047 private:
00048     AutoBuffer(const AutoBuffer&);
00049     T _store[N];
00050     T* _heapStore;
00051     T* const _ptr;
00052 };
00053 }
00054 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines