Page Speed Optimization Libraries
1.4.26.1
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_ATOM_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_ATOM_H_ 00021 00022 #include <set> 00023 #include "net/instaweb/util/public/string.h" 00024 00025 namespace net_instaweb { 00026 00027 struct CaseFold; 00028 struct CasePreserve; 00029 template<class CharTransform> class SymbolTable; 00030 00033 class Atom { 00034 public: 00035 Atom(const Atom& src) : str_(src.str_) {} 00036 Atom(); 00037 ~Atom() {} 00038 00039 Atom& operator=(const Atom& src) { 00040 if (&src != this) { 00041 str_ = src.str_; 00042 } 00043 return *this; 00044 } 00045 00047 const char* c_str() const { return str_; } 00048 int size() const { return strlen(str_); } 00049 00052 bool operator==(const Atom& sym) const { 00053 return str_ == sym.str_; 00054 } 00055 00058 bool operator!=(const Atom& sym) const { 00059 return str_ != sym.str_; 00060 } 00061 00065 friend class SymbolTable<CaseFold>; 00066 friend class SymbolTable<CasePreserve>; 00067 00068 private: 00069 explicit Atom(const char* str) : str_(str) {} 00070 const char* str_; 00071 }; 00072 00075 struct AtomCompare { 00076 bool operator()(const Atom& a1, const Atom& a2) const { 00077 return a1.c_str() < a2.c_str(); 00078 } 00079 }; 00080 00083 typedef std::set<Atom, AtomCompare> AtomSet; 00084 00085 } 00086 00087 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_ATOM_H_