ZNC  trunk
Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2024 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);
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);
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
Definition: Buffer.h:30
CBufLine(const CMessage &Format, const CString &sText="")
bool Equals(const CMessage &Format) const
Definition: Buffer.h:47
void SetTags(const MCString &mssTags)
Definition: Buffer.h:55
void SetText(const CString &sText)
Definition: Buffer.h:53
const MCString & GetTags() const
Definition: Buffer.h:65
CBufLine()
Definition: Buffer.h:32
CString m_sText
Definition: Buffer.h:71
CMessage ToMessage(const CClient &Client, const MCString &mssParams) const
void UpdateTime()
CString GetLine(const CClient &Client, const MCString &mssParams) const
CMessage m_Message
Definition: Buffer.h:70
void SetFormat(const CString &sFormat)
Definition: Buffer.h:52
void SetTime(const timeval &ts)
Definition: Buffer.h:54
CBufLine(const CString &sFormat, const CString &sText="", const timeval *ts=nullptr, const MCString &mssTags=MCString::EmptyMap)
const CString & GetCommand() const
Definition: Buffer.h:59
const CString & GetText() const
Definition: Buffer.h:63
timeval GetTime() const
Definition: Buffer.h:64
CString GetFormat() const
Definition: Buffer.h:60
Definition: Buffer.h:74
size_type Size() const
Definition: Buffer.h:98
size_type AddLine(const CString &sFormat, const CString &sText="", const timeval *ts=nullptr, const MCString &mssTags=MCString::EmptyMap)
const CBufLine & GetBufLine(unsigned int uIdx) const
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 UpdateLine(const CString &sCommand, const CMessage &Format, const CString &sText="")
CString GetLine(size_type uIdx, const CClient &Client, const MCString &msParams=MCString::EmptyMap) const
unsigned int m_uLineCount
Definition: Buffer.h:111
bool IsEmpty() const
Definition: Buffer.h:99
size_type AddLine(const CMessage &Format, const CString &sText="")
unsigned int GetLineCount() const
Definition: Buffer.h:107
void Clear()
Definition: Buffer.h:100
size_type UpdateExactLine(const CMessage &Format, const CString &sText="")
CBuffer(unsigned int uLineCount=100)
size_type UpdateExactLine(const CString &sFormat, const CString &sText="")
Same as UpdateLine, but does nothing if this exact line already exists.
Definition: Client.h:99
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition: Message.h:57
@ ExcludeTags
Definition: Message.h:149
const timeval & GetTime() const
Definition: Message.h:137
void SetTime(const timeval &ts)
Definition: Message.h:138
const MCString & GetTags() const
Definition: Message.h:140
CString ToString(unsigned int uFlags=IncludeAll) const
bool Equals(const CMessage &Other) const
void SetTags(const MCString &mssTags)
Definition: Message.h:141
const CString & GetCommand() const
Definition: Message.h:108
void Parse(const CString &sMessage)
String class that is used inside ZNC.
Definition: ZNCString.h:68
A dictionary for strings.
Definition: ZNCString.h:595
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:606