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-2018 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 ZNC_BUFFER_H
18 #define ZNC_BUFFER_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/ZNCString.h>
22 #include <znc/Message.h>
23 #include <sys/time.h>
24 #include <deque>
25 
26 // Forward Declarations
27 class CClient;
28 // !Forward Declarations
29 
30 class CBufLine {
31  public:
32  CBufLine() : CBufLine("") {
33  throw 0;
34  } // shouldn't be called, but is needed for compilation
35  CBufLine(const CMessage& Format, const CString& sText = "");
37  CBufLine(const CString& sFormat, const CString& sText = "",
38  const timeval* ts = nullptr,
39  const MCString& mssTags = MCString::EmptyMap);
40  ~CBufLine();
41  CMessage ToMessage(const CClient& Client, const MCString& mssParams) const;
43  CString GetLine(const CClient& Client, const MCString& mssParams) const;
45  void UpdateTime();
46 
47  bool Equals(const CMessage& Format) const {
48  return m_Message.Equals(Format);
49  }
50 
51  // Setters
52  void SetFormat(const CString& sFormat) { m_Message.Parse(sFormat); }
53  void SetText(const CString& sText) { m_sText = sText; }
54  void SetTime(const timeval& ts) { m_Message.SetTime(ts); }
55  void SetTags(const MCString& mssTags) { m_Message.SetTags(mssTags); }
56  // !Setters
57 
58  // Getters
59  const CString& GetCommand() const { return m_Message.GetCommand(); }
60  CString GetFormat() const {
62  }
63  const CString& GetText() const { return m_sText; }
64  timeval GetTime() const { return m_Message.GetTime(); }
65  const MCString& GetTags() const { return m_Message.GetTags(); }
66  // !Getters
67 
68  private:
69  protected:
72 };
73 
74 class CBuffer : private std::deque<CBufLine> {
75  public:
76  CBuffer(unsigned int uLineCount = 100);
77  ~CBuffer();
78 
79  size_type AddLine(const CMessage& Format, const CString& sText = "");
80  size_type UpdateLine(const CString& sCommand, const CMessage& Format,
81  const CString& sText = "");
82  size_type UpdateExactLine(const CMessage& Format,
83  const CString& sText = "");
84 
85  size_type AddLine(const CString& sFormat, const CString& sText = "",
86  const timeval* ts = nullptr,
87  const MCString& mssTags = MCString::EmptyMap);
89  size_type UpdateLine(const CString& sMatch, const CString& sFormat,
90  const CString& sText = "");
93  size_type UpdateExactLine(const CString& sFormat,
94  const CString& sText = "");
95  const CBufLine& GetBufLine(unsigned int uIdx) const;
96  CString GetLine(size_type uIdx, const CClient& Client,
97  const MCString& msParams = MCString::EmptyMap) const;
98  size_type Size() const { return size(); }
99  bool IsEmpty() const { return empty(); }
100  void Clear() { clear(); }
101 
102  // Setters
103  bool SetLineCount(unsigned int u, bool bForce = false);
104  // !Setters
105 
106  // Getters
107  unsigned int GetLineCount() const { return m_uLineCount; }
108  // !Getters
109  private:
110  protected:
111  unsigned int m_uLineCount;
112 };
113 
114 #endif // !ZNC_BUFFER_H
CString m_sText
Definition: Buffer.h:71
const CString & GetText() const
Definition: Buffer.h:63
CString ToString(unsigned int uFlags=IncludeAll) const
void UpdateTime()
Definition: Message.h:135
const MCString & GetTags() const
Definition: Message.h:126
size_type UpdateExactLine(const CMessage &Format, const CString &sText="")
CString GetLine(size_type uIdx, const CClient &Client, const MCString &msParams=MCString::EmptyMap) const
CMessage m_Message
Definition: Buffer.h:70
Definition: Buffer.h:30
Definition: Client.h:99
CBufLine()
Definition: Buffer.h:32
void SetText(const CString &sText)
Definition: Buffer.h:53
void Clear()
Definition: Buffer.h:100
CString GetLine(const CClient &Client, const MCString &mssParams) const
timeval GetTime() const
Definition: Buffer.h:64
void SetTags(const MCString &mssTags)
Definition: Message.h:127
void Parse(CString sMessage)
const timeval & GetTime() const
Definition: Message.h:123
bool IsEmpty() const
Definition: Buffer.h:99
bool Equals(const CMessage &Other) const
String class that is used inside ZNC.
Definition: ZNCString.h:68
bool SetLineCount(unsigned int u, bool bForce=false)
size_type Size() const
Definition: Buffer.h:98
CString GetFormat() const
Definition: Buffer.h:60
const MCString & GetTags() const
Definition: Buffer.h:65
const CString & GetCommand() const
Definition: Message.h:113
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:606
Definition: Buffer.h:74
void SetTags(const MCString &mssTags)
Definition: Buffer.h:55
void SetTime(const timeval &ts)
Definition: Buffer.h:54
A dictionary for strings.
Definition: ZNCString.h:595
CMessage ToMessage(const CClient &Client, const MCString &mssParams) const
void SetTime(const timeval &ts)
Definition: Message.h:124
const CBufLine & GetBufLine(unsigned int uIdx) const
void SetFormat(const CString &sFormat)
Definition: Buffer.h:52
unsigned int GetLineCount() const
Definition: Buffer.h:107
unsigned int m_uLineCount
Definition: Buffer.h:111
bool Equals(const CMessage &Format) const
Definition: Buffer.h:47
CBuffer(unsigned int uLineCount=100)
size_type AddLine(const CMessage &Format, const CString &sText="")
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition: Message.h:63
size_type UpdateLine(const CString &sCommand, const CMessage &Format, const CString &sText="")
const CString & GetCommand() const
Definition: Buffer.h:59