BuildCache
cache_entry.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2018 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_CACHE_ENTRY_HPP_
21 #define BUILDCACHE_CACHE_ENTRY_HPP_
22 
23 #include <string>
24 #include <vector>
25 
26 namespace bcache {
29 public:
31  enum class comp_mode_t {
32  NONE = 0,
33  ALL = 1
34  };
35 
37  cache_entry_t();
38 
45  cache_entry_t(const std::vector<std::string>& file_ids,
47  const std::string& std_out,
48  const std::string& std_err,
49  const int return_code);
50 
53  operator bool() const {
54  return m_valid;
55  }
56 
59  std::string serialize() const;
60 
64  static cache_entry_t deserialize(const std::string& data);
65 
67  const std::vector<std::string>& file_ids() const {
68  return m_file_ids;
69  }
70 
73  return m_compression_mode;
74  }
75 
77  const std::string& std_out() const {
78  return m_std_out;
79  }
80 
82  const std::string& std_err() const {
83  return m_std_err;
84  }
85 
87  int return_code() const {
88  return m_return_code;
89  }
90 
91 private:
92  std::vector<std::string> m_file_ids;
93  comp_mode_t m_compression_mode = comp_mode_t::NONE;
94  std::string m_std_out;
95  std::string m_std_err;
96  int m_return_code = 0;
97  bool m_valid = false; // true if this is a valid cache entry.
98 };
99 } // namespace bcache
100 
101 #endif // BUILDCACHE_CACHE_ENTRY_HPP_
bcache::cache_entry_t::std_out
const std::string & std_out() const
Definition: cache_entry.hpp:77
bcache::cache_entry_t::compression_mode
comp_mode_t compression_mode() const
Definition: cache_entry.hpp:72
bcache::cache_entry_t::comp_mode_t
comp_mode_t
Compression mode.
Definition: cache_entry.hpp:31
bcache::cache_entry_t::serialize
std::string serialize() const
Serialize a cache entry.
Definition: cache_entry.cpp:58
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::cache_entry_t::deserialize
static cache_entry_t deserialize(const std::string &data)
Deserialize a cache entry.
Definition: cache_entry.cpp:73
bcache::cache_entry_t::return_code
int return_code() const
Definition: cache_entry.hpp:87
bcache::cache_entry_t::file_ids
const std::vector< std::string > & file_ids() const
Definition: cache_entry.hpp:67
bcache::cache_entry_t::std_err
const std::string & std_err() const
Definition: cache_entry.hpp:82
bcache::cache_entry_t::comp_mode_t::NONE
@ NONE
Compress nothing (i.e. the entry is uncompressed in the cache).
bcache::cache_entry_t::cache_entry_t
cache_entry_t()
Construct an empty/invalid cache entry.
Definition: cache_entry.cpp:42
bcache::cache_entry_t
Meta data for a single cache entry.
Definition: cache_entry.hpp:28
bcache::cache_entry_t::comp_mode_t::ALL
@ ALL
Compress all files and stdout + stderr.