helics  3.5.2
LogBuffer.hpp
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "gmlc/libguarded/shared_guarded.hpp"
10 
11 #include <atomic>
12 #include <deque>
13 #include <functional>
14 #include <string>
15 #include <string_view>
16 #include <tuple>
17 
18 namespace Json {
19 class Value;
20 }
21 
22 namespace helics {
24 class LogBuffer {
25  private:
27  std::atomic<std::size_t> mMaxSize{0};
28 
29  public:
30  static constexpr std::size_t cDefaultBufferSize{10UL};
31  LogBuffer() = default;
32  explicit LogBuffer(std::size_t maxSize): mMaxSize(maxSize) {}
33  void resize(std::size_t newSize);
34  void enable(bool enable = true);
35  std::size_t capacity() const { return mMaxSize; }
36  std::size_t size() const { return mBuffer.lock()->size(); }
37 
38  void push(int logLevel, std::string_view header, std::string_view message);
39 
40  void
41  process(const std::function<void(int, std::string_view, std::string_view)>& procFunc) const;
42 };
43 
45 void bufferToJson(const LogBuffer& buffer, Json::Value& base);
46 
47 } // namespace helics
Definition: application_api/Federate.hpp:27
Definition: LogBuffer.hpp:24
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
void bufferToJson(const LogBuffer &buffer, Json::Value &base)
Definition: LogBuffer.cpp:60