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