]> git.sesse.net Git - casparcg/blob - common/printable.h
2.0. ampc: Fixed LOAD fail respone string.
[casparcg] / common / printable.h
1 #pragma once\r
2 \r
3 #include <string>\r
4 \r
5 #include <tbb/spin_mutex.h>\r
6 \r
7 namespace caspar {\r
8 \r
9 class printable\r
10 {\r
11         mutable tbb::spin_mutex mutex_;\r
12         const printable* parent_;\r
13 public:\r
14         printable(const printable* parent = nullptr){set_parent(parent);}\r
15 \r
16         std::wstring print() const\r
17         {\r
18                 tbb::spin_mutex::scoped_lock lock(mutex_);\r
19                 return (parent_ ? parent_->print() + L"/" : L"") + do_print();\r
20         }\r
21         \r
22         virtual void swap(object& other)\r
23         {\r
24                 tbb::spin_mutex::scoped_lock lock(mutex_);\r
25                 std::swap(parent_, other.parent_);\r
26         }\r
27         \r
28         const object* get_parent() const\r
29         {\r
30                 tbb::spin_mutex::scoped_lock lock(mutex_);\r
31                 return parent_;\r
32         }\r
33 \r
34         void set_parent(const object* parent)\r
35         {\r
36                 tbb::spin_mutex::scoped_lock lock(mutex_);\r
37                 parent_ = parent != this ? parent : nullptr;\r
38         }\r
39 \r
40 private:\r
41         virtual std::wstring do_print() const = 0;\r
42 };\r
43 \r
44 }