CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
component_identifier.cppm
Go to the documentation of this file.
1//
2// Created by castle on 3/10/25.
3//
4
6
7import std;
8import reflect;
9
10export namespace cydui::components {
12 public:
13 consteval identifier_t(std::source_location loc = std::source_location::current())
14 : loc_(loc) {}
15
17 const std::string& id, std::source_location loc = std::source_location::current()
18 )
19 : loc_(loc),
20 computed_id_(id) {}
21
23 const char* id, std::source_location loc = std::source_location::current()
24 )
25 : loc_(loc),
26 computed_id_(id) {}
27
28 std::string str() const {
29 if (computed_id_.empty()) {
30 return compute_id();
31 }
32 return computed_id_;
33 }
34
35 std::string str() {
36 if (computed_id_.empty()) {
37 computed_id_ = compute_id();
38 }
39 return computed_id_;
40 }
41
42 void set_id(const std::string& id) {
43 computed_id_ = id;
44 }
45
46 const std::source_location& loc() const {
47 return loc_;
48 }
49
50 private:
51 std::string compute_id() const {
52 return std::format("{}:{}:{}", loc_.file_name(), loc_.line(), loc_.column());
53 }
54
55 private:
56 const std::source_location loc_{};
57 std::string computed_id_;
58 };
59}
consteval identifier_t(std::source_location loc=std::source_location::current())
identifier_t(const std::string &id, std::source_location loc=std::source_location::current())
void set_id(const std::string &id)
identifier_t(const char *id, std::source_location loc=std::source_location::current())
const std::source_location & loc() const