FDO API Reference Feature Data Objects

Vector.h

Go to the documentation of this file.
00001 #ifndef FDO_VECTOR_H
00002 #define FDO_VECTOR_H        1
00003 // 
00004 
00005 //
00006 // Copyright (C) 2004-2006  Autodesk, Inc.
00007 // 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of version 2.1 of the GNU Lesser
00010 // General Public License as published by the Free Software Foundation.
00011 // 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // Lesser General Public License for more details.
00016 // 
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this library; if not, write to the Free Software
00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 //
00021 
00022 #ifdef _WIN32
00023 #pragma once
00024 #endif
00025 
00026 #include <Common/Collection.h>
00027 
00028 /// \brief
00029 /// An element in a vector.
00030 /// This class is just a ref-countable wrapper around a double.
00031 class FdoVectorElement : public FdoDisposable
00032 {
00033 public:
00034     /// \brief
00035     /// Creates a vector element.
00036     /// 
00037     /// \param value 
00038     /// Input the value to assign the element
00039     /// 
00040     /// \return
00041     /// Returns FdoProviderNameTokens
00042     /// 
00043     FDO_API_COMMON static FdoVectorElement* Create( double value )
00044     {
00045         return new FdoVectorElement(value);
00046     }
00047 
00048     /// \brief
00049     /// Gets the element value.
00050     /// 
00051     /// \return
00052     /// Returns the value that this element represents.
00053     /// 
00054     FDO_API_COMMON double  GetValue()
00055     {
00056         return mValue;
00057     }
00058 
00059     /// \brief
00060     /// Sets the element value.
00061     /// 
00062     /// \param value 
00063     /// Input the value to assign the element
00064     /// 
00065     FDO_API_COMMON void SetValue( double value ) 
00066     {
00067         mValue = value;
00068     }
00069 
00070     /// \brief
00071     /// Gets the element value in string format.
00072     /// 
00073     /// \return
00074     /// Returns the value that this element represents.
00075     /// 
00076     FDO_API_COMMON FdoStringP GetString();
00077 
00078 protected:
00079 /// \cond DOXYGEN-IGNORE
00080     FdoVectorElement() {}
00081     FdoVectorElement( double value )
00082     {
00083         mValue = value;
00084     }
00085 
00086     virtual ~FdoVectorElement(void)
00087     {
00088     }
00089 /// \endcond
00090 
00091 private:
00092     double mValue;
00093 };
00094 
00095 typedef FdoPtr<FdoVectorElement> FdoVectorElementP;
00096 
00097 /// \brief
00098 /// FdoVector is a one-dimensional collection of numbers.
00099 class FdoVector : public FdoCollection<FdoVectorElement,FdoException>
00100 {
00101 public:
00102     /// \brief
00103     /// Constructs a new empty vector
00104     /// 
00105     /// \return
00106     /// Returns FdoVector
00107     /// 
00108     FDO_API_COMMON static FdoVector* Create(void);
00109 
00110     /// \brief
00111     /// Creates a copy of a vector
00112     /// 
00113     /// \param src 
00114     /// Input pointer to the source vector
00115     /// 
00116     /// \return
00117     /// Returns FdoVector
00118     /// 
00119     FDO_API_COMMON static FdoVector* Create( const FdoVector* src);
00120 
00121     /// \brief
00122     /// Creates a vector that is tokenize from a string.
00123     /// The vector contains an element for each token. Non-numberic tokens
00124     /// become 0.0.
00125     /// 
00126     /// \param inString 
00127     /// Input the string to tokenize.
00128     /// \param delimiters 
00129     /// Input list of single character token delimiters.
00130     /// \param bNullTokens 
00131     /// true: include zero-length tokens in the vector ( as 0.0 ).
00132     /// false: exclude zero-length tokens
00133     /// 
00134     /// \return
00135     /// Returns FdoVector
00136     /// 
00137     FDO_API_COMMON static FdoVector* Create( const FdoStringP& inString, const FdoString* delimiters, bool bNullTokens = false );
00138 
00139     /// \brief
00140     /// Gets the number in the vector at the specified index. Throws an invalid argument exception if the index is out of range.
00141     /// 
00142     /// \param index 
00143     /// Input index
00144     /// 
00145     /// \return
00146     /// Returns the number in the vector at the specified index
00147     /// 
00148     FDO_API_COMMON double GetValue(int index) const;
00149 
00150     /// \brief
00151     /// Appends the numbers from src to the end of this vector.
00152     /// 
00153     /// \param src 
00154     /// Input the source collection
00155     /// 
00156     FDO_API_COMMON void Append( const FdoVector* src);
00157 
00158     /// \brief
00159     /// Adds a number to the end of this vector.
00160     /// 
00161     /// \param src 
00162     /// Input the source collection
00163     /// 
00164     FDO_API_COMMON int Add( double value );
00165 
00166     /// \brief
00167     /// Concatenates the numbers in this collection.
00168     /// 
00169     /// \param separator 
00170     /// Input separate each collection number with this separator string.
00171     /// 
00172     /// \return
00173     /// Returns the concatenation of all numbers in this vector, 
00174     /// separated by the given separator..
00175     /// 
00176     FDO_API_COMMON FdoStringP ToString( const FdoString* separator = L", " );
00177 
00178 protected:
00179 /// \cond DOXYGEN-IGNORE
00180     FdoVector(void);
00181     FdoVector( const FdoVector* src);
00182     FdoVector( const FdoStringP& inString, const FdoString* delimiters, bool bNullTokens = false );
00183 
00184     virtual ~FdoVector(void);
00185 /// \endcond
00186 
00187     FDO_API_COMMON virtual void Dispose()
00188     {
00189         delete this;
00190     }
00191 
00192 private:
00193 };
00194 
00195 /// \brief
00196 /// FdoVectorP is a FdoPtr on FdoVector, provided for convenience. It
00197 /// also provides vector arithmetic and comparison operators.
00198 class FdoVectorP : public FdoPtr<FdoVector>
00199 {
00200 public:
00201     /// \brief
00202     /// Vector FdoPtr default constructor
00203     /// 
00204     /// \return
00205     /// Returns FdoVectorP
00206     /// 
00207     FDO_API_COMMON FdoVectorP() {}
00208 
00209     /// \brief
00210     /// Vector FdoPtr copy constructor
00211     /// 
00212     /// \param src 
00213     /// Input the source vector as a FdoPtr
00214     /// 
00215     /// \return
00216     /// Returns FdoVectorP
00217     /// 
00218     FDO_API_COMMON FdoVectorP( const FdoVectorP& src ) 
00219         : FdoPtr<FdoVector>(src)
00220     {}
00221 
00222     /// \brief
00223     /// Vector FdoPtr copy constructor
00224     /// 
00225     /// \param src 
00226     /// Input the source vector as an object pointer
00227     /// 
00228     /// \return
00229     /// Returns FdoVectorP
00230     /// 
00231     FDO_API_COMMON FdoVectorP( FdoVector* src )
00232         : FdoPtr<FdoVector>(src)
00233     {}
00234 
00235     /// \brief
00236     /// Vector FdoPtr destructor
00237     /// 
00238     FDO_API_COMMON ~FdoVectorP() {}
00239 
00240     /// \brief
00241     /// Copies a vector
00242     /// 
00243     /// \param src 
00244     /// Input the source vector
00245     /// 
00246     /// \return
00247     /// Returns a new copy of the input vector
00248     /// 
00249     FDO_API_COMMON FdoVector* operator=( FdoVector* src ); 
00250 
00251     /// \brief
00252     /// Adds two vectors, by adding each individual element. The output vector has
00253     /// the same length as the longer of the input vectors. If one input
00254     /// vector is shorter than the other, it is treated as if it 
00255     /// is padded with zeros.
00256     /// 
00257     /// \param vec2 
00258     /// Input vector to add to this vector
00259     /// 
00260     /// \return
00261     /// Returns the sum of the two input vectors
00262     /// 
00263     FDO_API_COMMON const FdoVectorP operator+( const FdoVectorP vec2 ) const;
00264 
00265     /// \brief
00266     /// Subtracts two vectors, by subtracting each individual element. The output vector has
00267     /// the same length as the longer of the input vectors. If one input
00268     /// vector is shorter than the other, it is treated as if it 
00269     /// is padded with zeros.
00270     /// 
00271     /// \param vec2 
00272     /// Input vector to subtract from this vector
00273     /// 
00274     /// \return
00275     /// Returns the difference of the two input vectors
00276     /// 
00277     FDO_API_COMMON const FdoVectorP operator-( const FdoVectorP vec2 ) const;
00278 
00279     /// \brief
00280     /// Adds a vector, to this vector, by adding each individual element. The output vector has
00281     /// the same length as the longer of the input vectors. If one input
00282     /// vector is shorter than the other, it is treated as if it 
00283     /// is padded with zeros.
00284     /// 
00285     /// \param vec2 
00286     /// Input vector to add to this vector
00287     /// 
00288     /// \return
00289     /// Returns the sum of the two input vectors
00290     /// 
00291     FDO_API_COMMON FdoVectorP operator+=( const FdoVectorP vec2 );
00292 
00293     /// \brief
00294     /// Subtracts a vector, from this vector, by subtracting each individual element. The output vector has
00295     /// the same length as the longer of the input vectors. If one input
00296     /// vector is shorter than the other, it is treated as if it 
00297     /// is padded with zeros.
00298     /// 
00299     /// \param vec2 
00300     /// Input vector to subtract from this vector
00301     /// 
00302     /// \return
00303     /// Returns the difference of the two input vectors
00304     /// 
00305     FDO_API_COMMON FdoVectorP operator-=( const FdoVectorP vec2 );
00306 
00307     /// \brief
00308     /// Compare two vectors for equality. The vectors are equal
00309     /// if all of their elements are equal. If one vector is shorter than the other
00310     /// then it is treated as if it were padded with zeros to the length of the
00311     /// other vector.
00312     /// 
00313     /// \param vec2 
00314     /// Input vector to compare this vector
00315     /// 
00316     /// \return
00317     /// Returns true if the two vectors are identical.
00318     /// 
00319     FDO_API_COMMON FdoBoolean operator==( const FdoVectorP vec2 ) const;
00320 
00321     /// \brief
00322     /// Compare two vectors for difference. The vectors are differnt
00323     /// if one of their elements is differnt. If one vector is shorter than the other
00324     /// then it is treated as if it were padded with zeros to the length of the
00325     /// other vector.
00326     /// 
00327     /// \param vec2 
00328     /// Input vector to compare this vector
00329     /// 
00330     /// \return
00331     /// Returns true if the two vectors are different.
00332     /// 
00333     FDO_API_COMMON FdoBoolean operator!=( const FdoVectorP vec2 ) const;
00334 
00335     /// \brief
00336     /// Checks if this vector is greater than a second vector.
00337     /// Comparison is done by comparing the first element in each vector.
00338     /// If they are equal, then the second element is check and so on until
00339     /// a differing element is found. If one vector is shorter than the other
00340     /// then it is treated as if it were padded with zeros to the length of the
00341     /// other vector.
00342     /// 
00343     /// \param vec2 
00344     /// Input vector to compare this vector
00345     /// 
00346     /// \return
00347     /// Returns true if this vector is greater than vec2.
00348     /// 
00349     FDO_API_COMMON FdoBoolean operator>( const FdoVectorP vec2 ) const;
00350 
00351     /// \brief
00352     /// Checks if this vector is greater or equal to a second vector.
00353     /// Comparison is done by comparing the first element in each vector.
00354     /// If they are equal, then the second element is check and so on until
00355     /// a differing element is found. If one vector is shorter than the other
00356     /// then it is treated as if it were padded with zeros to the length of the
00357     /// other vector.
00358     /// 
00359     /// \param vec2 
00360     /// Input vector to compare this vector
00361     /// 
00362     /// \return
00363     /// Returns true if this vector is greater or equal vec2.
00364     /// 
00365     FDO_API_COMMON FdoBoolean operator>=( const FdoVectorP vec2 ) const;
00366 
00367     /// \brief
00368     /// Checks if this vector is less than a second vector.
00369     /// Comparison is done by comparing the first element in each vector.
00370     /// If they are equal, then the second element is check and so on until
00371     /// a differing element is found. If one vector is shorter than the other
00372     /// then it is treated as if it were padded with zeros to the length of the
00373     /// other vector.
00374     /// 
00375     /// \param vec2 
00376     /// Input vector to compare this vector
00377     /// 
00378     /// \return
00379     /// Returns true if this vector is less than vec2.
00380     /// 
00381     FDO_API_COMMON FdoBoolean operator<( const FdoVectorP vec2 ) const;
00382 
00383     /// \brief
00384     /// Checks if this vector is less than or equal to a second vector.
00385     /// Comparison is done by comparing the first element in each vector.
00386     /// If they are equal, then the second element is check and so on until
00387     /// a differing element is found. If one vector is shorter than the other
00388     /// then it is treated as if it were padded with zeros to the length of the
00389     /// other vector.
00390     /// 
00391     /// \param vec2 
00392     /// Input vector to compare this vector
00393     /// 
00394     /// \return
00395     /// Returns true if this vector is less than or equal vec2.
00396     /// 
00397     FDO_API_COMMON FdoBoolean operator<=( const FdoVectorP vec2 ) const;
00398 
00399 protected:
00400 /// \cond DOXYGEN-IGNORE
00401     /// General function to do the vector comparisons.
00402     FdoBoolean Compare( const FdoVectorP vec2, FdoBoolean lt, FdoBoolean eq, FdoBoolean gt ) const;
00403 /// \endcond
00404 };
00405 
00406 #endif
00407 
00408 

Comments or suggestions? Send us feedback.