library of assembled shared sources

http://lass.cocamware.com

xy.cpp

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 #include "prim_common.h"
00046 #include "xy.h"
00047 
00048 namespace lass
00049 {
00050 namespace prim
00051 {
00052 
00053 /** intializes iterator to @a x axis.
00054  */
00055 XY::XY():
00056     value_(0)
00057 {
00058 }
00059 
00060 
00061 
00062 
00063 /** initializes iterator to an axis by character: 'x' or 'y'.
00064  */
00065 XY::XY(char iAxis)
00066 {
00067     reset(iAxis);
00068 }
00069 
00070 
00071 
00072 /** initializes iterator to an axis by number.
00073  *  ..., -1 == @a y, 0 == @a x, 1 == @a y, 2 == @a x, ...
00074  */
00075 XY::XY(int iValue):
00076     value_(iValue)
00077 {
00078 }
00079 
00080 
00081 
00082 /** initializes iterator to an axis by character: "x" or "y".
00083  */
00084 XY::XY(const std::string& iAxis)
00085 {
00086     if (iAxis.length() != 1)
00087     {
00088         LASS_THROW("Invalid parameter iAxis '" << iAxis << "'.  It must be a single character.");
00089     }
00090     reset(iAxis[0]);
00091 }
00092 
00093 
00094 
00095 /** return axis by character: "x" or "y".
00096  */
00097 const char XY::axis() const
00098 {
00099     LASS_ASSERT(value_ >= 0 && value_ < dimension);
00100     const char axes[] = { 'x', 'y' };
00101     return axes[value_];
00102 }
00103 
00104 
00105 
00106 XY& XY::operator++()
00107 {
00108     LASS_ASSERT(value_ >= 0 && value_ < dimension);
00109     ++value_;
00110     return *this;
00111 }
00112 
00113 
00114 
00115 XY& XY::operator--()
00116 {
00117     LASS_ASSERT(value_ >= 0 && value_ < dimension);
00118     --value_;
00119     return *this;
00120 }
00121 
00122 
00123 
00124 XY XY::operator++(int)
00125 {
00126     XY result(*this);
00127     ++*this;
00128     return result;
00129 }
00130 
00131 
00132 
00133 XY XY::operator--(int)
00134 {
00135     XY result(*this);
00136     --*this;
00137     return result;
00138 }
00139 
00140 
00141 
00142 XY& XY::operator+=(int iOffset)
00143 {
00144     value_ += iOffset;
00145     return *this;
00146 }
00147 
00148 
00149 
00150 XY& XY::operator-=(int iOffset)
00151 {
00152     value_ -= iOffset;
00153     return *this;
00154 }
00155 
00156 
00157 
00158 
00159 // --- protected -----------------------------------------------------------------------------------
00160 
00161 
00162 
00163 // --- private -------------------------------------------------------------------------------------
00164 
00165 inline void XY::reset(char iAxis)
00166 {
00167     switch (iAxis)
00168     {
00169     case 0:
00170     case 'x':
00171     case 'X':
00172         value_ = 0;
00173         break;
00174 
00175     case 1:
00176     case 'y':
00177     case 'Y':
00178         value_ = 1;
00179         break;
00180 
00181     default:
00182         LASS_THROW("Invalid parameter iAxis '" << iAxis << "'.  Try 'x', 'X', 'y' or 'Y'.");
00183     }
00184 }
00185 
00186 
00187 
00188 // --- free ----------------------------------------------------------------------------------------
00189 
00190 /** @relates lass::prim::XY
00191  */
00192 bool operator==(const XY& iA, const XY& iB)
00193 {
00194     return iA.value_ == iB.value_;
00195 }
00196 
00197 
00198 
00199 /** @relates lass::prim::XY
00200  */
00201 bool operator==(const XY& iA, char iB)
00202 {
00203     return iA.axis() == iB;
00204 }
00205 
00206 
00207 
00208 /** @relates lass::prim::XY
00209  */
00210 bool operator==(char iA, const XY& iB)
00211 {
00212     return iA == iB.axis();
00213 }
00214 
00215 
00216 
00217 /** @relates lass::prim::XY
00218  */
00219 bool operator==(const XY& iA, const std::string& iB)
00220 {
00221     return std::string(1, iA.axis()) == iB;
00222 }
00223 
00224 
00225 
00226 /** @relates lass::prim::XY
00227  */
00228 bool operator==(const std::string& iA, const XY& iB)
00229 {
00230     return iA == std::string(1, iB.axis());
00231 }
00232 
00233 
00234 
00235 
00236 /** @relates lass::prim::XY
00237  */
00238 bool operator!=(const XY& iA, const XY& iB)
00239 {
00240     return !(iA == iB);
00241 }
00242 
00243 
00244 
00245 
00246 /** @relates lass::prim::XY
00247  */
00248 bool operator!=(const XY& iA, char iB)
00249 {
00250     return !(iA == iB);
00251 }
00252 
00253 
00254 
00255 
00256 /** @relates lass::prim::XY
00257  */
00258 bool operator!=(char iA, const XY& iB)
00259 {
00260     return !(iA == iB);
00261 }
00262 
00263 
00264 
00265 
00266 /** @relates lass::prim::XY
00267  */
00268 bool operator!=(const XY& iA, const std::string& iB)
00269 {
00270     return !(iA == iB);
00271 }
00272 
00273 
00274 
00275 
00276 /** @relates lass::prim::XY
00277  */
00278 bool operator!=(const std::string& iA, const XY& iB)
00279 {
00280     return !(iA == iB);
00281 }
00282 
00283 
00284 
00285 /** @relates lass::prim::XY
00286  */
00287 XY operator+(const XY& iA, int iOffset)
00288 {
00289     XY result(iA);
00290     result += iOffset;
00291     return result;
00292 }
00293 
00294 
00295 
00296 /** @relates lass::prim::XY
00297  */
00298 XY operator-(const XY& iA, int iOffset)
00299 {
00300     XY result(iA);
00301     result -= iOffset;
00302     return result;
00303 }
00304 
00305 
00306 
00307 }
00308 
00309 }
00310 
00311 // EOF

Generated on Mon Nov 10 14:22:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo