KiCad PCB EDA Suite
Loading...
Searching...
No Matches
text_eval_environment.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <kicommon.h>
23#include <wx/datetime.h>
24#include <wx/string.h>
25#include <cstdint>
26#include <functional>
27#include <map>
28#include <optional>
29#include <string>
30#include <tuple>
31#include <utility>
32
33namespace TEXT_EVAL
34{
35class SOURCE_SCOPE;
36
44{
45public:
56
58 using VCS_KEY = std::tuple<VCS_QUERY, wxString, std::string, int, bool>;
59
60 struct VCS_VALUE
61 {
62 std::string text;
63 int64_t number = 0;
64
65 bool operator==( const VCS_VALUE& ) const = default;
66 };
67
68 using CROSS_REFERENCE_KEY = std::pair<wxString, int>;
69
71 {
72 wxString text;
73 bool resolved = false;
74
75 bool operator==( const CROSS_REFERENCE_VALUE& ) const = default;
76 };
77
79 {
80 std::map<wxString, std::optional<wxString>> environmentVariables;
81 bool randomUsed = false;
82 std::optional<wxDateTime> time;
83 std::map<wxString, wxString> gitHashes;
84 std::map<VCS_KEY, VCS_VALUE> vcsValues;
85 std::map<CROSS_REFERENCE_KEY, CROSS_REFERENCE_VALUE> crossReferences;
86
87 bool operator==( const SOURCE_VALUES& ) const = default;
88 };
89
90 explicit ENVIRONMENT( const wxDateTime& aTime = wxDateTime::Now() ) :
91 m_time( aTime )
92 {
93 }
94
95 ENVIRONMENT( const ENVIRONMENT& ) = delete;
96 ENVIRONMENT& operator=( const ENVIRONMENT& ) = delete;
98
99 static ENVIRONMENT* Current();
100
104 static wxDateTime CurrentTime();
105
106 void RecordEnvironmentVariable( const wxString& aName, const std::optional<wxString>& aValue );
107 void RecordRandomUse();
108 void RecordCrossReference( const CROSS_REFERENCE_KEY& aKey, const CROSS_REFERENCE_VALUE& aValue );
109
110 bool IsCollectingSources() const { return m_sources != nullptr; }
111
115 const wxString& GitHash( const wxString& aPath, const std::function<wxString()>& aRead );
116 const VCS_VALUE& VcsValue( const VCS_KEY& aKey, const std::function<VCS_VALUE()>& aRead );
117
118private:
119 friend class SOURCE_SCOPE;
120
121 wxDateTime m_time;
122 std::map<wxString, wxString> m_gitHashes;
123 std::map<VCS_KEY, VCS_VALUE> m_vcsValues;
125};
126
127
150
151
158{
159public:
160 explicit ENVIRONMENT_SCOPE( ENVIRONMENT& aEnvironment );
162
165
166private:
168};
169} // namespace TEXT_EVAL
ENVIRONMENT_SCOPE(ENVIRONMENT &aEnvironment)
ENVIRONMENT_SCOPE & operator=(const ENVIRONMENT_SCOPE &)=delete
ENVIRONMENT_SCOPE(const ENVIRONMENT_SCOPE &)=delete
A text evaluation frame with one frozen clock and memoized external queries.
std::map< wxString, wxString > m_gitHashes
static wxDateTime CurrentTime()
void RecordEnvironmentVariable(const wxString &aName, const std::optional< wxString > &aValue)
ENVIRONMENT & operator=(const ENVIRONMENT &)=delete
ENVIRONMENT(const ENVIRONMENT &)=delete
ENVIRONMENT(const wxDateTime &aTime=wxDateTime::Now())
static ENVIRONMENT * Current()
void RecordCrossReference(const CROSS_REFERENCE_KEY &aKey, const CROSS_REFERENCE_VALUE &aValue)
std::tuple< VCS_QUERY, wxString, std::string, int, bool > VCS_KEY
Query, absolute path (Git directory for HEAD), selector or pattern, options, and whether the context ...
std::map< VCS_KEY, VCS_VALUE > m_vcsValues
std::pair< wxString, int > CROSS_REFERENCE_KEY
Record every source read through aEnvironment into aValues, including memo hits.
SOURCE_SCOPE(ENVIRONMENT &aEnvironment, ENVIRONMENT::SOURCE_VALUES &aValues)
SOURCE_SCOPE(const SOURCE_SCOPE &)=delete
SOURCE_SCOPE & operator=(const SOURCE_SCOPE &)=delete
ENVIRONMENT::SOURCE_VALUES & m_values
#define KICOMMON_API
Definition kicommon.h:27
bool operator==(const CROSS_REFERENCE_VALUE &) const =default
std::map< VCS_KEY, VCS_VALUE > vcsValues
std::map< wxString, std::optional< wxString > > environmentVariables
std::map< wxString, wxString > gitHashes
bool operator==(const SOURCE_VALUES &) const =default
std::map< CROSS_REFERENCE_KEY, CROSS_REFERENCE_VALUE > crossReferences
bool operator==(const VCS_VALUE &) const =default