Loading [MathJax]/jax/input/TeX/config.js
mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
typeDescription.hpp
Go to the documentation of this file.
1/** \file typeDescription.hpp
2 * \brief Type description helper classes
3 * \ingroup utils_files
4 * \author Jared R. Males (jaredmales@gmail.com)
5 *
6 */
7
8//***********************************************************************//
9// Copyright 2018 Jared R. Males (jaredmales@gmail.com)
10//
11// This file is part of mxlib.
12//
13// mxlib is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// mxlib is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25//***********************************************************************//
26
27#ifndef typeDescription_hpp
28#define typeDescription_hpp
29
30#include <string>
31#include <vector>
32
33namespace mx
34{
35namespace meta
36{
37
38/// Struct which contains static members describing a type.
39/** Specializations are provided for the fundamental types, std::string, and std::vector of fundamental types.
40 */
41template <typename T>
43{
44 typedef T type; ///< The type iteself.
45
46 /// Returns a unique numeric code for this type.
47 static constexpr int code()
48 {
49 return -1;
50 }
51
52 /// Returns the name of this type.
53 static constexpr const char *name()
54 {
55 return "unknown";
56 }
57};
58
59template <>
60struct typeDescription<bool>
61{
62 typedef bool type;
63
64 static constexpr int code()
65 {
66 return 0;
67 }
68
69 static constexpr const char *name()
70 {
71 return "bool";
72 }
73};
74
75template <>
76struct typeDescription<signed char>
77{
78 typedef signed char type;
79
80 static constexpr int code()
81 {
82 return 1;
83 }
84
85 static constexpr const char *name()
86 {
87 return "signed char";
88 }
89};
90
91template <>
92struct typeDescription<unsigned char>
93{
94 typedef unsigned char type;
95
96 static constexpr int code()
97 {
98 return 2;
99 }
100
101 static constexpr const char *name()
102 {
103 return "unsigned char";
104 }
105};
106
107template <>
108struct typeDescription<char>
109{
110 typedef char type;
111
112 static constexpr int code()
113 {
114 return 3;
115 }
116
117 static constexpr const char *name()
118 {
119 return "char";
120 }
121};
122
123template <>
124struct typeDescription<wchar_t>
125{
126 typedef wchar_t type;
127
128 static constexpr int code()
129 {
130 return 4;
131 }
132
133 static constexpr const char *name()
134 {
135 return "wchar_t";
136 }
137};
138
139template <>
140struct typeDescription<char16_t>
141{
142 typedef char16_t type;
143
144 static constexpr int code()
145 {
146 return 5;
147 }
148
149 static constexpr const char *name()
150 {
151 return "char16_t";
152 }
153};
154
155template <>
156struct typeDescription<char32_t>
157{
158 typedef char32_t type;
159
160 static constexpr int code()
161 {
162 return 6;
163 }
164
165 static constexpr const char *name()
166 {
167 return "char32_t";
168 }
169};
170
171template <>
172struct typeDescription<int>
173{
174 typedef int type;
175
176 static constexpr int code()
177 {
178 return 7;
179 }
180
181 static constexpr const char *name()
182 {
183 return "int";
184 }
185};
186
187template <>
188struct typeDescription<unsigned int>
189{
190 typedef unsigned int type;
191
192 static constexpr int code()
193 {
194 return 8;
195 }
196
197 static constexpr const char *name()
198 {
199 return "unsigned int";
200 }
201};
202
203template <>
204struct typeDescription<short int>
205{
206 typedef short int type;
207
208 static constexpr int code()
209 {
210 return 9;
211 }
212
213 static constexpr const char *name()
214 {
215 return "short int";
216 }
217};
218
219template <>
220struct typeDescription<short unsigned int>
221{
222 typedef short unsigned int type;
223
224 static constexpr int code()
225 {
226 return 10;
227 }
228
229 static constexpr const char *name()
230 {
231 return "short unsigned int";
232 }
233};
234
235template <>
236struct typeDescription<long int>
237{
238 typedef long int type;
239
240 static constexpr int code()
241 {
242 return 11;
243 }
244
245 static constexpr const char *name()
246 {
247 return "long int";
248 }
249};
250
251template <>
252struct typeDescription<long unsigned int>
253{
254 typedef long unsigned int type;
255
256 static constexpr int code()
257 {
258 return 12;
259 }
260
261 static constexpr const char *name()
262 {
263 return "long unsigned int";
264 }
265};
266
267template <>
268struct typeDescription<long long int>
269{
270 typedef long long int type;
271
272 static constexpr int code()
273 {
274 return 13;
275 }
276
277 static constexpr const char *name()
278 {
279 return "long long int";
280 }
281};
282
283template <>
284struct typeDescription<long long unsigned int>
285{
286 typedef long long unsigned int type;
287
288 static constexpr int code()
289 {
290 return 14;
291 }
292
293 static constexpr const char *name()
294 {
295 return "long long unsigned int";
296 }
297};
298
299template <>
300struct typeDescription<float>
301{
302 typedef float type;
303
304 static constexpr int code()
305 {
306 return 15;
307 }
308
309 static constexpr const char *name()
310 {
311 return "float";
312 }
313};
314
315template <>
316struct typeDescription<double>
317{
318 typedef double type;
319
320 static constexpr int code()
321 {
322 return 16;
323 }
324
325 static constexpr const char *name()
326 {
327 return "double";
328 }
329};
330
331template <>
332struct typeDescription<long double>
333{
334 typedef long double type;
335
336 static constexpr int code()
337 {
338 return 17;
339 }
340
341 static constexpr const char *name()
342 {
343 return "long double";
344 }
345};
346
347template <>
348struct typeDescription<std::string>
349{
350 typedef std::string type;
351
352 static constexpr int code()
353 {
354 return 100;
355 }
356
357 static constexpr const char *name()
358 {
359 return "std::string";
360 }
361};
362
363template <>
364struct typeDescription<std::vector<bool>>
365{
366 typedef std::vector<bool> type;
367
368 static constexpr int code()
369 {
370 return 1000;
371 }
372
373 static constexpr const char *name()
374 {
375 return "std::vector<bool>";
376 }
377};
378
379template <>
380struct typeDescription<std::vector<signed char>>
381{
382 typedef std::vector<signed char> type;
383
384 static constexpr int code()
385 {
386 return 1001;
387 }
388
389 static constexpr const char *name()
390 {
391 return "std::vector<signed char>";
392 }
393};
394
395template <>
396struct typeDescription<std::vector<unsigned char>>
397{
398 typedef std::vector<unsigned char> type;
399
400 static constexpr int code()
401 {
402 return 1002;
403 }
404
405 static constexpr const char *name()
406 {
407 return "std::vector<unsigned char>";
408 }
409};
410
411template <>
412struct typeDescription<std::vector<char>>
413{
414 typedef std::vector<char> type;
415
416 static constexpr int code()
417 {
418 return 1003;
419 }
420
421 static constexpr const char *name()
422 {
423 return "std::vector<char>";
424 }
425};
426
427template <>
428struct typeDescription<std::vector<wchar_t>>
429{
430 typedef std::vector<wchar_t> type;
431
432 static constexpr int code()
433 {
434 return 1004;
435 }
436
437 static constexpr const char *name()
438 {
439 return "std::vector<wchar_t>";
440 }
441};
442
443template <>
444struct typeDescription<std::vector<char16_t>>
445{
446 typedef std::vector<char16_t> type;
447
448 static constexpr int code()
449 {
450 return 1005;
451 }
452
453 static constexpr const char *name()
454 {
455 return "std::vector<char16_t>";
456 }
457};
458
459template <>
460struct typeDescription<std::vector<char32_t>>
461{
462 typedef std::vector<char32_t> type;
463
464 static constexpr int code()
465 {
466 return 1006;
467 }
468
469 static constexpr const char *name()
470 {
471 return "std::vector<char32_t>";
472 }
473};
474
475template <>
476struct typeDescription<std::vector<int>>
477{
478 typedef std::vector<int> type;
479
480 static constexpr int code()
481 {
482 return 1007;
483 }
484
485 static constexpr const char *name()
486 {
487 return "std::vector<int>";
488 }
489};
490
491template <>
492struct typeDescription<std::vector<unsigned int>>
493{
494 typedef std::vector<unsigned int> type;
495
496 static constexpr int code()
497 {
498 return 1008;
499 }
500
501 static constexpr const char *name()
502 {
503 return "std::vector<unsigned int>";
504 }
505};
506
507template <>
508struct typeDescription<std::vector<short int>>
509{
510 typedef std::vector<short int> type;
511
512 static constexpr int code()
513 {
514 return 1009;
515 }
516
517 static constexpr const char *name()
518 {
519 return "std::vector<short int>";
520 }
521};
522
523template <>
524struct typeDescription<std::vector<short unsigned int>>
525{
526 typedef std::vector<short unsigned int> type;
527
528 static constexpr int code()
529 {
530 return 1010;
531 }
532
533 static constexpr const char *name()
534 {
535 return "std::vector<short unsigned int>";
536 }
537};
538
539template <>
540struct typeDescription<std::vector<long int>>
541{
542 typedef std::vector<long int> type;
543
544 static constexpr int code()
545 {
546 return 1011;
547 }
548
549 static constexpr const char *name()
550 {
551 return "std::vector<long int>";
552 }
553};
554
555template <>
556struct typeDescription<std::vector<long unsigned int>>
557{
558 typedef std::vector<long unsigned int> type;
559
560 static constexpr int code()
561 {
562 return 1012;
563 }
564
565 static constexpr const char *name()
566 {
567 return "std::vector<long unsigned int>";
568 }
569};
570
571template <>
572struct typeDescription<std::vector<long long int>>
573{
574 typedef std::vector<long long int> type;
575
576 static constexpr int code()
577 {
578 return 1013;
579 }
580
581 static constexpr const char *name()
582 {
583 return "std::vector<long long int>";
584 }
585};
586
587template <>
588struct typeDescription<std::vector<long long unsigned int>>
589{
590 typedef std::vector<long long unsigned int> type;
591
592 static constexpr int code()
593 {
594 return 1014;
595 }
596
597 static constexpr const char *name()
598 {
599 return "std::vector<long long unsigned int>";
600 }
601};
602
603template <>
604struct typeDescription<std::vector<float>>
605{
606 typedef std::vector<float> type;
607
608 static constexpr int code()
609 {
610 return 1015;
611 }
612
613 static constexpr const char *name()
614 {
615 return "std::vector<float>";
616 }
617};
618
619template <>
620struct typeDescription<std::vector<double>>
621{
622 typedef std::vector<double> type;
623
624 static constexpr int code()
625 {
626 return 1016;
627 }
628
629 static constexpr const char *name()
630 {
631 return "std::vector<double>";
632 }
633};
634
635template <>
636struct typeDescription<std::vector<long double>>
637{
638 typedef std::vector<long double> type;
639
640 static constexpr int code()
641 {
642 return 1017;
643 }
644
645 static constexpr const char *name()
646 {
647 return "std::vector<long double>";
648 }
649};
650
651template <>
652struct typeDescription<std::vector<std::string>>
653{
654 typedef std::vector<std::string> type;
655
656 static constexpr int code()
657 {
658 return 1100;
659 }
660
661 static constexpr const char *name()
662 {
663 return "std::vector<std::string>";
664 }
665};
666
667// For additions:
668/*template<>
669struct typeDescription<>
670{
671 typedef type;
672
673 static constexpr int code() { return ;
674
675 static constexpr const char * name(){ return "";}
676};*/
677
678} // namespace meta
679} // namespace mx
680
681#endif // typeDescription_hpp
The mxlib c++ namespace.
Definition mxError.hpp:106
Struct which contains static members describing a type.
static constexpr const char * name()
Returns the name of this type.
static constexpr int code()
Returns a unique numeric code for this type.