- Main Page
- Related Pages
- Modules
- Classes
- Files

# ReadOnlyCollection.h

Go to the documentation of this file.

    00001 #ifndef _READONLYCOLLECTION_H_
    00002 #define _READONLYCOLLECTION_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 #include <FdoStd.h>
    00026
    00027 /// \brief
    00028 /// FdoReadOnlyCollection is an abstract template class used to define a collection
    00029 /// that can not be modified after it is constructed, i.e. provides read-only access.
    00030 template <class OBJ, class BASE, class EXC> class FdoReadOnlyCollection : public FdoIDisposable
    00031 {
    00032 protected:
    00033     FDO_API FdoReadOnlyCollection()
    00034     {
    00035     }
    00036
    00037     FDO_API virtual ~FdoReadOnlyCollection()
    00038     {
    00039         FDO_SAFE_RELEASE(m_base);
    00040     }
    00041
    00042     void SetBaseCollection(BASE* base)
    00043     {
    00044         FDO_SAFE_ADDREF(base);
    00045         m_base = base;
    00046     }
    00047
    00048 public:
    00049     /// \brief
    00050     /// Gets the number of items in the collection.
    00051     ///
    00052     /// \return
    00053     /// Returns number of items in the collection
    00054     ///
    00055     FDO_API virtual FdoInt32 GetCount()
    00056     {
    00057         if (m_base)
    00058             return m_base->GetCount();
    00059         else
    00060             return 0;
    00061     }
    00062
    00063     /// \brief
    00064     /// Gets the item in the collection at the specified index. Throws an invalid argument exception if the index is out of range.
    00065     ///
    00066     /// \param index
    00067     /// Input index
    00068     ///
    00069     /// \return
    00070     /// Returns the item in the collection at the specified index
    00071     ///
    00072     FDO_API virtual OBJ* GetItem(FdoInt32 index)
    00073     {
    00074         if (m_base)
    00075             return (OBJ*)m_base->GetItem(index);
    00076         else
    00077             throw EXC::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_INDEXOUTOFBOUNDS)));
    00078     }
    00079
    00080     /// \brief
    00081     /// Gets the item in the collection with the specified name. Throws an invalid argument exception if an item with the specified name does not exist in the collection.
    00082     ///
    00083     /// \param name
    00084     /// Input name to find
    00085     ///
    00086     /// \return
    00087     /// Returns the item in the collection with the specified name
    00088     ///
    00089     FDO_API virtual OBJ* GetItem(FdoString* name)
    00090     {
    00091         if (name == NULL)
    00092             throw EXC::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_1_BADPARAMETER)));
    00093
    00094         FdoInt32    size = GetCount();
    00095         for (FdoInt32 i = 0; i < size; i++)
    00096         {
    00097             OBJ* pitem = GetItem(i);
    00098             if (pitem != NULL && pitem->GetName() != NULL && wcscmp(name, pitem->GetName()) == 0)
    00099                 return pitem;
    00100             FDO_SAFE_RELEASE(pitem);
    00101         }
    00102         throw EXC::Create(FdoException::NLSGetMessage(FDO_NLSID(SCHEMA_5_INVALIDELEMENTNAME)));
    00103     }
    00104
    00105     /// \brief
    00106     /// Returns true if the collection contains the specified item, false otherwise.
    00107     ///
    00108     /// \param value
    00109     /// Input value
    00110     ///
    00111     /// \return
    00112     /// Returns true if the collection contains the specified item, false otherwise
    00113     ///
    00114     FDO_API virtual bool Contains(const OBJ* value)
    00115     {
    00116         if (m_base)
    00117             return m_base->Contains(value);
    00118         else
    00119             return false;
    00120     }
    00121
    00122     /// \brief
    00123     /// Returns the index of the specified item in the collection or -1 if the item does not exist.
    00124     ///
    00125     /// \param value
    00126     /// Input value
    00127     ///
    00128     /// \return
    00129     /// Returns the index of the specified item in the collection or -1 if the item does not exist
    00130     ///
    00131     FDO_API virtual FdoInt32 IndexOf(const OBJ* value)
    00132     {
    00133         if (m_base)
    00134             return m_base->IndexOf(value);
    00135         else
    00136             return -1;
    00137     }
    00138
    00139 private:
    00140     BASE*   m_base;
    00141 };
    00142 #endif
    00143
    00144

Please send us your comment about this page