ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2014 ZNC, see the NOTICE file for details.
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 
17 #ifndef _BUFFER_H
18 #define _BUFFER_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/ZNCString.h>
22 #include <sys/time.h>
23 #include <deque>
24 
25 // Forward Declarations
26 class CClient;
27 // !Forward Declarations
28 
29 class CBufLine {
30 public:
31  CBufLine() { throw 0; } // shouldn't be called, but is needed for compilation
32  CBufLine(const CString& sFormat, const CString& sText = "", const timeval* ts = 0);
33  ~CBufLine();
34  CString GetLine(const CClient& Client, const MCString& msParams) const;
35  void UpdateTime();
36 
37  // Setters
38  void SetFormat(const CString& sFormat) { m_sFormat = sFormat; }
39  void SetText(const CString& sText) { m_sText = sText; }
40  void SetTime(const timeval& ts) { m_time = ts; }
41  // !Setters
42 
43  // Getters
44  const CString& GetFormat() const { return m_sFormat; }
45  const CString& GetText() const { return m_sText; }
46  timeval GetTime() const { return m_time; }
47  // !Getters
48 
49 private:
50 protected:
53  timeval m_time;
54 };
55 
56 class CBuffer : private std::deque<CBufLine> {
57 public:
58  CBuffer(unsigned int uLineCount = 100);
59  ~CBuffer();
60 
61  size_type AddLine(const CString& sFormat, const CString& sText = "", const timeval* ts = 0);
63  size_type UpdateLine(const CString& sMatch, const CString& sFormat, const CString& sText = "");
66  size_type UpdateExactLine(const CString& sFormat, const CString& sText = "");
67  const CBufLine& GetBufLine(unsigned int uIdx) const;
68  CString GetLine(size_type uIdx, const CClient& Client, const MCString& msParams = MCString::EmptyMap) const;
69  size_type Size() const { return size(); }
70  bool IsEmpty() const { return empty(); }
71  void Clear() { clear(); }
72 
73  // Setters
74  bool SetLineCount(unsigned int u, bool bForce = false);
75  // !Setters
76 
77  // Getters
78  unsigned int GetLineCount() const { return m_uLineCount; }
79  // !Getters
80 private:
81 protected:
82  unsigned int m_uLineCount;
83 };
84 
85 #endif // !_BUFFER_H
CString m_sText
Definition: Buffer.h:52
const CString & GetText() const
Definition: Buffer.h:45
void UpdateTime()
size_type UpdateExactLine(const CString &sFormat, const CString &sText="")
Same as UpdateLine, but does nothing if this exact line already exists.
CString GetLine(size_type uIdx, const CClient &Client, const MCString &msParams=MCString::EmptyMap) const
Definition: Buffer.h:29
Definition: Client.h:84
CBufLine()
Definition: Buffer.h:31
void SetText(const CString &sText)
Definition: Buffer.h:39
void Clear()
Definition: Buffer.h:71
CString m_sFormat
Definition: Buffer.h:51
timeval GetTime() const
Definition: Buffer.h:46
bool IsEmpty() const
Definition: Buffer.h:70
String class that is used inside ZNC.
Definition: ZNCString.h:67
size_type UpdateLine(const CString &sMatch, const CString &sFormat, const CString &sText="")
Same as AddLine, but replaces a line whose format string starts with sMatch if there is one...
bool SetLineCount(unsigned int u, bool bForce=false)
size_type Size() const
Definition: Buffer.h:69
timeval m_time
Definition: Buffer.h:53
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:546
const CString & GetFormat() const
Definition: Buffer.h:44
Definition: Buffer.h:56
void SetTime(const timeval &ts)
Definition: Buffer.h:40
A dictionary for strings.
Definition: ZNCString.h:538
CString GetLine(const CClient &Client, const MCString &msParams) const
size_type AddLine(const CString &sFormat, const CString &sText="", const timeval *ts=0)
const CBufLine & GetBufLine(unsigned int uIdx) const
void SetFormat(const CString &sFormat)
Definition: Buffer.h:38
unsigned int GetLineCount() const
Definition: Buffer.h:78
unsigned int m_uLineCount
Definition: Buffer.h:82
CBuffer(unsigned int uLineCount=100)