Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- ClipboardService
- {
- using Type = size_t;
- static Type registerType(const char* typeName);
- setText(const std::string& text) { ClipboardLock l; l.clear(); l.setText(text); }
- std::string getText() { ClipboardLock l; return l.getText(); }
- bool hasText() { ClipboardLock l; return l.hasText(); }
- }
- //-- support for custom types, multiple types allowed
- ClipboardLock
- {
- void set(Type type, rttr::instance data);
- rttr::variant get(Type type);
- bool has(Type type);
- clear();
- setText(const std::string& text);
- std::string getText();
- bool hasText();
- private:
- Clip::lock m_lock;
- }
- //
- void ClipboardLock::setData(Type type, rttr::instance data)
- {
- std::string serializedStr = engine::io::toJsonString(data);
- m_lock.set_data(type, serializedStr.c_str(), serializedStr.size());
- }
- rttr::variant Clipboard::getData(Type type)
- {
- assert(hasData(type));
- size_t len = m_lock.get_data_length(type);
- assert(len > 0);
- std::string buf;
- buf.resize(len);
- m_lock.get_data(type, buf.data(), len);
- return engine::io::fromJsonString(buf);
- }
- // under the hood -> crossplatform library https://github.com/dacap/clip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement