Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circular_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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_UTIL_CIRCULAR_BUFFER_H_
20 #define PAGESPEED_KERNEL_UTIL_CIRCULAR_BUFFER_H_
21 
25 
26 namespace net_instaweb {
27 
28 class MessageHandler;
29 
33  public:
35  static CircularBuffer* Create(const int capacity);
43  static CircularBuffer* Init(bool parent, void* block,
44  const int block_size,
45  const int capacity);
49  static int Sizeof(const int capacity) {
51  int total = sizeof(CircularBuffer) + capacity - 1;
52  return total;
53  }
56  void Clear();
58  bool Write(const StringPiece& message);
61 
62  private:
66  ~CircularBuffer();
68  StringPiece FirstChunk();
70  StringPiece SecondChunk();
71 
73  int capacity_;
75  bool wrapped_;
77  int offset_;
79  char buffer_[1];
80 
81 
82 };
83 
84 }
85 
86 #endif
static int Sizeof(const int capacity)
Definition: circular_buffer.h:49
static CircularBuffer * Create(const int capacity)
Instantiate buffer with malloc.
Definition: circular_buffer.h:32
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
GoogleString ToString(MessageHandler *handler)
Return data content as string.
static CircularBuffer * Init(bool parent, void *block, const int block_size, const int capacity)
Definition: message_handler.h:39
bool Write(const StringPiece &message)
Write message to buffer.