00001 /* 00002 * Copyright (C) 2006-2011, SRI International (R) 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #pragma once 00019 00020 #ifndef __OpenKarto_Name_h__ 00021 #define __OpenKarto_Name_h__ 00022 00023 #include <OpenKarto/String.h> 00024 00025 namespace karto 00026 { 00027 00029 00030 00040 class KARTO_EXPORT Identifier 00041 { 00042 public: 00046 Identifier(); 00047 00052 Identifier(const char* pString); 00053 00058 Identifier(const String& rString); 00059 00063 Identifier(const Identifier& rOther); 00064 00068 virtual ~Identifier(); 00069 00070 public: 00075 const String& GetName() const; 00076 00081 void SetName(const String& pName); 00082 00087 const String& GetScope() const; 00088 00093 void SetScope(const String& rScope); 00094 00099 kt_size_t Size() const; 00100 00104 void Clear(); 00105 00110 const String& ToString() const; 00111 00112 public: 00116 Identifier& operator=(const Identifier& rOther); 00117 00121 kt_bool operator==(const Identifier& rOther) const; 00122 00126 kt_bool operator!=(const Identifier& rOther) const 00127 { 00128 return !(*this == rOther); 00129 } 00130 00135 kt_bool operator<(const Identifier& rOther) const; 00136 00140 friend KARTO_FORCEINLINE std::ostream& operator << (std::ostream& rStream, const Identifier& rIdentifier) 00141 { 00142 rStream << rIdentifier.ToString(); 00143 return rStream; 00144 } 00145 00146 private: 00151 void Parse(const String& rString); 00152 00157 void Validate(const String& rString); 00158 00162 void Update(); 00163 00169 inline kt_bool IsValidFirst(char c) 00170 { 00171 return (isalpha(c) || c == '/'); 00172 } 00173 00179 inline kt_bool IsValid(char c) 00180 { 00181 return (isalnum(c) || c == '/' || c == '_' || c == '-'); 00182 } 00183 00184 private: 00185 String m_Name; 00186 String m_Scope; 00187 String m_FullName; 00188 }; 00189 00191 00192 } 00193 00194 #endif // __OpenKarto_Name_h__