API Documentation
Loading...
Searching...
No Matches
ContactInfo.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/Model.h>
3#if NDEVR_CONTACT_INFO
4#include <NDEVR/Translator.h>
5namespace NDEVR
6{
7 class ContactName : public Model
8 {
9 public:
10 ContactName(const Model& model)
11 : Model(model)
12 {
13
14 if (!isOfType(TypeName()))
15 {
16 //setup model for first time
17 setModelProperty(Model::e_type, TypeName());
18 }
19 }
20 void set(const String& name)
21 {
22 setProperty(DesignObject::e_untranslated_string_data, name);
23 }
24 String get() const
25 {
26 return getProperty<String>(DesignObject::e_untranslated_string_data);
27 }
28 static constexpr const char* ValidRegex() { return "(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"; }
29 static constexpr const char* TypeName() { return "contact_name"; }
30 };
31 class TelephoneNumber : public Model
32 {
33 public:
34 TelephoneNumber(const Model& model)
35 : Model(model)
36 {
37 if (!isOfType(TypeName()))
38 {
39 //setup model for first time
40 setModelProperty(Model::e_type, TypeName());
41 setProperty(Model::e_name, _t("Mobile"));
42 setProperty(Model::e_icon, "mobile");
43 }
44 }
45 String phoneNumber() const
46 {
47 return getProperty<String>(DesignObject::e_untranslated_string_data);
48 }
49 void updatePhoneNumber(const String& phone_number, const void* lock_ptr = nullptr)
50 {
51 updateProperty<String>(DesignObject::e_untranslated_string_data, phone_number, lock_ptr);
52 }
53 String phoneNumberName() const
54 {
55 return getProperty<String>(DesignObject::e_name);
56 }
57 void updatePhoneNumberName(const String& phone_number_name, const void* lock_ptr = nullptr)
58 {
59 updateProperty<String>(DesignObject::e_name, phone_number_name, lock_ptr);
60 }
61 static constexpr const char* ValidRegex() { return "sad";/*TODO*/ }
62 static constexpr const char* TypeName() { return "telephone_number"; }
63
64 };
65
66 class PhysicalAddressModel : public Model
67 {
68 public:
69 PhysicalAddressModel(const Model& model)
70 : Model(model)
71 {
72 if (getModelProperty<String>(Model::e_type) != TypeName())
73 {
74 setModelProperty(Model::e_type, TypeName());
75 setAddress("\t\t\t");
76 setProperty(Model::e_name, _t("Address"));
77 setProperty(Model::e_icon, "pin");
78 }
79 }
80 String address() const
81 {
82 return getProperty<String>(DesignObject::e_untranslated_string_data);
83 }
84 void setAddress(const String& address)
85 {
86 lib_assert(address.count('\t') == 3, "Bad Address");
87 if (address.count('\t') == 3)
88 updateProperty(DesignObject::e_untranslated_string_data, address);
89 }
90 String streetAddress() const
91 {
92 return getProperty<String>(DesignObject::e_untranslated_string_data).splitString('\t')[0];
93 }
94 void setStreetAddress(const String& street)
95 {
96 String current_data = getProperty<String>(DesignObject::e_untranslated_string_data);
97 Buffer<String> parts = current_data.splitString('\t');
98 lib_assert(parts.size() == 4, "Bad Address");
99 current_data.clear();
100 for (uint04 i = 0; i < parts.size(); i++)
101 {
102 if (i == 0)
103 current_data += street;
104 else
105 current_data += parts[i];
106 if (i < 3)
107 current_data += "\t";
108 }
109 setAddress(current_data);
110 }
111 String city() const
112 {
113 String s = getProperty<String>(DesignObject::e_untranslated_string_data);
114 if (s.contains('\t'))
115 return s.splitString('\t')[1];
116 else
117 return String();
118 }
119 void setCity(const String& city)
120 {
121 String current_data = getProperty<String>(DesignObject::e_untranslated_string_data);
122 Buffer<String> parts = current_data.splitString('\t');
123 lib_assert(parts.size() == 4, "Bad Address");
124 current_data.clear();
125 for (uint04 i = 0; i < parts.size(); i++)
126 {
127 if (i == 1)
128 current_data += city;
129 else
130 current_data += parts[i];
131 if (i < 3)
132 current_data += "\t";
133 }
134 setAddress(current_data);
135 }
136
137 String state() const
138 {
139 String s = getProperty<String>(DesignObject::e_untranslated_string_data);
140 if (s.count('\t') >= 2)
141 return s.splitString('\t')[2];
142 else
143 return String();
144 }
145 void setState(const String& state)
146 {
147 String current_data = getProperty<String>(DesignObject::e_untranslated_string_data);
148 Buffer<String> parts = current_data.splitString('\t');
149 lib_assert(parts.size() == 4, "Bad Address");
150 current_data.clear();
151 for (uint04 i = 0; i < parts.size(); i++)
152 {
153 if (i == 2)
154 current_data += state;
155 else
156 current_data += parts[i];
157 if (i < 3)
158 current_data += "\t";
159 }
160 setAddress(current_data);
161 }
162
163 String zipCode() const
164 {
165 String s = getProperty<String>(DesignObject::e_untranslated_string_data);
166 if (s.count('\t') >= 3)
167 return s.splitString('\t')[3];
168 else
169 return String();
170 }
171 void setZipCode(const String& zip)
172 {
173 String current_data = getProperty<String>(DesignObject::e_untranslated_string_data);
174 Buffer<String> parts = current_data.splitString('\t');
175 lib_assert(parts.size() == 4, "Bad Address");
176 current_data.clear();
177 for (uint04 i = 0; i < parts.size(); i++)
178 {
179 if (i == 3)
180 current_data += zip;
181 else
182 current_data += parts[i];
183 if (i < 3)
184 current_data += "\t";
185 }
186 setAddress(current_data);
187 }
188 static constexpr const char* TypeName() { return "physical_address"; }
189 };
190 class EmailAddress : public Model
191 {
192 public:
193 EmailAddress(const Model& model)
194 : Model(model)
195 {
196 if (!isOfType(TypeName()))
197 {
198 //setup model for first time
199 setModelProperty(Model::e_type, TypeName());
200 }
201 }
202 static constexpr const char* TypeName() { return "email_address"; }
203 void set(const String& email)
204 {
205 setProperty(DesignObject::e_untranslated_string_data, email);
206 }
207 String get() const
208 {
209 return getProperty<String>(DesignObject::e_untranslated_string_data);
210 }
211 };
212 class CompanyName : public Model
213 {
214 public:
215 CompanyName(const Model& model)
216 : Model(model)
217 {
218 if (!isOfType(TypeName()))
219 {
220 //setup model for first time
221 setModelProperty(Model::e_type, TypeName());
222 }
223 }
224 void set(const String& companyName)
225 {
226 setProperty(DesignObject::e_untranslated_string_data, companyName);
227 }
228 String get() const
229 {
230 return getProperty<String>(DesignObject::e_untranslated_string_data);
231 }
232 static constexpr const char* TypeName() { return "company_name"; }
233 };
234 class CompanyRole : public Model
235 {
236 public:
237 CompanyRole(const Model& model)
238 : Model(model)
239 {
240 if (!isOfType(TypeName()))
241 {
242 //setup model for first time
243 setModelProperty(Model::e_type, TypeName());
244 }
245 }
246 void set(const String& role)
247 {
248 setProperty(DesignObject::e_untranslated_string_data, role);
249 }
250 String get() const
251 {
252 return getProperty<String>(DesignObject::e_untranslated_string_data);
253 }
254 static constexpr const char* TypeName() { return "company_role"; }
255 };
256
257 class ContactInfo : public Model
258 {
259 public:
260 ContactInfo(const Model& model)
261 : Model(model)
262 {
263 if (!isOfType(TypeName()))
264 {
265 //setup model for first time
266 createChildren(5);
267 setModelProperty(Model::e_type, TypeName());
268 setProperty(DesignObject::e_name, _t("Contact"));
269 }
270 }
271 ContactName contactName()
272 {
273 return ContactName(getChild(0));
274 }
275 TelephoneNumber telephoneNumber()
276 {
277 return TelephoneNumber(getChild(1));
278 }
279 EmailAddress emailAddress()
280 {
281 return EmailAddress(getChild(2));
282 }
283 CompanyName companyName()
284 {
285 return CompanyName(getChild(3));
286 }
287 CompanyRole companyRole()
288 {
289 return CompanyRole(getChild(4));
290 }
291 static constexpr const char* TypeName() { return "contact_info"; }
292 };
293}
294#endif
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
#define _t(english_string)
Definition Translator.h:87
Definition ACIColor.h:37