Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
synchronized.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef SYNCHRONIZED_H
5#define SYNCHRONIZED_H
6
7#include <QtCore/qmutex.h>
8
9#include <atomic>
10#include <vector>
11
12QT_BEGIN_NAMESPACE
13
14template<typename T> class WriteSynchronizedRef
15{
16 Q_DISABLE_COPY_MOVE(WriteSynchronizedRef)
17
18public:
19 WriteSynchronizedRef(std::vector<T> &vector) Q_DECL_NOEXCEPT
20 : m_vector(vector)
21 {}
22
23 void emplace_back(T &&value)
24 {
25 QMutexLocker lock(&m_mutex);
26 m_vector.push_back(std::move(value));
27 }
28
29 void emplace_back(const T &value)
30 {
31 QMutexLocker lock(&m_mutex);
32 m_vector.emplace_back(value);
33 }
34
35 void emplace_bulk(std::vector<T> && values)
36 {
37 QMutexLocker lock(&m_mutex);
38 if (!m_vector.empty()) {
39 m_vector.insert(m_vector.cend(), std::make_move_iterator(values.begin()),
40 std::make_move_iterator(values.end()));
41 } else {
42 m_vector = std::move(values);
43 }
44 }
45
46private:
47 mutable QMutex m_mutex;
48 std::vector<T> &m_vector;
49};
50
51template<typename T> class ReadSynchronizedRef
52{
54
55public:
56 ReadSynchronizedRef(const std::vector<T> &v) noexcept
57 : m_vector(v)
58 {}
59
60 size_t size() const
61 {
62 return m_vector.size();
63 }
64
65 bool next(T *value) const
66 {
68 const bool hasNext = idx < m_vector.size();
69 if (hasNext)
70 *value = m_vector[idx];
71 return hasNext;
72 }
73
74private:
75 const std::vector<T> &m_vector;
76 mutable std::atomic<size_t> m_next = 0;
77};
78
79QT_END_NAMESPACE
80
81#endif
void HandleTranslationUnit(clang::ASTContext &context) override
LupdateASTConsumer(clang::ASTContext *context, Stores *stores)
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &compiler, llvm::StringRef) override
LupdateFrontendAction(Stores *stores)
bool operator()(const clang::RawComment &LHS, const clang::RawComment &RHS)
BeforeThanCompare(const clang::SourceManager &SM)
bool operator()(const clang::RawComment *LHS, const clang::RawComment *RHS)
clang::FrontendAction * create() override
LupdateToolActionFactory(Stores *stores)
bool VisitNamedDecl(clang::NamedDecl *namedDeclaration)
void findContextForTranslationStoresFromPP(clang::NamedDecl *namedDeclaration)
LupdateVisitor(clang::ASTContext *context, Stores *stores)
bool VisitCallExpr(clang::CallExpr *callExpression)
QT_WARNING_PUSH QT_WARNING_POP QT_BEGIN_NAMESPACE QString toQt(llvm::StringRef str)
Definition cpp_clang.h:36
#define LUPDATE_CLANG_VERSION
Definition cpp_clang.h:42
#define LUPDATE_CLANG_VERSION_CHECK(major, minor, patch)
Definition cpp_clang.h:41
std::vector< std::string > getAliasFunctionDefinition()
void finalize(ReadSynchronizedRef< TranslationRelatedStore > &ast, WriteSynchronizedRef< TranslationRelatedStore > &newAst)
bool stringContainsTranslationInformation(llvm::StringRef ba)
void correctAstTranslationContext(ReadSynchronizedRef< TranslationRelatedStore > &ast, WriteSynchronizedRef< TranslationRelatedStore > &newAst, const TranslationStores &qDecl)
void collectMessages(TranslatorMessageVector &result, TranslationRelatedStore &store)
TranslatorMessage translatorMessage(const TranslationRelatedStore &store, const QString &id, bool plural, bool isID, bool isWarningOnly=false)
void loadCPP(Translator &translator, const QStringList &filenames, ConversionData &cd, bool *fail)
bool hasQuote(llvm::StringRef source)
QString cleanQuote(const std::string &token)
Definition cpp_clang.h:262
void exploreChildrenForFirstStringLiteral(clang::Stmt *stmt, QString &context)
bool trFunctionPresent(llvm::StringRef text)
QString exploreBases(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
QString cleanQuote(llvm::StringRef s, QuoteCompulsary quote)
Definition cpp_clang.h:245
bool isPointWithin(const clang::SourceRange &sourceRange, const clang::SourceLocation &point, const clang::SourceManager &sm)
bool isQObjectOrQDeclareTrFunctionMacroDeclared(clang::CXXRecordDecl *recordDecl, QString &context, const clang::SourceManager &sm)
static bool capture(const QRegularExpression &exp, const QString &line, QString *i, QString *c)
bool isFileSignificant(const std::string &filePath)
QString fixedLineEndings(const QString &s)
Definition cpp_clang.h:220
QString contextForFunctionDecl(clang::FunctionDecl *func, const std::string &funcName)
QString contextForNoopMacro(clang::NamedDecl *namedDecl, const clang::SourceManager &sm)
QString lookForContext(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
Stores(TranslationStores &a, TranslationStores &qd, TranslationStores &qn)
Definition cpp_clang.h:205
WriteSynchronizedRef< TranslationRelatedStore > QDeclareTrWithContext
Definition cpp_clang.h:213
WriteSynchronizedRef< TranslationRelatedStore > QNoopTranlsationWithContext
Definition cpp_clang.h:214
TranslationStores Preprocessor
Definition cpp_clang.h:211
WriteSynchronizedRef< TranslationRelatedStore > AST
Definition cpp_clang.h:212
clang::SourceLocation sourceLocation
Definition cpp_clang.h:67
bool isValid(bool printwarning=false)
Definition cpp_clang.h:69
clang::SourceLocation callLocation(const clang::SourceManager &sourceManager)
Definition cpp_clang.h:163
void printStore() const
Definition cpp_clang.h:179
QHash< QString, QString > lupdateAllMagicMetaData
Definition cpp_clang.h:62