library of assembled shared sources

http://lass.cocamware.com

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