2015-06-21 23:42:29 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#ifndef NT_STORAGE_H_
|
|
|
|
|
#define NT_STORAGE_H_
|
|
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
#include <iosfwd>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
2015-06-21 23:42:29 -07:00
|
|
|
#include "ntcore.h"
|
|
|
|
|
|
|
|
|
|
#include "llvm/StringMap.h"
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
namespace ntimpl {
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-27 00:09:21 -07:00
|
|
|
inline llvm::StringRef MakeStringRef(const NT_String& str) {
|
2015-06-25 22:57:43 -07:00
|
|
|
return llvm::StringRef(str.str, str.len);
|
2015-06-22 00:25:59 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
class StorageEntry {
|
|
|
|
|
public:
|
|
|
|
|
StorageEntry() {
|
|
|
|
|
NT_InitValue(&value);
|
|
|
|
|
flags = 0;
|
|
|
|
|
}
|
|
|
|
|
~StorageEntry() { NT_DisposeValue(&value); }
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
NT_Value value;
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
|
|
StorageEntry(const StorageEntry&) = delete;
|
|
|
|
|
StorageEntry& operator=(const StorageEntry&) = delete;
|
2015-06-21 23:42:29 -07:00
|
|
|
};
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
class Storage {
|
|
|
|
|
public:
|
|
|
|
|
static Storage& GetInstance() {
|
|
|
|
|
if (!m_instance) m_instance = new Storage;
|
|
|
|
|
return *m_instance;
|
|
|
|
|
}
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
typedef llvm::StringMap<StorageEntry> EntriesMap;
|
2015-06-27 10:02:20 -07:00
|
|
|
|
|
|
|
|
EntriesMap& entries() { return m_entries; }
|
|
|
|
|
const EntriesMap& entries() const { return m_entries; }
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-27 10:22:59 -07:00
|
|
|
void SavePersistent(std::ostream& os) const;
|
|
|
|
|
void LoadPersistent(std::istream& is,
|
|
|
|
|
void (*warn)(std::size_t line, const char* msg));
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
private:
|
|
|
|
|
Storage();
|
|
|
|
|
~Storage();
|
|
|
|
|
Storage(const Storage&) = delete;
|
|
|
|
|
Storage& operator=(const Storage&) = delete;
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-27 10:02:20 -07:00
|
|
|
EntriesMap m_entries;
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
static Storage* m_instance;
|
2015-06-21 23:42:29 -07:00
|
|
|
};
|
|
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
} // namespace ntimpl
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-06-25 22:57:43 -07:00
|
|
|
#endif // NT_STORAGE_H_
|