-
Notifications
You must be signed in to change notification settings - Fork 90
/
int_format.cpp
46 lines (37 loc) · 1.11 KB
/
int_format.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Clip Library
// Copyright (c) 2015-2017 David Capello
#include "clip.h"
#include "random.h"
#include <cassert>
#include <iostream>
int main() {
clip::format int_format = clip::register_format("com.github.clip.CustomInt");
{
clip::lock l;
if (l.is_convertible(int_format)) {
int data = 0;
if (l.get_data(int_format, (char*)&data, sizeof(int)))
std::cout << "Existing custom data in clipboard: " << data << "\n";
else
std::cout << "Error getting existing custom data from clipboard\n";
}
else
std::cout << "Clipboard doesn't have custom data\n";
}
int newData = RandomInt(0, 9999).generate();
{
clip::lock l;
l.clear();
l.set_data(int_format, (const char*)&newData, sizeof(int));
std::cout << "Set custom data in clipboard: " << newData << "\n";
}
{
clip::lock l;
int data = 0;
l.get_data(int_format, (char*)&data, sizeof(int));
// This could fail if we are running several instances of this
// example at the same time.
assert(data == newData);
std::cout << "Get custom data in clipboard: " << data << "\n";
}
}