Generated on Tue Dec 13 2011 10:02:21 for Gecode by doxygen 1.7.4
archive.hpp
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-08-29 16:19:20 +0200 (Mon, 29 Aug 2011) $ by $Author: schulte $
00011  *     $Revision: 12361 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode {
00045   class Archive {
00046   private:
00048     int _size;
00050     int _n;
00052     unsigned int* _a;
00054     int _pos;
00056     GECODE_KERNEL_EXPORT void resize(int n);
00057   public:
00059     Archive(void);
00061     GECODE_KERNEL_EXPORT ~Archive(void);
00063     GECODE_KERNEL_EXPORT Archive(const Archive& e);
00065     GECODE_KERNEL_EXPORT Archive& operator =(const Archive& e);
00067     void put(unsigned int i);
00069     int size(void) const;
00071     unsigned int operator [](int i) const;
00073     unsigned int get(void);
00074   };
00075 
00079   Archive&
00080   operator <<(Archive& e, unsigned int i);
00084   Archive&
00085   operator <<(Archive& e, int i);
00089   Archive&
00090   operator <<(Archive& e, unsigned short i);
00094   Archive&
00095   operator <<(Archive& e, short i);
00099   Archive&
00100   operator <<(Archive& e, unsigned char i);
00104   Archive&
00105   operator <<(Archive& e, char i);
00109   Archive&
00110   operator <<(Archive& e, bool i);
00111 
00115   Archive&
00116   operator >>(Archive& e, unsigned int& i);
00120   Archive&
00121   operator >>(Archive& e, int& i);
00125   Archive&
00126   operator >>(Archive& e, unsigned short& i);
00130   Archive&
00131   operator >>(Archive& e, short& i);
00135   Archive&
00136   operator >>(Archive& e, unsigned char& i);
00140   Archive&
00141   operator >>(Archive& e, char& i);
00145   Archive&
00146   operator >>(Archive& e, bool& i);
00147 
00148   /*
00149    * Implementation
00150    *
00151    */
00152 
00153   forceinline
00154   Archive::Archive(void) : _size(0), _n(0), _a(NULL), _pos(0) {}
00155 
00156   forceinline void
00157   Archive::put(unsigned int i) {
00158     if (_n==_size)
00159       resize(_n+1);
00160     _a[_n++] = i;
00161   }
00162     
00163   forceinline int
00164   Archive::size(void) const { return _n; }
00165   
00166   forceinline unsigned int
00167   Archive::operator [](int i) const {
00168     assert(i < _n);
00169     return _a[i];
00170   }
00171 
00172   forceinline unsigned int
00173   Archive::get(void) {
00174     assert(_pos < _n);
00175     return _a[_pos++];
00176   }
00177 
00178   forceinline Archive&
00179   operator <<(Archive& e, unsigned int i) {
00180     e.put(i);
00181     return e;
00182   }
00183   forceinline Archive&
00184   operator <<(Archive& e, int i) {
00185     e.put(static_cast<unsigned int>(i));
00186     return e;
00187   }
00188   forceinline Archive&
00189   operator <<(Archive& e, unsigned short i) {
00190     e.put(i);
00191     return e;
00192   }
00193   forceinline Archive&
00194   operator <<(Archive& e, short i) {
00195     e.put(static_cast<unsigned int>(i));
00196     return e;
00197   }
00198   forceinline Archive&
00199   operator <<(Archive& e, unsigned char i) {
00200     e.put(i);
00201     return e;
00202   }
00203   forceinline Archive&
00204   operator <<(Archive& e, char i) {
00205     e.put(static_cast<unsigned int>(i));
00206     return e;
00207   }
00208   forceinline Archive&
00209   operator <<(Archive& e, bool i) {
00210     e.put(static_cast<unsigned int>(i));
00211     return e;
00212   }
00213 
00214   forceinline Archive&
00215   operator >>(Archive& e, unsigned int& i) {
00216     i = e.get();
00217     return e;
00218   }
00219   forceinline Archive&
00220   operator >>(Archive& e, int& i) {
00221     i = static_cast<int>(e.get());
00222     return e;
00223   }
00224   forceinline Archive&
00225   operator >>(Archive& e, unsigned short& i) {
00226     i = static_cast<unsigned short>(e.get());
00227     return e;
00228   }
00229   forceinline Archive&
00230   operator >>(Archive& e, short& i) {
00231     i = static_cast<short>(e.get());
00232     return e;
00233   }
00234   forceinline Archive&
00235   operator >>(Archive& e, unsigned char& i) {
00236     i = static_cast<unsigned char>(e.get());
00237     return e;
00238   }
00239   forceinline Archive&
00240   operator >>(Archive& e, char& i) {
00241     i = static_cast<char>(e.get());
00242     return e;
00243   }
00244   forceinline Archive&
00245   operator >>(Archive& e, bool& i) {
00246     i = static_cast<bool>(e.get());
00247     return e;
00248   }
00249 
00250 }
00251 
00252 // STATISTICS: kernel-branch