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