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 HDF5ELEMENT_H 00011 #define HDF5ELEMENT_H 00012 00013 #include "Hdf5Node.h" 00014 00015 #include <map> 00016 #include <string> 00017 #include <vector> 00018 00019 class DataVariant; 00020 class Hdf5Attribute; 00021 class Hdf5Node; 00022 00023 /** 00024 * An Hdf5Element is the most basic base class of an HDF component. 00025 * 00026 * It provides access to the name of the item, as well as its attributes. 00027 */ 00028 class Hdf5Element : public Hdf5Node 00029 { 00030 public: 00031 /** 00032 * The type of container that is used internally to store and manage Hdf5Attributes. 00033 */ 00034 typedef std::map<std::string, Hdf5Attribute*> AttributeContainer; 00035 00036 /** 00037 * Creates an attribute with a given type and number of elements. 00038 * 00039 * For supported types, see DynamicObject::set(). 00040 * 00041 * @param name 00042 * The name of the attribute. 00043 * @param value 00044 * The current value of the attribute. 00045 * @return Returns a new Hdf5Attribute with the given name and value. 00046 */ 00047 Hdf5Attribute* addAttribute(const std::string& name, const DataVariant& value); 00048 00049 /** 00050 * Gets the element's attributes. 00051 * 00052 * @return Returns the member vector of attributes. 00053 * NOTE: You cannot call delete on an Hdf5Attribute since its destructor is protected. 00054 */ 00055 const AttributeContainer& getAttributes() const; 00056 00057 /** 00058 * Gets an attribute based on its name. 00059 * 00060 * @param name 00061 * The name of the attribute to fetch. 00062 * 00063 * @return Returns a pointer to the Hdf5Attribute with the matching name. If multiple attributes 00064 * with that name exist, the first one in the vector of attributes is returned. 00065 * NOTE: You cannot call delete on this pointer since the Hdf5Attribute destructor is protected. 00066 */ 00067 Hdf5Attribute* getAttribute(const std::string& name) const; 00068 00069 /** 00070 * Gets the number of attributes. 00071 * 00072 * @return The number of attributes in the element. Equivalent to calling getAttributes().size(). 00073 */ 00074 size_t getNumAttributes() const; 00075 00076 /** 00077 * Removes an attribute from the %Hdf5Element. 00078 * 00079 * @param name 00080 * The name of the attribute to remove from the %Hdf5Element. 00081 * This is the only way to manually delete an attribute from this object 00082 * since Hdf5Attribute::~Hdf5Attribute is protected. 00083 * 00084 * @return Returns true if the operation was successful. False, otherwise. 00085 */ 00086 bool removeAttribute(const std::string& name); 00087 00088 /** 00089 * Destroys an Hdf5Element and all of its attributes. 00090 */ 00091 virtual ~Hdf5Element(); 00092 00093 protected: 00094 /** 00095 * Creates an Hdf5Element object, which is the most basic type of HDF object. 00096 * 00097 * @param pParent 00098 * The parent node of this element. 00099 * @param name 00100 * The name of the HDF object. 00101 */ 00102 Hdf5Element(Hdf5Node* pParent, const std::string& name); 00103 00104 private: 00105 AttributeContainer mAttributes; 00106 }; 00107 00108 #endif