library of assembled shared sources

http://lass.cocamware.com

xyz.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 "xyz.h"
00047 
00048 namespace lass
00049 {
00050 namespace prim
00051 {
00052 
00053 /** intializes iterator to @a x axis.
00054  */
00055 XYZ::XYZ():
00056     value_(0)
00057 {
00058 }
00059 
00060 
00061 
00062 /** initializes iterator to an axis by character: 'x', 'y' or 'z'.
00063  */
00064 XYZ::XYZ(char iAxis)
00065 {
00066     reset(iAxis);
00067 }
00068 
00069 
00070 
00071 /** initializes iterator to an axis by number.
00072  *  ..., -1 == @a z, 0 == @a x, 1 == @a y, 2 == @a z, 3 == @a x, ...
00073  */
00074 XYZ::XYZ(int iValue):
00075     value_(iValue)
00076 {
00077 }
00078 
00079 
00080 
00081 /** initializes iterator to an axis by character: "x", "y" or "z".
00082  */
00083 XYZ::XYZ(const std::string& iAxis)
00084 {
00085     if (iAxis.length() != 1)
00086     {
00087         LASS_THROW("Invalid parameter iAxis '" << iAxis << "'.  It must be a single character.");
00088     }
00089     reset(iAxis[0]);
00090 }
00091 
00092 
00093 
00094 /** return axis by character: "x", "y" or "z".
00095  */
00096 const char XYZ::axis() const
00097 {
00098     LASS_ASSERT(value_ >= 0 && value_ < 3);
00099     const char axes[] = { 'x', 'y', 'z' };
00100     return axes[value_];
00101 }
00102 
00103 
00104 
00105 XYZ& XYZ::operator++()
00106 {
00107     LASS_ASSERT(value_ >= 0 && value_ < dimension);
00108     ++value_;
00109     return *this;
00110 }
00111 
00112 
00113 
00114 XYZ& XYZ::operator--()
00115 {
00116     LASS_ASSERT(value_ >= 0 && value_ < dimension);
00117     --value_;
00118     return *this;
00119 }
00120 
00121 
00122 
00123 XYZ XYZ::operator++(int)
00124 {
00125     XYZ result(*this);
00126     ++*this;
00127     return result;
00128 }
00129 
00130 
00131 
00132 XYZ XYZ::operator--(int)
00133 {
00134     XYZ result(*this);
00135     --*this;
00136     return result;
00137 }
00138 
00139 
00140 
00141 XYZ& XYZ::operator+=(int iOffset)
00142 {
00143     value_ += iOffset;
00144     return *this;
00145 }
00146 
00147 
00148 
00149 XYZ& XYZ::operator-=(int iOffset)
00150 {
00151     value_ -= iOffset;
00152     return *this;
00153 }
00154 
00155 
00156 
00157 
00158 // --- protected -----------------------------------------------------------------------------------
00159 
00160 
00161 
00162 // --- private -------------------------------------------------------------------------------------
00163 
00164 inline void XYZ::reset(char iAxis)
00165 {
00166     switch (iAxis)
00167     {
00168     case 0:
00169     case 'x':
00170     case 'X':
00171         value_ = 0;
00172         break;
00173 
00174     case 1:
00175     case 'y':
00176     case 'Y':
00177         value_ = 1;
00178         break;
00179 
00180     case 2:
00181     case 'z':
00182     case 'Z':
00183         value_ = 2;
00184         break;
00185 
00186     default:
00187         LASS_THROW("Invalid parameter iAxis '" << iAxis
00188             << "'.  Try 'x', 'X', 'y', 'Y', 'z' or 'Z'.");
00189     }
00190 }
00191 
00192 
00193 
00194 // --- free ----------------------------------------------------------------------------------------
00195 
00196 /** @relates lass::prim::XYZ
00197  */
00198 bool operator==(const XYZ& iA, const XYZ& iB)
00199 {
00200     return iA.value_ == iB.value_;
00201 }
00202 
00203 
00204 
00205 /** @relates lass::prim::XYZ
00206  */
00207 bool operator==(const XYZ& iA, char iB)
00208 {
00209     return iA.axis() == iB;
00210 }
00211 
00212 
00213 
00214 /** @relates lass::prim::XYZ
00215  */
00216 bool operator==(char iA, const XYZ& iB)
00217 {
00218     return iA == iB.axis();
00219 }
00220 
00221 
00222 
00223 /** @relates lass::prim::XYZ
00224  */
00225 bool operator==(const XYZ& iA, const std::string& iB)
00226 {
00227     return std::string(1, iA.axis()) == iB;
00228 }
00229 
00230 
00231 
00232 /** @relates lass::prim::XYZ
00233  */
00234 bool operator==(const std::string& iA, const XYZ& iB)
00235 {
00236     return iA == std::string(1, iB.axis());
00237 }
00238 
00239 
00240 
00241 
00242 /** @relates lass::prim::XYZ
00243  */
00244 bool operator!=(const XYZ& iA, const XYZ& iB)
00245 {
00246     return !(iA == iB);
00247 }
00248 
00249 
00250 
00251 
00252 /** @relates lass::prim::XYZ
00253  */
00254 bool operator!=(const XYZ& iA, char iB)
00255 {
00256     return !(iA == iB);
00257 }
00258 
00259 
00260 
00261 
00262 /** @relates lass::prim::XYZ
00263  */
00264 bool operator!=(char iA, const XYZ& iB)
00265 {
00266     return !(iA == iB);
00267 }
00268 
00269 
00270 
00271 
00272 /** @relates lass::prim::XYZ
00273  */
00274 bool operator!=(const XYZ& iA, const std::string& iB)
00275 {
00276     return !(iA == iB);
00277 }
00278 
00279 
00280 
00281 
00282 /** @relates lass::prim::XYZ
00283  */
00284 bool operator!=(const std::string& iA, const XYZ& iB)
00285 {
00286     return !(iA == iB);
00287 }
00288 
00289 
00290 
00291 /** @relates lass::prim::XYZ
00292  */
00293 XYZ operator+(const XYZ& iA, int iOffset)
00294 {
00295     XYZ result(iA);
00296     result += iOffset;
00297     return result;
00298 }
00299 
00300 
00301 
00302 /** @relates lass::prim::XYZ
00303  */
00304 XYZ operator-(const XYZ& iA, int iOffset)
00305 {
00306     XYZ result(iA);
00307     result -= iOffset;
00308     return result;
00309 }
00310 
00311 
00312 
00313 }
00314 
00315 }
00316 
00317 // 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