Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resource_namer.h
Go to the documentation of this file.
1 // Copyright 2010 Google Inc.
16 
17 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_
18 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_
19 
20 #include "base/logging.h"
24 
25 namespace net_instaweb {
26 
27 class Hasher;
28 
33  public:
36  static const int kOverhead;
37 
38  ResourceNamer() {}
39  ~ResourceNamer() {}
40 
42 
45  bool Decode(const StringPiece& encoded_string, int hash_length,
46  int signature_length);
47 
50  bool DecodeIgnoreHashAndSignature(StringPiece encoded_string);
51 
54  GoogleString Encode() const;
55 
62  GoogleString EncodeIdName() const;
63 
65 
69  int EventualSize(const Hasher& hasher, int signature_length) const;
70 
72  StringPiece id() const { return id_; }
73  StringPiece options() const { return options_; }
74  StringPiece name() const { return name_; }
75  StringPiece hash() const { return hash_; }
76  StringPiece ext() const { return ext_; }
77  StringPiece experiment() const { return experiment_; }
78  StringPiece signature() const { return signature_; }
79 
80  bool has_experiment() const { return !experiment_.empty(); }
81  bool has_options() const { return !options_.empty(); }
82 
84  void set_id(const StringPiece& p) { p.CopyToString(&id_); }
85  void set_options(const StringPiece& opts) { opts.CopyToString(&options_); }
86  void set_name(const StringPiece& n) { n.CopyToString(&name_); }
87  void set_hash(const StringPiece& h) { h.CopyToString(&hash_); }
88  void set_ext(const StringPiece& e) {
91  CHECK(e.empty() || e[0] != '.');
92  e.CopyToString(&ext_);
93  }
94  void set_experiment(const StringPiece& e) { e.CopyToString(&experiment_); }
95  void set_signature(const StringPiece& s) { s.CopyToString(&signature_); }
96 
98  void ClearHash() { hash_.clear(); }
99  void CopyFrom(const ResourceNamer& other);
100 
102 
104  GoogleString PrettyName() const {return InternalEncode(); }
105 
106  private:
107  GoogleString InternalEncode() const;
108  bool LegacyDecode(const StringPiece& encoded_string);
109 
110  GoogleString id_;
111  GoogleString options_;
112  GoogleString name_;
113  GoogleString hash_;
114  GoogleString ext_;
115  GoogleString experiment_;
116  GoogleString signature_;
117 
118 
119 };
120 
121 }
122 
123 #endif
void set_id(const StringPiece &p)
Simple setters.
Definition: resource_namer.h:84
bool Decode(const StringPiece &encoded_string, int hash_length, int signature_length)
Encoding and decoding in various formats.
StringPiece id() const
Simple getters.
Definition: resource_namer.h:72
GoogleString EncodeIdName() const
bool DecodeIgnoreHashAndSignature(StringPiece encoded_string)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
GoogleString PrettyName() const
Utility functions.
Definition: resource_namer.h:104
static const int kOverhead
Definition: resource_namer.h:36
void ClearHash()
Other setter-like operations.
Definition: resource_namer.h:98
int EventualSize(const Hasher &hasher, int signature_length) const
Note: there is no need at this time to decode the name key.
GoogleString Encode() const
void set_ext(const StringPiece &e)
Definition: resource_namer.h:88
Definition: resource_namer.h:32