Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
atom.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_ATOM_H_
20 #define PAGESPEED_KERNEL_BASE_ATOM_H_
21 
22 #include <set>
24 
25 namespace net_instaweb {
26 
27 struct CaseFold;
28 struct CasePreserve;
29 template<class CharTransform> class SymbolTable;
30 
33 class Atom {
34  public:
35  Atom(const Atom& src) : str_(src.str_) {}
36  Atom();
37  ~Atom() {}
38 
39  Atom& operator=(const Atom& src) {
40  if (&src != this) {
41  str_ = src.str_;
42  }
43  return *this;
44  }
45 
49  const StringPiece* Rep() const { return str_; }
50 
53  bool operator==(const Atom& sym) const {
54  return str_ == sym.str_;
55  }
56 
59  bool operator!=(const Atom& sym) const {
60  return str_ != sym.str_;
61  }
62 
66  friend class SymbolTable<CaseFold>;
67  friend class SymbolTable<CasePreserve>;
68 
69  private:
70  explicit Atom(const StringPiece* str) : str_(str) {}
71  const StringPiece* str_;
72 };
73 
76 struct AtomCompare {
77  bool operator()(const Atom& a1, const Atom& a2) const {
80  return a1.Rep()->data() < a2.Rep()->data();
81  }
82 };
83 
86 typedef std::set<Atom, AtomCompare> AtomSet;
87 
88 }
89 
90 #endif
bool operator()(const Atom &a1, const Atom &a2) const
Definition: atom.h:77
Definition: atom.h:29
const StringPiece * Rep() const
Definition: atom.h:49
bool operator==(const Atom &sym) const
Definition: atom.h:53
A helper for case-sensitive hashing.
Definition: string_hash.h:49
Definition: atom.h:33
Atom & operator=(const Atom &src)
atoms are memory-managed by SymbolTables.
Definition: atom.h:39
Definition: atom.h:76
bool operator!=(const Atom &sym) const
Definition: atom.h:59
std::set< Atom, AtomCompare > AtomSet
Definition: atom.h:86
A helper for case-insensitive hashing, which folds to lowercase.
Definition: string_hash.h:67