YggdrasilWM  0.1.1
A tiny window manager coded in C++
TSBarsData Class Reference

#include <TSBarsData.hpp>

Collaboration diagram for TSBarsData:
Collaboration graph

Public Member Functions

 TSBarsData ()
 
 ~TSBarsData ()
 
void addData (std::string key, std::string value)
 
std::unordered_map< std::string, std::string > getData ()
 
void removeData (std::string key)
 
void modifyData (std::string key, std::string value)
 
bool wait ()
 

Public Attributes

bool dataChanged = false
 

Private Attributes

std::mutex mutex
 
std::condition_variable cv
 
std::unordered_map< std::string, std::string > data
 
std::set< std::string > modifiedKeys
 

Detailed Description

Yb dP 8 w 8 Yb dP 8b d8 YbdP .d88 .d88 .d88 8d8b .d88 d88b w 8 Yb db dP 8YbmdP8 YP 8 8 8 8 8 8 8P 8 8 Yb. 8 8 YbdPYbdP 8 " 8 88Y88 Y88Y88 8 `Y88 Y88P 8 8 YP YP 8 8 wwdP wwdP Yggdrasil Window Manager https://github.com/corecaps/YggdrasilWM Copyright (C) 2024 jgarcia jgarc.nosp@m.ia@s.nosp@m.tuden.nosp@m.t.42.nosp@m..fr corec.nosp@m.aps@.nosp@m.gmail.nosp@m..com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Constructor & Destructor Documentation

◆ TSBarsData()

TSBarsData::TSBarsData ( )

Yb dP 8 w 8 Yb dP 8b d8 YbdP .d88 .d88 .d88 8d8b .d88 d88b w 8 Yb db dP 8YbmdP8 YP 8 8 8 8 8 8 8P 8 8 Yb. 8 8 YbdPYbdP 8 " 8 88Y88 Y88Y88 8 `Y88 Y88P 8 8 YP YP 8 8 wwdP wwdP Yggdrasil Window Manager https://github.com/corecaps/YggdrasilWM Copyright (C) 2024 jgarcia jgarc.nosp@m.ia@s.nosp@m.tuden.nosp@m.t.42.nosp@m..fr corec.nosp@m.aps@.nosp@m.gmail.nosp@m..com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

29 : mutex(), cv(), data(),modifiedKeys(){}
std::unordered_map< std::string, std::string > data
Definition: TSBarsData.hpp:45
std::condition_variable cv
Definition: TSBarsData.hpp:44
std::mutex mutex
Definition: TSBarsData.hpp:43
std::set< std::string > modifiedKeys
Definition: TSBarsData.hpp:46

◆ ~TSBarsData()

TSBarsData::~TSBarsData ( )
30 {}

Member Function Documentation

◆ addData()

void TSBarsData::addData ( std::string  key,
std::string  value 
)
31  {
32  std::lock_guard<std::mutex> lock(mutex);
33  data[key] = value;
34  modifiedKeys.insert(key);
35  dataChanged = true;
36  cv.notify_one();
37 }
bool dataChanged
Definition: TSBarsData.hpp:41

References cv, data, dataChanged, modifiedKeys, and mutex.

◆ getData()

std::unordered_map< std::string, std::string > TSBarsData::getData ( )
38  {
39  std::unique_lock<std::mutex> lock(mutex);
40  std::unordered_map<std::string, std::string> modifiedData;
41  for (const auto& key : modifiedKeys) {
42  modifiedData[key] = data[key]; // Assumes key still exists. Adjust if you track removals differently.
43  }
44  modifiedKeys.clear();
45  return modifiedData;
46 }

References data, modifiedKeys, and mutex.

◆ modifyData()

void TSBarsData::modifyData ( std::string  key,
std::string  value 
)
56  {
57  std::lock_guard<std::mutex> lock(mutex);
58  data[key] = value;
59  modifiedKeys.insert(key);
60  dataChanged = true;
61  cv.notify_one();
62 }

References cv, data, dataChanged, modifiedKeys, and mutex.

◆ removeData()

void TSBarsData::removeData ( std::string  key)
47  {
48  std::lock_guard<std::mutex> lock(mutex);
49  if (modifiedKeys.find(key) != modifiedKeys.end()) {
50  modifiedKeys.erase(key);
51  }
52  data.erase(key);
53  dataChanged = true;
54  cv.notify_one();
55 }

References cv, data, dataChanged, modifiedKeys, and mutex.

◆ wait()

bool TSBarsData::wait ( )
63  {
64  std::unique_lock<std::mutex> lock(mutex);
65  if (!cv.wait_for(lock, std::chrono::milliseconds(1000),[this] { return dataChanged; }))
66  return false;
67  else {
68  dataChanged = false;
69  return true;
70  }
71 }

References cv, dataChanged, and mutex.

Member Data Documentation

◆ cv

std::condition_variable TSBarsData::cv
private

Referenced by addData(), modifyData(), removeData(), and wait().

◆ data

std::unordered_map<std::string, std::string> TSBarsData::data
private

◆ dataChanged

bool TSBarsData::dataChanged = false

Referenced by addData(), modifyData(), removeData(), and wait().

◆ modifiedKeys

std::set<std::string> TSBarsData::modifiedKeys
private

◆ mutex

std::mutex TSBarsData::mutex
private

The documentation for this class was generated from the following files: