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