1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#ifndef CLDAPSETTINGSSTORE_HPP
#define CLDAPSETTINGSSTORE_HPP
#include "JSON.h"
#include "dap/dap.hpp"
#include "wxStringHash.h"
#include <map>
#include <wx/filename.h>
enum class DapPathFormat : size_t {
PATH_NATIVE = 0,
// relative path: file name only
PATH_RELATIVE = (1 << 0),
// forward slash, always
PATH_FORWARD_SLASH = (1 << 1),
// MSW: use volume in path
PATH_NO_VOLUME = (1 << 2),
};
enum class DapLaunchType {
LAUNCH = 0,
ATTACH,
};
class DapEntry
{
wxString m_command;
wxString m_name;
wxString m_connection_string;
wxString m_environment;
size_t m_flags = (size_t)DapPathFormat::PATH_NATIVE; // bitset of DapPathFormats
dap::EnvFormat m_envFormat = dap::EnvFormat::LIST;
DapLaunchType m_launch_type = DapLaunchType::LAUNCH;
private:
void SetFlag(DapPathFormat flag, bool b)
{
if(b) {
m_flags |= (size_t)flag;
} else {
m_flags &= ~(size_t)flag;
}
}
bool HasFlag(DapPathFormat flag) const { return m_flags & (size_t)flag; }
public:
DapEntry() {}
~DapEntry() {}
void SetEnvFormat(const dap::EnvFormat& envFormat) { this->m_envFormat = envFormat; }
dap::EnvFormat GetEnvFormat() const { return m_envFormat; }
void SetCommand(const wxString& command) { this->m_command = command; }
void SetName(const wxString& name) { this->m_name = name; }
void SetConnectionString(const wxString& connection_string) { this->m_connection_string = connection_string; }
const wxString& GetCommand() const { return m_command; }
const wxString& GetName() const { return m_name; }
const wxString& GetConnectionString() const { return m_connection_string; }
void SetEnvironment(const wxString& environment) { this->m_environment = environment; }
const wxString& GetEnvironment() const { return m_environment; }
void SetUseVolume(bool b) { SetFlag(DapPathFormat::PATH_NO_VOLUME, !b); }
bool UseVolume() const { return !HasFlag(DapPathFormat::PATH_NO_VOLUME); }
void SetUseRelativePath(bool b) { SetFlag(DapPathFormat::PATH_RELATIVE, b); }
bool UseRelativePath() const { return HasFlag(DapPathFormat::PATH_RELATIVE); }
void SetUseForwardSlash(bool b) { SetFlag(DapPathFormat::PATH_FORWARD_SLASH, b); }
bool UseForwardSlash() const { return HasFlag(DapPathFormat::PATH_FORWARD_SLASH); }
bool IsUsingNativePath() const { return m_flags == 0; }
void SetUseNativePath() { m_flags = 0; }
DapLaunchType GetLaunchType() const { return m_launch_type; }
void SetLaunchType(DapLaunchType type) { m_launch_type = type; }
JSONItem To() const;
void From(const JSONItem& json);
};
class clDapSettingsStore
{
std::map<wxString, DapEntry> m_entries;
public:
clDapSettingsStore();
~clDapSettingsStore();
void Load(const wxFileName& file);
void Save(const wxFileName& file);
bool IsEmpty() const { return m_entries.empty(); }
bool Get(const wxString& name, DapEntry* entry) const;
bool Contains(const wxString& name) const;
bool Set(const DapEntry& entry);
/**
* @brief replace all entries with this list
* @param entries
*/
void Set(const std::vector<DapEntry>& entries);
/**
* @brief update the list. If a dap server already exists with the same name
* it will be replaced
*/
void Update(const std::vector<DapEntry>& entries);
bool Delete(const wxString& name);
const std::map<wxString, DapEntry>& GetEntries() const { return m_entries; }
void Clear();
bool empty() const { return IsEmpty(); }
size_t size() const { return m_entries.size(); }
};
#endif // CLDAPSETTINGSSTORE_HPP
|