PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: XmlAttribute.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_XML_ATTRIBUTE_H__ 00024 #define __PLCORE_XML_ATTRIBUTE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Xml/XmlBase.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class XmlDocument; 00044 00045 00046 //[-------------------------------------------------------] 00047 //[ Classes ] 00048 //[-------------------------------------------------------] 00049 /** 00050 * @brief 00051 * XML element attribute 00052 * 00053 * @remarks 00054 * An attribute is a name-value pair. Elements have an arbitrary 00055 * number of attributes, each with a unique name. 00056 */ 00057 class XmlAttribute : public XmlBase { 00058 00059 00060 //[-------------------------------------------------------] 00061 //[ Friends ] 00062 //[-------------------------------------------------------] 00063 friend class XmlElement; 00064 friend class XmlAttributeSet; 00065 00066 00067 //[-------------------------------------------------------] 00068 //[ Public functions ] 00069 //[-------------------------------------------------------] 00070 public: 00071 /** 00072 * @brief 00073 * Default constructor 00074 */ 00075 PLCORE_API XmlAttribute(); 00076 00077 /** 00078 * @brief 00079 * Destructor 00080 */ 00081 PLCORE_API virtual ~XmlAttribute(); 00082 00083 /** 00084 * @brief 00085 * Return the name of this attribute 00086 * 00087 * @return 00088 * Name of this attribute 00089 */ 00090 inline String GetName() const; 00091 00092 /** 00093 * @brief 00094 * Set the name of this attribute 00095 * 00096 * @param[in] sName 00097 * Name of this attribute to set 00098 */ 00099 inline void SetName(const String &sName); 00100 00101 /** 00102 * @brief 00103 * Return the value of this attribute 00104 * 00105 * @return 00106 * Value of this attribute 00107 */ 00108 inline String GetValue() const; 00109 00110 /** 00111 * @brief 00112 * Return the value of this attribute, converted to an integer 00113 * 00114 * @return 00115 * Value of this attribute, converted to an integer 00116 */ 00117 inline int GetIntValue() const; 00118 00119 /** 00120 * @brief 00121 * Return the value of this attribute, converted to a double 00122 * 00123 * @return 00124 * Value of this attribute, converted to a double 00125 */ 00126 inline double GetDoubleValue() const; 00127 00128 /** 00129 * @brief 00130 * Examines the value string 00131 * 00132 * @param[out] nValue 00133 * Will receive the integer value if all went fine, if not, this variable is not touched 00134 * 00135 * @return 00136 * If the attribute value is not an integer, it returns 'WrongType'. Returns 00137 * 'Success' on success. 00138 * 00139 * @remarks 00140 * It is an alternative to the 'GetIntValue()'-function with richer error checking. 00141 * If the value is an integer, it is stored in 'value' and the call returns 00142 * 'Success'. If it is not an integer, it returns 'WrongType'. 00143 * A specialized but useful call. Note that for success it returns 'Success', 00144 * which is the opposite of almost all other parser calls. 00145 */ 00146 PLCORE_API EQueryResult QueryIntValue(int &nValue) const; 00147 00148 /** 00149 * @brief 00150 * Examines the value string 00151 * 00152 * @param[out] dValue 00153 * Will receive the double value if all went fine, if not, this variable is not touched 00154 * 00155 * @return 00156 * If the attribute value is not an integer, it returns 'WrongType'. Returns 00157 * 'Success' on success. 00158 * 00159 * @see 00160 * - QueryIntValue() 00161 */ 00162 PLCORE_API EQueryResult QueryDoubleValue(double &dValue) const; 00163 00164 /** 00165 * @brief 00166 * Set the value 00167 * 00168 * @param[in] sValue 00169 * Attribute value to set 00170 */ 00171 inline void SetValue(const String &sValue); 00172 00173 /** 00174 * @brief 00175 * Set the value from an integer 00176 * 00177 * @param[in] nValue 00178 * Attribute integer value to set 00179 */ 00180 inline void SetIntValue(int nValue); 00181 00182 /** 00183 * @brief 00184 * Set the value from a double 00185 * 00186 * @param[in] dValue 00187 * Attribute double value to set 00188 */ 00189 inline void SetDoubleValue(double dValue); 00190 00191 /** 00192 * @brief 00193 * Get the next sibling attribute in the DOM 00194 * 00195 * @return 00196 * The next sibling attribute in the DOM, a null pointer at end 00197 */ 00198 inline XmlAttribute *GetNext(); 00199 inline const XmlAttribute *GetNext() const; 00200 00201 /** 00202 * @brief 00203 * Get the previous sibling attribute in the DOM 00204 * 00205 * @return 00206 * The previous sibling attribute in the DOM, a null pointer at beginning 00207 */ 00208 inline XmlAttribute *GetPrevious(); 00209 inline const XmlAttribute *GetPrevious() const; 00210 00211 /** 00212 * @brief 00213 * Compare functions 00214 * 00215 * @param[in] cOther 00216 * Other attribute to compare with 00217 * 00218 * @return 00219 * 'true' if the condition is fulfilled, else 'false' 00220 */ 00221 inline bool operator ==(const XmlAttribute &cOther) const; 00222 inline bool operator <(const XmlAttribute &cOther) const; 00223 inline bool operator >(const XmlAttribute &cOther) const; 00224 00225 00226 //[-------------------------------------------------------] 00227 //[ Public virtual XmlBase functions ] 00228 //[-------------------------------------------------------] 00229 public: 00230 PLCORE_API virtual bool Save(File &cFile, uint32 nDepth = 0) override; 00231 PLCORE_API virtual String ToString(uint32 nDepth = 0) const override; 00232 PLCORE_API virtual const char *Parse(const char *pszData, XmlParsingData *pData = nullptr, EEncoding nEncoding = EncodingUnknown) override; 00233 00234 00235 //[-------------------------------------------------------] 00236 //[ Private functions ] 00237 //[-------------------------------------------------------] 00238 private: 00239 /** 00240 * @brief 00241 * Copy constructor 00242 * 00243 * @param[in] cSource 00244 * Source to copy from 00245 */ 00246 XmlAttribute(const XmlAttribute &cSource); 00247 00248 /** 00249 * @brief 00250 * Copy operator 00251 * 00252 * @param[in] cSource 00253 * Source to copy from 00254 * 00255 * @return 00256 * Reference to this instance 00257 */ 00258 XmlAttribute &operator =(const XmlAttribute &cSource); 00259 00260 00261 //[-------------------------------------------------------] 00262 //[ Private data ] 00263 //[-------------------------------------------------------] 00264 private: 00265 XmlDocument *m_pDocument; /**< A pointer back to a document, for error reporting, can be a null pointer */ 00266 String m_sName; /**< Name */ 00267 String m_sValue; /**< Value */ 00268 XmlAttribute *m_pPreviousAttribute; /**< Previous attribute, can be a null pointer */ 00269 XmlAttribute *m_pNextAttribute; /**< Next attribute, can be a null pointer */ 00270 00271 00272 }; 00273 00274 00275 //[-------------------------------------------------------] 00276 //[ Namespace ] 00277 //[-------------------------------------------------------] 00278 } // PLCore 00279 00280 00281 //[-------------------------------------------------------] 00282 //[ Implementation ] 00283 //[-------------------------------------------------------] 00284 #include "PLCore/Xml/XmlAttribute.inl" 00285 00286 00287 #endif // __PLCORE_XML_ATTRIBUTE_H__
|