DataElementGroup.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef DATA_ELEMENT_GROUP
00011 #define DATA_ELEMENT_GROUP
00012 
00013 #include "DataElement.h"
00014 
00015 #include <vector>
00016 
00017 /**
00018  *  Provides for associations of DataElements.
00019  *  
00020  *  A data element group stores a list of DataElements. It assumes 
00021  *  ownership of the elements added to it, meaning that when the group is
00022  *  destroyed, all elements currently contained in the group will also be
00023  *  destroyed.
00024  *
00025  *  If a DataElement that has been added to the group is destroyed via
00026  *  ModelServices, the group will be notified and will remove the element
00027  *  from its internal tracking. This will trigger a notification of a change to the
00028  *  group.
00029  *
00030  *  This subclass of Subject will notify upon the following conditions:
00031  *    - An element or group of elements is added to the group
00032  *    - An element or group of elements is removed from the group
00033  *    - Other notifications documented in the DataElement and Subject classes.
00034  *
00035  *  @see     DataElement
00036  */
00037 class DataElementGroup : public DataElement
00038 {
00039 public:
00040    /**
00041     *  Emitted with any<DataElement*> when a member element is externally deleted.
00042     */
00043    SIGNAL_METHOD(DataElementGroup, ElementDeleted)
00044 
00045    /**
00046     *  Adds an element to the group. It is possible to add the same element to
00047     *  the group multiple times. If uniformity is being enforced and the element
00048     *  is of a different type from the elements already in the group, the method
00049     *  will fail. The method will also fail if pElement is NULL.
00050     *
00051     *  @param   pElement
00052     *           A pointer to the element to add to the group
00053     *
00054     *  @return  true if the element was added to the group, otherwise false.
00055     *
00056     *  @notify  Subject::signalModified
00057     *
00058     *  @see     enforceUniformity()
00059     */
00060    virtual bool insertElement(DataElement* pElement) = 0;
00061 
00062    /**
00063     *  Add several elements to the group. It is possible to add the same element
00064     *  to the group multiple times.
00065     *
00066     *  This method adds several elements to the group. If any of the elements to
00067     *  add are NULL, the method will fail, having done nothing. If uniformity is
00068     *  being enforced and any of the elements to add are of a different type
00069     *  from the elements in the group or each other, the method will fail,
00070     *  having done nothing.
00071     *
00072     *  @param   elements
00073     *           A vector of elements to add to the group
00074     *
00075     *  @return  true if the elements were added, otherwise false.
00076     *
00077     *  @notify  Subject::signalModified after the 
00078     *           elements are done being added to the list. Only one notification 
00079     *           will be done. No notification will be done if elements is empty.
00080     *
00081     *  @see     enforceUniformity()
00082     */
00083    virtual bool insertElements(const std::vector<DataElement*>& elements) = 0;
00084 
00085    /**
00086     *  Checks to see if an element is in the group.
00087     *
00088     *  @param   pElement
00089     *           The element to check for.
00090     *
00091     *  @return  true if the specified element is in the group, otherwise false.
00092     */
00093    virtual bool hasElement(DataElement* pElement) const = 0;
00094 
00095    /**
00096     *  Counts the elements in the group.
00097     *
00098     *  @return  the number of elements in the group.
00099     */
00100    virtual unsigned int getNumElements() const = 0;
00101 
00102    /**
00103     *  Gets the list of elements in the group. The elements are not guaranteed
00104     *  to be in any particular order.
00105     *
00106     *  @return  the list of elements in the group.
00107     */
00108    virtual const std::vector<DataElement*>& getElements() const = 0;
00109 
00110    /**
00111     *  Removes an element from the group, optionally deleting it as well.
00112     *
00113     *  @param   pElement
00114     *           A pointer to the element to remove from the group
00115     *
00116     *  @param   bDelete
00117     *           Specifies if the element should be destroyed as well as being 
00118     *           removed from the group. If the element is not found in the 
00119     *           group it will not be deleted, regardless of the value of this 
00120     *           parameter.
00121     *
00122     *  @return  true if the element was in the group, otherwise false.
00123     *
00124     *  @notify  Subject::signalModified after the 
00125     *           element is removed from the list.
00126     */
00127    virtual bool removeElement(DataElement* pElement, bool bDelete = false) = 0;
00128 
00129    /**
00130     *  Removes several elements from the group.
00131     *
00132     *  This method removes several elements from the group, optionally deleting
00133     *  them in the process. If the list of elements to remove contains elements
00134     *  not in the group, those elements will be ignored.
00135     *
00136     *  @param   elements
00137     *           A vector of elements to remove from the group
00138     *
00139     *  @param   bDelete
00140     *           Specifies if the elements should be destroyed as well as being 
00141     *           removed from the group. Elements not found in the group will
00142     *           not be deleted regardless of the value of this parameter.
00143     *
00144     *  @return  Returns \c true if the list of elements to remove was not empty
00145     *           and all of the specified elements were found in the group;
00146     *           otherwise returns \c false.
00147     *
00148     *  @notify  Subject::signalModified after the 
00149     *           elements are done being removed from the list. Only one 
00150     *           notification will be done.
00151     */
00152    virtual bool removeElements(const std::vector<DataElement*>& elements, bool bDelete = false) = 0;
00153 
00154    /**
00155     *  Removes all of the elements from the group.
00156     *
00157     *  This method removes all of the elements from the group, optionally deleting
00158     *  them in the process.
00159     *
00160     *  @param   bDelete
00161     *           Specifies if the elements should be destroyed as well as being 
00162     *           removed from the group.
00163     *
00164     *  @notify  Subject::signalModified after the elements are
00165     *           done being removed from the group if the group was not empty.
00166     *           At most one notification will be done.
00167     */
00168    virtual void clear(bool bDelete = false) = 0;
00169 
00170    /**
00171     *  Specifies whether all elements added to a group must be of the same type.
00172     *
00173     *  This method specifies whether all elements in a group must be of the same
00174     *  type. If the group already has elements of varying types in it when this 
00175     *  method is called to turn on enforcement, it will fail to turn on enforcement. 
00176     *  When uniformity is enforced, addElement and addElements will fail to 
00177     *  add elements of types different from the type of the elements already 
00178     *  in the group. The default for a new DataElementGroup is for enforcement
00179     *  of uniformity to be off.
00180     *
00181     *  @param   enforce
00182     *           Specifies if enforcement is being turned on or off
00183     *
00184     *  @return  true if the enforcement setting was successfully set. It will
00185     *           always succeed in turning uniformity enforcement off. If 
00186     *           enforcement is being turned on and there are already elements
00187     *           of varying types in the group, it will fail and return false.
00188     */
00189    virtual bool enforceUniformity(bool enforce) = 0;
00190 
00191    /**
00192     *  Indicates if all of the elements in the group are of the same type.
00193     *
00194     *  @return  true if the group is empty or all elements in the group are of
00195     *           the same type, false otherwise.
00196     */
00197    virtual bool isUniform() const = 0;
00198 
00199 protected:
00200    /**
00201     * This should be destroyed by calling ModelServices::destroyElement.
00202     */
00203    virtual ~DataElementGroup() {}
00204 };
00205 
00206 #endif

Software Development Kit - Opticks 4.9.0 Build 16218