• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/include/spike/app/context.hpp
1
/*  Spike is universal dedicated module handler
2

3
    Copyright 2021-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19
#include "cache.hpp"
20
#include "spike/app_context.hpp"
21
#include "spike/crypto/jenkinshash.hpp"
22
#include "spike/util/pugi_fwd.hpp"
23
#include <map>
24
#include <mutex>
25
#include <optional>
26

27
class PathFilter;
28
struct reflectorStatic;
29
class ReflectorFriend;
30

31
struct MainAppConfFriend : MainAppConf {
32
  using MainAppConf::extractSettings;
33
  using MainAppConf::generateLog;
34
};
35

36
extern struct MainAppConfFriend mainSettings;
37

38
struct CLISettings {
39
  std::string out;
40
};
41

42
extern struct CLISettings cliSettings;
43

44
template <class func> class APPOptionalCall {
45
public:
46
  using value_type = func;
47
  APPOptionalCall() = default;
×
48
  APPOptionalCall(const APPOptionalCall &) = default;
49
  APPOptionalCall(APPOptionalCall &&) = default;
50
  APPOptionalCall &operator=(const APPOptionalCall &) = default;
51
  APPOptionalCall &operator=(APPOptionalCall &&) = default;
52
  APPOptionalCall(func obj) : object(obj) {}
53
  APPOptionalCall &operator=(func obj) {
54
    object = obj;
×
55
    return *this;
56
  }
57

58
  operator bool() const { return object != nullptr; }
×
59
  template <class... C> auto operator()(C &&...params) {
×
60
    using return_type = decltype(object(std::forward<C>(params)...));
61

62
    if constexpr (!std::is_void_v<return_type>) {
63
      if (object) {
×
64
        return object(std::forward<C>(params)...);
×
65
      }
66
      return return_type{};
67
    } else {
68
      if (object) {
×
69
        object(std::forward<C>(params)...);
×
70
      }
71
    }
72
  }
73

74
private:
75
  func object = nullptr;
76
};
77

78
struct APPContextCopyData {
×
79
  template <class C> using func = std::add_pointer_t<C>;
80
  template <class C> using opt_func = APPOptionalCall<std::add_pointer_t<C>>;
81
  opt_func<decltype(AppProcessFile)> ProcessFile;
82
  opt_func<decltype(AppExtractStat)> ExtractStat;
83
  opt_func<decltype(AppNewArchive)> NewArchive;
84
  opt_func<decltype(AppFinishContext)> FinishContext;
85
  opt_func<decltype(AppAdditionalHelp)> AdditionalHelp;
86
  const AppInfo_s *info = nullptr;
87

88
protected:
89
  const char *moduleName;
90
  opt_func<decltype(AppInitContext)> InitContext;
91
};
92

93
struct APPContext : APPContextCopyData {
94
  APPContext(const char *moduleName_, const std::string &appFolder_,
95
             const std::string &appName_);
96
  APPContext() = default;
×
97
  APPContext(const APPContext &) = delete;
98
  APPContext(APPContext &&other);
99
  ~APPContext();
100

101
  APPContext &operator=(APPContext &&other);
102

103
  ReflectorFriend &Settings() { return *info->settings; }
×
104
  const ReflectorFriend &Settings() const { return *info->settings; }
×
105

106
  void PrintCLIHelp() const;
107
  void SetupModule();
108
  void FromConfig();
109
  void ResetSwitchSettings();
110
  void GetMarkdownDoc(std::ostream &out, pugi::xml_node node) const;
111
  int ApplySetting(std::string_view key, std::string_view value);
112

113
private:
114
  void *dlHandle = nullptr;
115
  std::string appFolder;
116
  std::string appName;
117

118
  const reflectorStatic *RTTI() const;
119
  void CreateLog();
120
  void GetHelp(std::ostream &str, const reflectorStatic *ref, size_t level = 1);
121
  void GetHelp(std::ostream &str);
122
};
123

124
struct ZIPIOEntryIterator {
×
125
  ZIPIOEntryRawIterator &base;
126
  ZIPIOEntry current;
127
  std::mutex iterMtx;
128

129
  ZIPIOEntry operator++() {
×
130
    std::lock_guard<std::mutex> lg(iterMtx);
×
131
    auto retVal = current;
132
    current = base.Next();
×
133
    return retVal;
×
134
  }
135
  ZIPIOEntry operator++(int) { return operator++(); }
136
  ZIPIOEntry operator*() const { return current; }
×
137
  bool operator!=(const ZIPIOEntry &) { return current; }
×
138
};
139

140
struct ZIPIOContextIterator {
×
141
  std::unique_ptr<ZIPIOEntryRawIterator> base;
142
  ZIPIOEntryIterator begin() const { return {*base.get(), base->Fist(), {}}; }
×
143
  ZIPIOEntry end() const { return {}; }
×
144
};
145

146
struct AppContextShare : AppContext {
147
  virtual void BaseOutputPath(std::string basePath_) = 0;
148
  virtual void Finish() = 0;
149
  virtual JenHash Hash() = 0;
150
  virtual std::string FullPath() = 0;
151
  const std::vector<std::string> &SupplementalFiles() override;
152
  std::function<void()> forEachFile;
153
  std::optional<std::vector<std::string>> supplementals;
154
};
155

156
struct ZIPExtactContext;
157

158
struct ZIPIOContext : AppContextLocator {
159
  virtual std::istream *OpenFile(const ZipEntry &entry) = 0;
160
  virtual ZIPIOContextIterator
161
      Iter(ZIPIOEntryType = ZIPIOEntryType::String) const = 0;
162
  virtual std::string GetChunk(const ZipEntry &entry, size_t offset,
163
                               size_t size) const = 0;
164
  virtual std::shared_ptr<AppContextShare> Instance(ZIPIOEntry entry);
165
  virtual void Merge(ZIPExtactContext *eCtx, const std::string &records) = 0;
166
  virtual void InitMerger() = 0;
167
  virtual void Finish() = 0;
168
  const std::vector<std::string> &SupplementalFiles() override;
169
  std::string basePath;
170
  std::optional<std::vector<std::string>> supplementals;
171
};
172

173
std::shared_ptr<AppContextShare> MakeIOContext(
174
    const std::string &path,
175
    std::optional<std::vector<std::string>> supplementals = std::nullopt);
176
std::unique_ptr<ZIPIOContext> MakeZIPContext(const std::string &file,
177
                                             const PathFilter &pathFilter,
178
                                             const PathFilter &moduleFilter);
179
std::unique_ptr<ZIPIOContext> MakeZIPContext(const std::string &file);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc