PLearn 0.1
CopiesMap.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 1999-2006 University of Montreal and individual contributors
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 // 
00009 //  1. Redistributions of source code must retain the above copyright
00010 //     notice, this list of conditions and the following disclaimer.
00011 // 
00012 //  2. Redistributions in binary form must reproduce the above copyright
00013 //     notice, this list of conditions and the following disclaimer in the
00014 //     documentation and/or other materials provided with the distribution.
00015 // 
00016 //  3. The name of the authors may not be used to endorse or promote
00017 //     products derived from this software without specific prior written
00018 //     permission.
00019 // 
00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 // 
00031 // This file is part of the PLearn library. For more information on the PLearn
00032 // library, go to the PLearn Web site at www.plearn.org
00033 
00034 
00035 #ifndef CopiesMap_INC
00036 #define CopiesMap_INC
00037 
00038 #include <deque>
00039 #include <map>
00040 #include <plearn/base/pl_hash_fun.h>
00041 #include <set>
00042 #include <list>
00043 #include <vector>
00044 #include <string>
00045 #include <time.h>       
00046 #include <utility>      
00047 #include "plerror.h"    
00048 
00049 
00055 #define NODEEPCOPY(TYPE)                                      \
00056       inline void deepCopyField(TYPE&, CopiesMap&) {}         \
00057       inline void deepCopyField(Array<TYPE>&, CopiesMap&) {}
00058 
00059 namespace PLearn {
00060 using std::string;
00061 using std::deque;
00062 using std::map;
00063 using std::multimap;
00064 using std::set;
00065 using std::multiset;
00066 using std::list;
00067 using std::vector;
00068 using std::pair;
00069 
00070 class PPath;
00071 class VMField;
00072 class VMFieldStat;
00073 template <class T> class Array;
00074 
00077 typedef map<const void*,void*> CopiesMap;
00078 
00080 typedef map<string, float> map_string_float;
00081 typedef map<string, double> map_string_double;
00082 typedef map<double, string> map_double_string;
00083 typedef map<float, string> map_float_string;
00084 typedef map<string, string> map_string_string;
00085 typedef map<float, float> map_float_float;
00086 typedef map<double, double> map_double_double;
00087 typedef map<string, int> map_string_int;
00088 typedef map<int, string> map_int_string;
00089 
00105 
00106 NODEEPCOPY(double)
00107 NODEEPCOPY(const double)
00108 NODEEPCOPY(float)
00109 NODEEPCOPY(const float)
00110 NODEEPCOPY(int)
00111 NODEEPCOPY(int8_t)
00112 NODEEPCOPY(const int)
00113 NODEEPCOPY(unsigned int)
00114 NODEEPCOPY(const unsigned int)
00115 NODEEPCOPY(short)
00116 NODEEPCOPY(const short)
00117 NODEEPCOPY(unsigned short)
00118 NODEEPCOPY(const unsigned short)
00119 NODEEPCOPY(char)
00120 NODEEPCOPY(const char)
00121 NODEEPCOPY(unsigned char)
00122 NODEEPCOPY(const unsigned char)
00123 NODEEPCOPY(const string)
00124 NODEEPCOPY(clock_t)
00125 NODEEPCOPY(bool)
00126 NODEEPCOPY(map_string_float)
00127 NODEEPCOPY(map_string_double)
00128 NODEEPCOPY(map_float_string)
00129 NODEEPCOPY(map_double_string)
00130 NODEEPCOPY(map_string_string)
00131 NODEEPCOPY(map_float_float)
00132 NODEEPCOPY(map_double_double)
00133 NODEEPCOPY(map_string_int)
00134 NODEEPCOPY(map_int_string)
00135 NODEEPCOPY(string)
00136 NODEEPCOPY(PPath)
00137 NODEEPCOPY(VMField)
00138 NODEEPCOPY(VMFieldStat)
00139 NODEEPCOPY(FILE*)   
00140 
00141 
00142 //#####  Some Standard STL Containers  ########################################
00143 
00145 template <class T, class U>
00146 inline void deepCopyField(pair<T,U>& p, CopiesMap& copies)
00147 {
00148     deepCopyField(p.first, copies);
00149     deepCopyField(p.second, copies);
00150 }
00151 
00153 template <class T, class Alloc>
00154 void deepCopyField(deque<T,Alloc>& c, CopiesMap& copies)
00155 {
00156     for (typename deque<T,Alloc>::iterator it = c.begin(), end=c.end()
00157              ; it != end ; ++it)
00158         deepCopyField(*it, copies);
00159 }
00160 
00161 template <class T, class U, class Compare, class Alloc>
00162 void deepCopyField(map<T,U,Compare,Alloc>& c, CopiesMap& copies)
00163 {
00164     for (typename map<T,U,Compare,Alloc>::iterator it = c.begin(), end=c.end()
00165              ; it != end ; ++it)
00166         deepCopyField(*it, copies);
00167 }
00168 
00169 template <class T, class U, class Compare, class Alloc>
00170 void deepCopyField(hash_map<T,U,Compare,Alloc>& c, CopiesMap& copies)
00171 {
00172     for (typename hash_map<T,U,Compare,Alloc>::iterator it = c.begin(), end=c.end()
00173              ; it != end ; ++it)
00174         deepCopyField(*it, copies);
00175 }
00176 
00177 template <class T, class U, class Compare, class Alloc>
00178 void deepCopyField(multimap<T,U,Compare,Alloc>& c, CopiesMap& copies)
00179 {
00180     for (typename multimap<T,U,Compare,Alloc>::iterator it = c.begin(), end=c.end()
00181              ; it != end ; ++it)
00182         deepCopyField(*it, copies);
00183 }
00184 
00185 template <class T, class Compare, class Alloc>
00186 void deepCopyField(set<T,Compare,Alloc>& c, CopiesMap& copies)
00187 {
00188     for (typename set<T,Compare,Alloc>::iterator it = c.begin(), end=c.end()
00189              ; it != end ; ++it)
00190         deepCopyField(*it, copies);
00191 }
00192 
00193 template <class T, class Compare, class Alloc>
00194 void deepCopyField(multiset<T,Compare,Alloc>& c, CopiesMap& copies)
00195 {
00196     for (typename multiset<T,Compare,Alloc>::iterator it = c.begin(), end=c.end()
00197              ; it != end ; ++it)
00198         deepCopyField(*it, copies);
00199 }
00200 
00201 template <class T, class Alloc>
00202 void deepCopyField(list<T,Alloc>& c, CopiesMap& copies)
00203 {
00204     for (typename list<T,Alloc>::iterator it = c.begin(), end=c.end()
00205              ; it != end ; ++it)
00206         deepCopyField(*it, copies);
00207 }
00208 
00209 template <class T, class Alloc>
00210 void deepCopyField(vector<T,Alloc>& c, CopiesMap& copies)
00211 {
00212     for (typename vector<T,Alloc>::iterator it = c.begin(), end=c.end()
00213              ; it != end ; ++it)
00214         deepCopyField(*it, copies);
00215 }
00216 
00217 //#####  Fallbacks  ###########################################################
00218 
00220 template <class T>
00221 inline void deepCopyField(T&, CopiesMap&)
00222 {
00224     PLWARNING(
00225         "In CopiesMap.h - deepCopyField not handled for the type '%s'. "
00226         "If it actually doesn't need deep copy, edit CopiesMap.h and add"
00227         " NODEEPCOPY(your_type) to remove this warning.",
00228         TypeTraits<T>().name().c_str()
00229         );
00230 }
00231 
00232 template <class T>
00233 inline void deepCopyField(T*& field, CopiesMap& copies)
00234 {
00235     if (field)
00236         field = field->deepCopy(copies);
00237 }
00238 
00240 template<class T>
00241 T* deepCopy(const T* source, CopiesMap& copies)
00242 { return source->deepCopy(copies); }
00243 
00245 template<class T>
00246 inline T* deepCopy(const T* source)
00247 { 
00248     CopiesMap copies; 
00249     return deepCopy(source, copies);
00250 }
00251 
00252 
00253 }
00254 
00255 #endif //ndef CopiesMap_INC
00256 
00257 
00258 /*
00259   Local Variables:
00260   mode:c++
00261   c-basic-offset:4
00262   c-file-style:"stroustrup"
00263   c-file-offsets:((innamespace . 0)(inline-open . 0))
00264   indent-tabs-mode:nil
00265   fill-column:79
00266   End:
00267 */
00268 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines