Allow for easy switching between fake and real env.

This commit is contained in:
King_DuckZ 2020-04-15 00:32:45 +02:00
parent a6bf45fab9
commit a1da8d1053

View file

@ -17,7 +17,13 @@
#pragma once #pragma once
#define USE_FAKE_ENV
#if defined(USE_FAKE_ENV)
# include "env_fake.hpp" # include "env_fake.hpp"
#else
# include "env_real.hpp"
#endif
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#if !defined(NDEBUG) #if !defined(NDEBUG)
@ -31,12 +37,17 @@ namespace duck {
class RunContext { class RunContext {
public: public:
typedef std::filesystem::path path_type; typedef std::filesystem::path path_type;
#if defined(USE_FAKE_ENV)
typedef EnvFake env_type;
#else
typedef EnvReal env_type;
#endif
RunContext(); RunContext();
~RunContext() noexcept = default; ~RunContext() noexcept = default;
EnvFake& env() noexcept { return m_env; } env_type& env() noexcept { return m_env; }
const EnvFake& env() const noexcept { return m_env; } const env_type& env() const noexcept { return m_env; }
void add_to_env (std::string_view colours); void add_to_env (std::string_view colours);
@ -47,7 +58,7 @@ namespace duck {
const path_type& gcc_env_d() const; const path_type& gcc_env_d() const;
private: private:
EnvFake m_env; env_type m_env;
path_type m_root; path_type m_root;
path_type m_eprefix; path_type m_eprefix;
path_type m_eroot; path_type m_eroot;
@ -58,4 +69,8 @@ namespace duck {
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::ostream& operator<< (std::ostream&, const RunContext& sp); std::ostream& operator<< (std::ostream&, const RunContext& sp);
#endif #endif
#if defined(USE_FAKE_ENV)
# undef USE_FAKE_ENV
#endif
} //namespace duck } //namespace duck