PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ParamsParser.h * 00003 * 00004 * Copyright (C) 2002-2011 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_TOOLS_PARAMSPARSER_H__ 00024 #define __PLCORE_TOOLS_PARAMSPARSER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/String/RegEx.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Class for parsing parameters 00046 * 00047 * @remarks 00048 * This class can parse parameter lists given as strings (e.g. "param1=\"hello\" param2=10") 00049 */ 00050 class ParamsParser { 00051 00052 00053 //[-------------------------------------------------------] 00054 //[ Public functions ] 00055 //[-------------------------------------------------------] 00056 public: 00057 /** 00058 * @brief 00059 * Constructor 00060 */ 00061 inline ParamsParser(); 00062 00063 /** 00064 * @brief 00065 * Destructor 00066 */ 00067 inline ~ParamsParser(); 00068 00069 /** 00070 * @brief 00071 * Parse parameter string 00072 * 00073 * @param[in] sParameters 00074 * String containing parameters (e.g. "Param0=\"Hello\" Param1=10) 00075 * 00076 * @return 00077 * 'true' if the string could be parsed, else 'false' 00078 * 00079 * @remarks 00080 * This will first check if the string is a valid parameter string 00081 * and then parse the first parameter and value. If the string is not 00082 * valid or empty, the function will return 'false'. 00083 */ 00084 PLCORE_API bool ParseString(const String &sParameters); 00085 00086 /** 00087 * @brief 00088 * Parse next parameter 00089 * 00090 * @return 00091 * 'true' if the next name/value pair could be parsed, else 'false' 00092 */ 00093 PLCORE_API bool Next(); 00094 00095 /** 00096 * @brief 00097 * Check if the current (last parsed) parameter is valid 00098 * 00099 * @return 00100 * 'true' if there is a current parameter, else 'false' 00101 */ 00102 inline bool HasParam() const; 00103 00104 /** 00105 * @brief 00106 * Get name of currently parsed parameter 00107 * 00108 * @return 00109 * Parameter name 00110 */ 00111 inline String GetName() const; 00112 00113 /** 00114 * @brief 00115 * Get value of currently parsed parameter 00116 * 00117 * @return 00118 * Parameter name 00119 */ 00120 inline String GetValue() const; 00121 00122 00123 //[-------------------------------------------------------] 00124 //[ Private data ] 00125 //[-------------------------------------------------------] 00126 private: 00127 String m_sParameters; /**< Parsed parameter string */ 00128 RegEx m_cRegEx; /**< Regular expression for parsing a parameter string */ 00129 long m_nParsePos; /**< Current parsing position (-1 for inactive) */ 00130 String m_sName; /**< Name of next parameter */ 00131 String m_sValue; /**< Value of next parameter */ 00132 00133 00134 }; 00135 00136 00137 //[-------------------------------------------------------] 00138 //[ Namespace ] 00139 //[-------------------------------------------------------] 00140 } // PLCore 00141 00142 00143 //[-------------------------------------------------------] 00144 //[ Implementation ] 00145 //[-------------------------------------------------------] 00146 #include "PLCore/Base/Tools/ParamsParser.inl" 00147 00148 00149 #endif // __PLCORE_TOOLS_PARAMSPARSER_H__
|