libidx
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Yann LeCun and Pierre Sermanet * 00003 * yann@cs.nyu.edu, pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef _SRG_H 00034 #define _SRG_H 00035 00036 #include <stdio.h> 00037 00038 #include "defines.h" 00039 #include "stl.h" 00040 #include "smart.h" 00041 00042 namespace ebl { 00043 00045 // srg: storage area for idx data. 00046 00062 template <typename T> class srg : public smart_pointer { 00063 public: 00065 srg(); 00067 srg(intg s); 00075 ~srg(); 00077 intg size(); 00081 intg changesize(intg s); 00083 intg growsize(intg s); 00085 intg growsize_chunk(intg s, intg s_chunk); 00086 00087 /* //! decrement reference counter and deallocate srg */ 00088 /* //! if it reaches zero. */ 00089 /* int unlock(); */ 00090 /* //! lock: increment reference counter. */ 00091 /* //! This is called wheneve a new idx is created */ 00092 /* //! on the srg. */ 00093 /* int lock(); */ 00094 00096 T get(intg i); 00098 T* get_data(); 00100 void set_data(T* ptr); 00102 void set(intg i, T val); 00104 void clear(); 00106 void pretty(FILE *f); 00107 00108 // friends ///////////////////////////////////////////////////////////////// 00109 template <typename T2> friend class idx; 00110 template <typename T2> friend class idxiter; 00111 template <typename T2> friend class noncontiguous_idxiter; 00112 template <typename T2> friend class contiguous_idxiter; 00113 template <typename T2> friend class idxlooper; 00114 00115 // member variables //////////////////////////////////////////////////////// 00116 private: 00117 T *data; 00118 intg size_; 00119 00120 // int refcount; //!< Reference counter: tells us how many idx point here. 00121 00122 // debug only ////////////////////////////////////////////////////////////// 00123 #ifdef __DEBUGMEM__ 00124 public: 00125 static intg memsize; 00126 #endif 00127 }; 00128 00129 } // end namespace ebl 00130 00131 #include "srg.hpp" 00132 00133 #endif /* _SRG_H */