NDEVR
API Documentation
ContactInfo.h
1#pragma once
2#include <NDEVR/Model.h>
3#if NDEVR_CONTACT_INFO
4#include <NDEVR/Translator.h>
5namespace NDEVR
6{
11 class ContactName : public Model
12 {
13 public:
20 ContactName(const Model& model)
21 : Model(model)
22 {
23
24 if (!is<NDPN::type>(TypeName()))
25 {
26 //setup model for first time
27 set<NDPN::type>(TypeName());
28 }
29 }
34 void setContact(const StringView& name)
35 {
36 set<NDPO::untranslated_string_data>(name);
37 }
42 StringView getContact() const
43 {
44 return get<NDPO::untranslated_string_data>();
45 }
50 static constexpr const char* ValidRegex() { return "(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"; }
55 static constexpr const char* TypeName() { return "contact_name"; }
56 };
61 class TelephoneNumber : public Model
62 {
63 public:
70 TelephoneNumber(const Model& model)
71 : Model(model)
72 {
73 if (!model.isValid())
74 return;
75 if (!is<NDPN::type>(TypeName()))
76 {
77 //setup model for first time
78 set<NDPN::type>(TypeName());
79 set<NDPOC::name>(_t("Mobile"));
80 set<NDPO::icon>("mobile");
81 }
82 }
87 StringView phoneNumber() const
88 {
89 return get<NDPO::untranslated_string_data>();
90 }
96 void updatePhoneNumber(const StringView& phone_number, const void* lock_ptr = nullptr)
97 {
98 update<NDPO::untranslated_string_data>(phone_number, lock_ptr);
99 }
104 StringView phoneNumberName() const
105 {
106 return get<NDPO::name>();
107 }
113 void updatePhoneNumberName(const StringView& phone_number_name, const void* lock_ptr = nullptr)
114 {
115 update<NDPO::name>(phone_number_name, lock_ptr);
116 }
121 static constexpr StringView ValidRegex() { return "sad";/*TODO*/ }
126 static constexpr StringView TypeName() { return "telephone_number"; }
127
128 };
129
135 class PhysicalAddressModel : public Model
136 {
137 public:
144 PhysicalAddressModel(const Model& model)
145 : Model(model)
146 {
147 if (get<NDPN::type>() != TypeName())
148 {
149 set<NDPN::type>(TypeName());
150 setAddress("\t\t\t");
151 set<NDPOC::name>(_t("Address"));
152 set<NDPO::icon>("pin");
153 }
154 }
159 StringView address() const
160 {
161 return get<NDPO::untranslated_string_data>();
162 }
170 void setAddress(const StringView& address)
171 {
172 lib_assert(address.count('\t') == 3, "Bad Address");
173 if (address.count('\t') == 3)
174 update<NDPO::untranslated_string_data>(address);
175 }
180 StringView streetAddress() const
181 {
182 StringView address = get<NDPO::untranslated_string_data>();
183 return address.split('\t')[0];
184 }
189 void setStreetAddress(const StringView& street)
190 {
191 String current_data(get<NDPO::untranslated_string_data>());
192 Buffer<StringView> parts = current_data.split('\t');
193 lib_assert(parts.size() == 4, "Bad Address");
194 current_data.clear();
195 for (uint04 i = 0; i < parts.size(); i++)
196 {
197 if (i == 0)
198 current_data += street;
199 else
200 current_data += parts[i];
201 if (i < 3)
202 current_data += "\t";
203 }
204 setAddress(current_data);
205 }
210 StringView city() const
211 {
212 StringView s = get<NDPO::untranslated_string_data>();
213 if (s.contains('\t'))
214 return s.split('\t')[1];
215 else
216 return StringView();
217 }
222 void setCity(const StringView& city)
223 {
224 String current_data(get<NDPO::untranslated_string_data>());
225 Buffer<StringView> parts = current_data.split('\t');
226 lib_assert(parts.size() == 4, "Bad Address");
227 current_data.clear();
228 for (uint04 i = 0; i < parts.size(); i++)
229 {
230 if (i == 1)
231 current_data += city;
232 else
233 current_data += parts[i];
234 if (i < 3)
235 current_data += "\t";
236 }
237 setAddress(current_data);
238 }
239
244 String state() const
245 {
246 StringView s = get<NDPO::untranslated_string_data>();
247 if (s.count('\t') >= 2)
248 return String(s.split('\t')[2]);
249 else
250 return String();
251 }
256 void setState(const StringView& state)
257 {
258 StringView current_data(get<NDPO::untranslated_string_data>());
259 Buffer<StringView> parts = current_data.split('\t');
260 lib_assert(parts.size() == 4, "Bad Address");
261 String all_data;
262 for (uint04 i = 0; i < parts.size(); i++)
263 {
264 if (i == 2)
265 all_data += state;
266 else
267 all_data += parts[i];
268 if (i < 3)
269 all_data += "\t";
270 }
271 setAddress(all_data);
272 }
273
278 StringView zipCode() const
279 {
280 StringView s = get<NDPO::untranslated_string_data>();
281 if (s.count('\t') >= 3)
282 return s.split('\t')[3];
283 else
284 return StringView();
285 }
290 void setZipCode(const StringView& zip)
291 {
292 StringView current_data = get<NDPO::untranslated_string_data>();
293 Buffer<StringView> parts = current_data.split('\t');
294 lib_assert(parts.size() == 4, "Bad Address");
295 String all_data;
296 for (uint04 i = 0; i < parts.size(); i++)
297 {
298 if (i == 3)
299 all_data += zip;
300 else
301 all_data += parts[i];
302 if (i < 3)
303 all_data += "\t";
304 }
305 setAddress(all_data);
306 }
311 static constexpr const char* TypeName() { return "physical_address"; }
312 };
317 class EmailAddress : public Model
318 {
319 public:
326 EmailAddress(const Model& model)
327 : Model(model)
328 {
329 if (!is<NDPN::type>(TypeName()))
330 {
331 //setup model for first time
332 set<NDPN::type>(TypeName());
333 }
334 }
339 static constexpr const char* TypeName() { return "email_address"; }
344 void setEmail(const StringView& email)
345 {
346 set<NDPO::untranslated_string_data>(email);
347 }
352 StringView getEmail() const
353 {
354 return get<NDPO::untranslated_string_data>();
355 }
356 };
361 class CompanyName : public Model
362 {
363 public:
370 CompanyName(const Model& model)
371 : Model(model)
372 {
373 if (!is<NDPN::type>(TypeName()))
374 {
375 //setup model for first time
376 set<NDPN::type>(TypeName());
377 }
378 }
383 void setCompany(const StringView& companyName)
384 {
385 set<NDPO::untranslated_string_data>(companyName);
386 }
391 StringView getCompany() const
392 {
393 return get<NDPO::untranslated_string_data>();
394 }
399 static constexpr const char* TypeName() { return "company_name"; }
400 };
405 class CompanyRole : public Model
406 {
407 public:
414 CompanyRole(const Model& model)
415 : Model(model)
416 {
417 if (!is<NDPN::type>(TypeName()))
418 {
419 //setup model for first time
420 set<NDPN::type>(TypeName());
421 }
422 }
427 void setCompanyRole(const StringView& role)
428 {
429 set<NDPO::untranslated_string_data>(role);
430 }
435 StringView getCompanyRole() const
436 {
437 return get<NDPO::untranslated_string_data>();
438 }
443 static constexpr const char* TypeName() { return "company_role"; }
444 };
445
451 class ContactInfo : public Model
452 {
453 public:
461 ContactInfo(const Model& model)
462 : Model(model)
463 {
464 if (!is<NDPN::type>(TypeName()))
465 {
466 //setup model for first time
467 createChildren(5);
468 set<NDPN::type>(TypeName());
469 set<NDPOC::name>(_t("Contact"));
470 }
471 }
476 ContactName contactName()
477 {
478 return ContactName(getChild(0));
479 }
484 TelephoneNumber telephoneNumber()
485 {
486 return TelephoneNumber(getChild(1));
487 }
492 EmailAddress emailAddress()
493 {
494 return EmailAddress(getChild(2));
495 }
500 CompanyName companyName()
501 {
502 return CompanyName(getChild(3));
503 }
508 CompanyRole companyRole()
509 {
510 return CompanyRole(getChild(4));
511 }
516 static constexpr const char* TypeName() { return "contact_info"; }
517 };
518}
519#endif
A core class that represents a node on model hierarchy.
Definition Model.h:292
The primary namespace for the NDEVR SDK.