FDO API Reference Feature Data Objects

RestrictedNamedCollection.h

Go to the documentation of this file.
00001 #ifndef _RESTRICTEDNAMEDCOLLECTION_H_
00002 #define _RESTRICTEDNAMEDCOLLECTION_H_
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 /// \brief
00027 /// FdoRestrictedNamedCollection is an abstract template class that can be
00028 /// wrapped around a base collection of type specified by the BASECOLLECTION 
00029 /// template argument. However, the members of this collection are restricted 
00030 /// to being of a subtype of the type of members allowed in the base 
00031 /// collection. The subtype is specified by the SUBOBJ template argument. 
00032 ///
00033 /// Any class deriving from this template must also defined a:
00034 ///
00035 ///    SUBOBJ* DownCast(BASEOBJ* value )
00036 ///
00037 /// function, which must cast the member of the base type to the subtype. It is recommended
00038 /// that static_cast be used, when possible, to perform the down cast.
00039 ///
00040 /// \note
00041 /// BASEOBJ must match the item class for BASECOLLECTION. 
00042 template <class BASEOBJ, class SUBOBJ, class BASECOLLECTION> class FdoRestrictedNamedCollection : public FdoIDisposable
00043 {
00044 protected:
00045     FdoRestrictedNamedCollection() {}
00046     FdoRestrictedNamedCollection( BASECOLLECTION* baseCollection )
00047     {
00048         m_collection = FDO_SAFE_ADDREF(baseCollection);
00049     }
00050 
00051 public:
00052 
00053     /// \brief
00054     /// Gets the number of items in the collection.
00055     /// 
00056     /// \return
00057     /// Returns number of items in the collection
00058     /// 
00059     virtual FdoInt32 GetCount() const
00060     {
00061         return m_collection->GetCount();
00062     }
00063 
00064     /// \brief
00065     /// Gets the item in the collection at the specified index. Throws an invalid argument exception if the index is out of range.
00066     /// 
00067     /// \param index 
00068     /// Input index
00069     /// 
00070     /// \return
00071     /// Returns the item in the collection at the specified index
00072     /// 
00073     virtual SUBOBJ* GetItem(FdoInt32 index) const
00074     {
00075         return DownCast(m_collection->GetItem(index));
00076     }
00077 
00078     /// \brief
00079     /// Gets an item by name. Throws an invalid argument exception if 
00080     /// the item is not in this collection
00081     /// 
00082     /// \param name 
00083     /// Input item name
00084     /// 
00085     /// \return
00086     /// Returns the item in the collection with the specified name
00087     /// 
00088     virtual SUBOBJ* GetItem(const wchar_t* name) const
00089     {
00090         return DownCast(m_collection->GetItem(name));
00091     }
00092 
00093     /// \brief
00094     /// Gets an item by name.
00095     /// 
00096     /// \param name 
00097     /// Input item name
00098     /// 
00099     /// \return
00100     /// Returns the item in the collection with the specified name.
00101     /// Returns NULL if the item is not in this collection.
00102     /// 
00103     ///  
00104     virtual SUBOBJ* FindItem(const wchar_t* name) const
00105     {
00106         return DownCast(m_collection->FindItem(name));
00107     }
00108 
00109     /// \brief
00110     /// Sets the item in the collection at the specified index to the specified value. Throws an invalid argument exception if the index is out of range.
00111     /// 
00112     /// \param index 
00113     /// Input index
00114     /// \param value 
00115     /// Input value
00116     /// 
00117     /// \return
00118     /// Returns nothing
00119     /// 
00120     virtual void SetItem(FdoInt32 index, SUBOBJ* value)
00121     {
00122         m_collection->SetItem(index, value);
00123     }
00124 
00125     /// \brief
00126     /// Adds the specified item to the end of the collection. Returns the index of the newly added item.
00127     /// 
00128     /// \param value 
00129     /// Input value
00130     /// 
00131     /// \return
00132     /// Returns the index of the newly added item
00133     /// 
00134     virtual FdoInt32 Add(SUBOBJ* value)
00135     {
00136         return m_collection->Add(value);
00137     }
00138 
00139     /// \brief
00140     /// Inserts the specified item at the specified index within the collection. 
00141     /// Items following the insertion point are moved down to accommodate the new item. 
00142     /// Throws an invalid argument exception if the specified index is out of range.
00143     /// 
00144     /// \param index 
00145     /// Input index
00146     /// \param value 
00147     /// Input value
00148     /// 
00149     /// \return
00150     /// Returns nothing
00151     /// 
00152     virtual void Insert(FdoInt32 index, SUBOBJ* value)
00153     {
00154         m_collection->Insert(index, value );
00155     }
00156 
00157     /// \brief
00158     /// Removes all items from the collection.
00159     /// 
00160     /// \return
00161     /// Returns nothing
00162     /// 
00163     virtual void Clear()
00164     {
00165         m_collection->Clear();
00166     }
00167 
00168     /// \brief
00169     /// Removes the specified item from the collection. Throws an invalid argument exception if the item does not exist within the collection.
00170     /// 
00171     /// \param value 
00172     /// Input value
00173     /// 
00174     /// \return
00175     /// Returns nothing
00176     /// 
00177     virtual void Remove(const SUBOBJ* value)
00178     {
00179         m_collection->Remove(value);
00180     }
00181 
00182     /// \brief
00183     /// Removes the specified item from the collection. Throws an invalid argument exception if the item does not exist within the collection.
00184     /// 
00185     /// \param index 
00186     /// Input index
00187     /// 
00188     /// \return
00189     /// Returns nothing
00190     /// 
00191     virtual void RemoveAt(FdoInt32 index)
00192     {
00193         m_collection->RemoveAt(index);
00194     }
00195 
00196     /// \brief
00197     /// Returns true if the collection contains the specified item, false otherwise.
00198     /// 
00199     /// \param value 
00200     /// Input value
00201     /// 
00202     /// \return
00203     /// Returns true if the collection contains the specified item, false otherwise
00204     /// 
00205     virtual bool Contains(const SUBOBJ* value) const
00206     {
00207         return m_collection->Contains(value);
00208     }
00209 
00210     /// \brief
00211     /// Returns the index of the specified item in the collection or -1 if the item does not exist.
00212     /// 
00213     /// \param value 
00214     /// Input value
00215     /// 
00216     /// \return
00217     /// Returns the index of the specified item in the collection or -1 if the item does not exist
00218     /// 
00219     virtual FdoInt32 IndexOf(const SUBOBJ* value) const
00220     {
00221         return m_collection->IndexOf(value);
00222     }
00223 
00224     /// \brief
00225     /// Returns a read only pointer to the base collection
00226     /// 
00227     /// \return
00228     /// Returns const BASECOLLECTION*
00229     /// 
00230     virtual const BASECOLLECTION* GetBaseCollection()
00231     {
00232         return (const BASECOLLECTION*) m_collection;
00233     }
00234 
00235 protected:
00236     /// Downcasts an item from the Base to the SubType.
00237     virtual SUBOBJ* DownCast( BASEOBJ* value ) const = 0;
00238 
00239 private:
00240 
00241     FdoPtr<BASECOLLECTION > m_collection;
00242 
00243 };
00244 #endif
00245 
00246 

Comments or suggestions? Send us feedback.