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