Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. //
  2. ClipboardService
  3. {
  4.     using Type = size_t;
  5.     static Type registerType(const char* typeName);
  6.  
  7.     setText(const std::string& text) { ClipboardLock l; l.clear(); l.setText(text); }
  8.     std::string getText() { ClipboardLock l; return l.getText(); }
  9.     bool hasText() { ClipboardLock l; return l.hasText(); }
  10. }
  11.  
  12. //-- support for custom types, multiple types allowed
  13. ClipboardLock
  14. {
  15.     void set(Type type, rttr::instance data);
  16.     rttr::variant get(Type type);
  17.     bool has(Type type);
  18.     clear();
  19.  
  20.     setText(const std::string& text);
  21.     std::string getText();
  22.     bool hasText();
  23.  
  24. private:
  25.     Clip::lock m_lock;
  26. }
  27.  
  28. //
  29. void ClipboardLock::setData(Type type, rttr::instance data)
  30. {
  31.     std::string serializedStr = engine::io::toJsonString(data);
  32.     m_lock.set_data(type, serializedStr.c_str(), serializedStr.size());
  33. }
  34.  
  35. rttr::variant Clipboard::getData(Type type)
  36. {
  37.     assert(hasData(type));
  38.  
  39.     size_t len = m_lock.get_data_length(type);
  40.     assert(len > 0);
  41.     std::string buf;
  42.     buf.resize(len);
  43.     m_lock.get_data(type, buf.data(), len);
  44.  
  45.     return engine::io::fromJsonString(buf);
  46. }
  47.  
  48. // under the hood -> crossplatform library https://github.com/dacap/clip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement