Add type-safe wrapper around NT_Value and NT_String.

Change-Id: Ib7ef5a6de9c8c7a1f5f6432083d1fb38328438dc
This commit is contained in:
Peter Johnson
2015-06-28 21:52:06 -07:00
parent 8d6a0786c8
commit f6deafee22
5 changed files with 311 additions and 53 deletions

View File

@@ -13,27 +13,28 @@
#include "ntcore.h"
#include "Value.h"
#include "llvm/StringMap.h"
namespace ntimpl {
inline llvm::StringRef MakeStringRef(const NT_String& str) {
return llvm::StringRef(str.str, str.len);
}
class StorageEntry {
public:
StorageEntry() {
NT_InitValue(&value);
flags = 0;
}
~StorageEntry() { NT_DisposeValue(&value); }
StorageEntry() { m_flags = 0; }
NT_Value value;
unsigned int flags;
Value& value() { return m_value; }
const Value& value() const { return m_value; }
unsigned int flags() const { return m_flags; }
void set_flags(unsigned int flags) { m_flags = flags; }
bool IsPersistent() const { return (m_flags & NT_PERSISTENT) != 0; }
StorageEntry(const StorageEntry&) = delete;
StorageEntry& operator=(const StorageEntry&) = delete;
private:
Value m_value;
unsigned int m_flags;
};
class Storage {
@@ -49,7 +50,7 @@ class Storage {
const EntriesMap& entries() const { return m_entries; }
void SavePersistent(std::ostream& os) const;
void LoadPersistent(std::istream& is,
bool LoadPersistent(std::istream& is,
void (*warn)(std::size_t line, const char* msg));
private: