dimension.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 3 -*-
00002  *
00003  * Copyright (c), GREYC.
00004  * All rights reserved
00005  *
00006  * You may use this file under the terms of the BSD license as follows:
00007  *
00008  * "Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are
00010  * met:
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above copyright
00014  *     notice, this list of conditions and the following disclaimer in
00015  *     the documentation and/or other materials provided with the
00016  *     distribution.
00017  *   * Neither the name of the GREYC, nor the name of its
00018  *     contributors may be used to endorse or promote products
00019  *     derived from this software without specific prior written
00020  *     permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00033  *
00034  *
00035  * For more information, refer to:
00036  * https://clouard.users.greyc.fr/Pandore
00037  */
00038 
00044 #ifndef __PDIMENSIONH__
00045 #define __PDIMENSIONH__
00046 
00047 namespace pandore {
00048 
00049    class Dimension1d;
00050    class Dimension2d;
00051    class Dimension3d;
00052 
00053 /* @brief A trait that returns the name of the object Dimension1d.
00054  *
00055  * TypeName is a trait that returns the name
00056  * of the object Dimension1d.
00057  */
00058    template<>
00059    struct TypeName< Dimension1d > {
00060          /*
00061           * Returns the name of the type.
00062           * @return     the string with the name.
00063           */
00064          static ::std::string Name() { return "Dimension1d"; }
00065    };
00066 
00067    /* @brief A trait that returns the name of the object Dimension2d.
00068     *
00069     * TypeName is a trait that returns the name
00070     * of the object Dimension2d.
00071     */
00072    template<>
00073    struct TypeName< Dimension2d > {
00074          /*
00075           * Returns the name of the type.
00076           * @return     the string with the name.
00077           */
00078          static std::string Name() { return "Dimension2d"; }
00079    };
00080 
00081    /* @brief A trait that returns the name of the object Dimension3d.
00082     *
00083     * TypeName is a trait that returns the name
00084     * of the object Dimension3d.
00085     */
00086    template<>
00087    struct TypeName< Dimension3d > {
00088          /*
00089           * Returns the name of the type.
00090           * @return     the string with the name.
00091           */
00092          static std::string Name() { return "Dimension3d"; }
00093    };
00094 
00107    class Dimension: public Pobject {
00108       protected:
00109          Dimension() {}
00110    
00111       public:
00112          ~Dimension() {}
00113 
00119          Pobject* Mask( const Pobject * /*mask*/ ) {
00120             return this;
00121          }
00122 
00129          Pobject* UnMask( const Pobject * /*mask*/, const Pobject * /*reference*/ ) {
00130             return this; 
00131          } 
00132 
00139          Errc LoadAttributes( FILE* /*df*/ ) {
00140             return SUCCESS;
00141          }
00142 
00148          Errc SaveAttributes( FILE* /*df*/ ) const {
00149             return SUCCESS;
00150          }
00151    };
00152 
00167    class Dimension1d: public Dimension {
00168       public:
00170          Long w;
00171 
00177          Typobj Type() const { return Po_Dimension1d; } 
00178    
00183          std::string Name() const { return TypeName< Dimension1d >::Name(); }
00184 
00188          Dimension1d(): Dimension(), w(0) {}
00189    
00194          Dimension1d( Long width ): Dimension(), w(width) {}
00195 
00200          Dimension1d( const Dimension1d& d ): Dimension(), w(d.w) {}
00201 
00207          const Dimension1d& operator=( const Dimension1d& d ) {
00208             w = d.w;
00209             return *this;
00210          }
00211 
00217          bool operator==( const Dimension1d& d ) const {
00218             return d.w == w;
00219          }
00220 
00226          bool operator!=( const Dimension1d& d ) const {
00227             return !(d == *this);
00228          }
00229 
00236          Dimension1d operator+( int x ) const {
00237             return Dimension1d(w + x);
00238          }
00239 
00246          Dimension1d operator-( int x ) const {
00247             return Dimension1d(w - x);
00248          }
00249 
00256          Dimension1d operator*( int x ) const {
00257             return Dimension1d(w * x);
00258          }
00259 
00266          Dimension1d operator/( int x ) const {
00267             return Dimension1d(w / x);
00268          }
00269          
00273          Pobject* Clone() const {
00274             return new Dimension1d(w);
00275          }   
00276 
00282          Errc LoadData( FILE *df ) {
00283             if (this->Fdecode(&w, sizeof(w), 1, df) < 1) {
00284                return FAILURE;
00285             }
00286             return SUCCESS;
00287          }
00288   
00294          Errc SaveData( FILE *df ) const {
00295             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00296                return FAILURE;
00297             }
00298             return SUCCESS;
00299          }
00300    };
00301 
00309    inline const Dimension1d operator*( int x, const Dimension1d &d ) {
00310       return Dimension1d(d.w * x);
00311    }
00312    
00327    class Dimension2d: public Dimension {
00328       public:
00330          Long w;
00332          Long h;
00333 
00339          Typobj Type() const { return Po_Dimension2d; } 
00340    
00345          std::string Name() const { return TypeName< Dimension2d >::Name();  }
00346 
00350          Dimension2d(): Dimension(), w(0), h(0) {}
00351 
00357          Dimension2d( Long height, Long width ): Dimension(), w(width), h(height) {}
00358 
00363          Dimension2d( const Dimension2d& d ): Dimension(), w(d.w), h(d.h) {}
00364 
00370          const Dimension2d& operator=( const Dimension2d& d ) {
00371             w = d.w;
00372             h = d.h;
00373 
00374             return *this;
00375          }
00376    
00382          bool operator==( const Dimension2d& d ) const {
00383             return  d.w == w && d.h == h;
00384          }
00385 
00391          bool operator!=( const Dimension2d& d ) const {
00392             return !(d == *this);
00393          }
00394    
00401          Dimension2d operator+( int x ) const {
00402             return Dimension2d(h + x, w + x);
00403          }
00404    
00411          Dimension2d operator-( int x ) const {
00412             return Dimension2d(h - x, w - x);
00413          }
00414 
00421          Dimension2d operator*( int x ) const {
00422             return Dimension2d(h * x, w * x);
00423          }
00424    
00431          Dimension2d operator/( int x ) const {
00432             return Dimension2d(h / x, w / x);
00433          }
00434 
00438          Pobject* Clone() const {
00439             return new Dimension2d(h, w);
00440          }   
00441    
00447          Errc LoadData( FILE *df ) {
00448             if (Fdecode(&h, sizeof(h), 1, df) < 1) {
00449                return FAILURE;
00450             }
00451             if (Fdecode(&w, sizeof(w), 1, df) < 1) {
00452                return FAILURE;
00453             }
00454             return SUCCESS;
00455          }
00456 
00462          Errc SaveData( FILE *df ) const {
00463             if (this->Fencode(&h, sizeof(h), 1, df) < 1) {
00464                return FAILURE;
00465             }
00466             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00467                return FAILURE;
00468             }
00469             return SUCCESS;
00470          }
00471    };
00472 
00480    inline const Dimension2d operator*( int x, const Dimension2d &d ) {
00481       return Dimension2d(d.h * x, d.w * x);
00482    }
00483    
00498    class Dimension3d: public Dimension {
00499       public:
00501          Long d;
00503          Long h;
00505          Long w;
00506 
00512          Typobj Type() const { return Po_Dimension3d; } 
00513    
00518          std::string Name() const { return TypeName< Dimension3d >::Name(); }
00519 
00524          Dimension3d(): Dimension(), d(0), h(0), w(0) {}
00525 
00532          Dimension3d( Long depth, Long height, Long width ): Dimension(), d(depth), h(height), w(width) {}
00533 
00538          Dimension3d( const Dimension3d &d ): Dimension(), d(d.d), h(d.h), w(d.w) {}
00539 
00545          Dimension3d operator=( const Dimension3d &x ) {
00546             w = x.w; h = x.h; d = x.d;
00547             return *this;
00548          }
00549    
00555          bool operator==( const Dimension3d &x ) const{
00556             return x.w == w && x.h == h && x.d == d;
00557          }
00558    
00564          bool operator!=( const Dimension3d &x ) const {
00565             return !(x == *this);
00566          }
00567    
00574          Dimension3d operator+( int x ) const {
00575             return Dimension3d(d + x, h + x, w + x);
00576          }
00577    
00584          Dimension3d operator-( int x ) const {
00585             return Dimension3d(d - x, h - x, w - x);
00586          }
00587 
00594          Dimension3d operator*( int x ) const {
00595             return Dimension3d(d * x, h * x, w * x);
00596          }
00597          
00604          Dimension3d operator/( int x ) const {
00605             return Dimension3d(d / x, h / x, w / x);
00606          }
00607 
00611          Pobject* Clone() const {
00612             return new Dimension3d(d, h, w);
00613          }
00614 
00620          Errc LoadData( FILE *df ) {
00621             if (this->Fdecode(&d, sizeof(d), 1, df) < 1) {
00622                return FAILURE;
00623             }
00624             if (this->Fdecode(&h, sizeof(h), 1, df) < 1) {
00625                return FAILURE;
00626             }
00627             if (this->Fdecode(&w, sizeof(w), 1, df) < 1) {
00628                return FAILURE;
00629             }
00630             return SUCCESS;
00631          }
00632 
00638          Errc SaveData( FILE *df ) const {
00639             if (this->Fencode(&d, sizeof(d), 1, df) < 1) {
00640                return FAILURE;
00641             }
00642             if (this->Fencode(&h, sizeof(h), 1, df) < 1) {
00643                return FAILURE;
00644             }
00645             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00646                return FAILURE;
00647             }
00648             return SUCCESS;
00649          }
00650    };
00651 
00659    inline const Dimension3d operator*( int x, const Dimension3d &d ) {
00660       return Dimension3d(d.d * x, d.h * x, d.w * x);
00661    }
00662 
00663 } //End of pandore:: namespace
00664 
00665 #endif // __PDIMENSIONH__

The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 19 June 2015