Skip to content

Commit 0c9e180

Browse files
Merge remote-tracking branch 'origin/main' into main
2 parents fe5b670 + 1dd7eac commit 0c9e180

File tree

111 files changed

+25751
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+25751
-84
lines changed

qt_clion/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(REQUIRED_LIBS Core Gui Widgets)
1111
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets)
1212

1313
if(WIN32)
14-
set(CMAKE_PREFIX_PATH "D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5")
14+
set(CMAKE_PREFIX_PATH D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5)
1515
else()
1616
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Qt5")
1717
endif()

qt_driview/main.cpp

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,11 @@
1-
/****************************************************************************
2-
**
3-
** Copyright (C) 2016 The Qt Company Ltd.
4-
** Contact: https://www.qt.io/licensing/
5-
**
6-
** This file is part of the examples of the Qt Toolkit.
7-
**
8-
** $QT_BEGIN_LICENSE:BSD$
9-
** Commercial License Usage
10-
** Licensees holding valid commercial Qt licenses may use this file in
11-
** accordance with the commercial license agreement provided with the
12-
** Software or, alternatively, in accordance with the terms contained in
13-
** a written agreement between you and The Qt Company. For licensing terms
14-
** and conditions see https://www.qt.io/terms-conditions. For further
15-
** information use the contact form at https://www.qt.io/contact-us.
16-
**
17-
** BSD License Usage
18-
** Alternatively, you may use this file under the terms of the BSD license
19-
** as follows:
20-
**
21-
** "Redistribution and use in source and binary forms, with or without
22-
** modification, are permitted provided that the following conditions are
23-
** met:
24-
** * Redistributions of source code must retain the above copyright
25-
** notice, this list of conditions and the following disclaimer.
26-
** * Redistributions in binary form must reproduce the above copyright
27-
** notice, this list of conditions and the following disclaimer in
28-
** the documentation and/or other materials provided with the
29-
** distribution.
30-
** * Neither the name of The Qt Company Ltd nor the names of its
31-
** contributors may be used to endorse or promote products derived
32-
** from this software without specific prior written permission.
33-
**
34-
**
35-
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36-
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37-
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38-
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39-
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40-
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41-
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42-
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43-
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44-
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45-
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46-
**
47-
** $QT_END_LICENSE$
48-
**
49-
****************************************************************************/
50-
511
#include <QApplication>
522
#include <QDesktopWidget>
533
#include <QFileSystemModel>
544
#include <QFileIconProvider>
555
#include <QTreeView>
566
#include <QCommandLineParser>
577
#include <QCommandLineOption>
8+
#include <QDir>
589

5910
int main(int argc, char *argv[])
6011
{

qt_driview/qt_driview.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ QT += core gui
88

99
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
1010

11+
requires(qtConfig(treeview))
12+
1113
TARGET = qt_driview
1214
TEMPLATE = app
1315

qt_screenshot/3rd/spdlog/async.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3+
4+
#pragma once
5+
6+
//
7+
// Async logging using global thread pool
8+
// All loggers created here share same global thread pool.
9+
// Each log message is pushed to a queue along with a shared pointer to the
10+
// logger.
11+
// If a logger deleted while having pending messages in the queue, it's actual
12+
// destruction will defer
13+
// until all its messages are processed by the thread pool.
14+
// This is because each message in the queue holds a shared_ptr to the
15+
// originating logger.
16+
17+
#include <spdlog/async_logger.h>
18+
#include <spdlog/details/registry.h>
19+
#include <spdlog/details/thread_pool.h>
20+
21+
#include <memory>
22+
#include <mutex>
23+
#include <functional>
24+
25+
namespace spdlog {
26+
27+
namespace details {
28+
static const size_t default_async_q_size = 8192;
29+
}
30+
31+
// async logger factory - creates async loggers backed with thread pool.
32+
// if a global thread pool doesn't already exist, create it with default queue
33+
// size of 8192 items and single thread.
34+
template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
35+
struct async_factory_impl
36+
{
37+
template<typename Sink, typename... SinkArgs>
38+
static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&... args)
39+
{
40+
auto &registry_inst = details::registry::instance();
41+
42+
// create global thread pool if not already exists..
43+
44+
auto &mutex = registry_inst.tp_mutex();
45+
std::lock_guard<std::recursive_mutex> tp_lock(mutex);
46+
auto tp = registry_inst.get_tp();
47+
if (tp == nullptr)
48+
{
49+
tp = std::make_shared<details::thread_pool>(details::default_async_q_size, 1U);
50+
registry_inst.set_tp(tp);
51+
}
52+
53+
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
54+
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
55+
registry_inst.initialize_logger(new_logger);
56+
return new_logger;
57+
}
58+
};
59+
60+
using async_factory = async_factory_impl<async_overflow_policy::block>;
61+
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
62+
63+
template<typename Sink, typename... SinkArgs>
64+
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&... sink_args)
65+
{
66+
return async_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
67+
}
68+
69+
template<typename Sink, typename... SinkArgs>
70+
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&... sink_args)
71+
{
72+
return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
73+
}
74+
75+
// set global thread pool.
76+
inline void init_thread_pool(
77+
size_t q_size, size_t thread_count, std::function<void()> on_thread_start, std::function<void()> on_thread_stop)
78+
{
79+
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start, on_thread_stop);
80+
details::registry::instance().set_tp(std::move(tp));
81+
}
82+
83+
inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start)
84+
{
85+
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
86+
}
87+
88+
inline void init_thread_pool(size_t q_size, size_t thread_count)
89+
{
90+
init_thread_pool(
91+
q_size, thread_count, [] {}, [] {});
92+
}
93+
94+
// get the global thread pool.
95+
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool()
96+
{
97+
return details::registry::instance().get_tp();
98+
}
99+
} // namespace spdlog
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3+
4+
#pragma once
5+
6+
#ifndef SPDLOG_HEADER_ONLY
7+
# include <spdlog/async_logger.h>
8+
#endif
9+
10+
#include <spdlog/sinks/sink.h>
11+
#include <spdlog/details/thread_pool.h>
12+
13+
#include <memory>
14+
#include <string>
15+
16+
SPDLOG_INLINE spdlog::async_logger::async_logger(
17+
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
18+
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
19+
{}
20+
21+
SPDLOG_INLINE spdlog::async_logger::async_logger(
22+
std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
23+
: async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
24+
{}
25+
26+
// send the log message to the thread pool
27+
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
28+
{
29+
if (auto pool_ptr = thread_pool_.lock())
30+
{
31+
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
32+
}
33+
else
34+
{
35+
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
36+
}
37+
}
38+
39+
// send flush request to the thread pool
40+
SPDLOG_INLINE void spdlog::async_logger::flush_()
41+
{
42+
if (auto pool_ptr = thread_pool_.lock())
43+
{
44+
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
45+
}
46+
else
47+
{
48+
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
49+
}
50+
}
51+
52+
//
53+
// backend functions - called from the thread pool to do the actual job
54+
//
55+
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg)
56+
{
57+
for (auto &sink : sinks_)
58+
{
59+
if (sink->should_log(msg.level))
60+
{
61+
SPDLOG_TRY
62+
{
63+
sink->log(msg);
64+
}
65+
SPDLOG_LOGGER_CATCH(msg.source)
66+
}
67+
}
68+
69+
if (should_flush_(msg))
70+
{
71+
backend_flush_();
72+
}
73+
}
74+
75+
SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
76+
{
77+
for (auto &sink : sinks_)
78+
{
79+
SPDLOG_TRY
80+
{
81+
sink->flush();
82+
}
83+
SPDLOG_LOGGER_CATCH(source_loc())
84+
}
85+
}
86+
87+
SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
88+
{
89+
auto cloned = std::make_shared<spdlog::async_logger>(*this);
90+
cloned->name_ = std::move(new_name);
91+
return cloned;
92+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3+
4+
#pragma once
5+
6+
// Fast asynchronous logger.
7+
// Uses pre allocated queue.
8+
// Creates a single back thread to pop messages from the queue and log them.
9+
//
10+
// Upon each log write the logger:
11+
// 1. Checks if its log level is enough to log the message
12+
// 2. Push a new copy of the message to a queue (or block the caller until
13+
// space is available in the queue)
14+
// Upon destruction, logs all remaining messages in the queue before
15+
// destructing..
16+
17+
#include <spdlog/logger.h>
18+
19+
namespace spdlog {
20+
21+
// Async overflow policy - block by default.
22+
enum class async_overflow_policy
23+
{
24+
block, // Block until message can be enqueued
25+
overrun_oldest // Discard oldest message in the queue if full when trying to
26+
// add new item.
27+
};
28+
29+
namespace details {
30+
class thread_pool;
31+
}
32+
33+
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>, public logger
34+
{
35+
friend class details::thread_pool;
36+
37+
public:
38+
template<typename It>
39+
async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp,
40+
async_overflow_policy overflow_policy = async_overflow_policy::block)
41+
: logger(std::move(logger_name), begin, end)
42+
, thread_pool_(std::move(tp))
43+
, overflow_policy_(overflow_policy)
44+
{}
45+
46+
async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
47+
async_overflow_policy overflow_policy = async_overflow_policy::block);
48+
49+
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
50+
async_overflow_policy overflow_policy = async_overflow_policy::block);
51+
52+
std::shared_ptr<logger> clone(std::string new_name) override;
53+
54+
protected:
55+
void sink_it_(const details::log_msg &msg) override;
56+
void flush_() override;
57+
void backend_sink_it_(const details::log_msg &incoming_log_msg);
58+
void backend_flush_();
59+
60+
private:
61+
std::weak_ptr<details::thread_pool> thread_pool_;
62+
async_overflow_policy overflow_policy_;
63+
};
64+
} // namespace spdlog
65+
66+
#ifdef SPDLOG_HEADER_ONLY
67+
# include "async_logger-inl.h"
68+
#endif

qt_screenshot/3rd/spdlog/cfg/argv.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2+
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3+
4+
#pragma once
5+
#include <spdlog/cfg/helpers.h>
6+
#include <spdlog/details/registry.h>
7+
8+
//
9+
// Init log levels using each argv entry that starts with "SPDLOG_LEVEL="
10+
//
11+
// set all loggers to debug level:
12+
// example.exe "SPDLOG_LEVEL=debug"
13+
14+
// set logger1 to trace level
15+
// example.exe "SPDLOG_LEVEL=logger1=trace"
16+
17+
// turn off all logging except for logger1 and logger2:
18+
// example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info"
19+
20+
namespace spdlog {
21+
namespace cfg {
22+
23+
// search for SPDLOG_LEVEL= in the args and use it to init the levels
24+
inline void load_argv_levels(int argc, const char **argv)
25+
{
26+
const std::string spdlog_level_prefix = "SPDLOG_LEVEL=";
27+
for (int i = 1; i < argc; i++)
28+
{
29+
std::string arg = argv[i];
30+
if (arg.find(spdlog_level_prefix) == 0)
31+
{
32+
auto levels_string = arg.substr(spdlog_level_prefix.size());
33+
helpers::load_levels(levels_string);
34+
}
35+
}
36+
}
37+
38+
inline void load_argv_levels(int argc, char **argv)
39+
{
40+
load_argv_levels(argc, const_cast<const char **>(argv));
41+
}
42+
43+
} // namespace cfg
44+
} // namespace spdlog

0 commit comments

Comments
 (0)