comservatory
Strict validation of CSV files in C++
Loading...
Searching...
No Matches
Creator.hpp
Go to the documentation of this file.
1#ifndef COMSERVATORY_CREATOR_HPP
2#define COMSERVATORY_CREATOR_HPP
3
4#include <stdexcept>
5
6#include "Field.hpp"
7
14namespace comservatory {
15
34 virtual Field* create(Type t, size_t n, bool dummy) const = 0;
35
39 virtual ~FieldCreator() {}
43};
44
48template<bool validate_only>
49struct DefaultFieldCreator : public FieldCreator {
50 Field* create(Type observed, size_t n, bool dummy) const {
51 Field* ptr;
52
53 switch (observed) {
54 case STRING:
55 if (dummy || validate_only) {
56 ptr = new DummyStringField(n);
57 } else {
58 ptr = new FilledStringField(n);
59 }
60 break;
61 case NUMBER:
62 if (dummy || validate_only) {
63 ptr = new DummyNumberField(n);
64 } else {
65 ptr = new FilledNumberField(n);
66 }
67 break;
68 case BOOLEAN:
69 if (dummy || validate_only) {
70 ptr = new DummyBooleanField(n);
71 } else {
72 ptr = new FilledBooleanField(n);
73 }
74 break;
75 case COMPLEX:
76 if (dummy || validate_only) {
77 ptr = new DummyComplexField(n);
78 } else {
79 ptr = new FilledComplexField(n);
80 }
81 break;
82 default:
83 throw std::runtime_error("unrecognized type during field creation");
84 }
85
86 return ptr;
87 }
88};
93}
94
95#endif
96
Defines the Field virtual class and concrete implementations.
Contains all comservatory functions and classes.
Definition: Field.hpp:16
DummyField< std::complex< double >, COMPLEX > DummyComplexField
Definition: Field.hpp:244
Type
Definition: Type.hpp:15
FilledField< double, NUMBER > FilledNumberField
Definition: Field.hpp:209
FilledField< std::string, STRING > FilledStringField
Definition: Field.hpp:194
FilledField< std::complex< double >, COMPLEX > FilledComplexField
Definition: Field.hpp:239
FilledField< bool, BOOLEAN > FilledBooleanField
Definition: Field.hpp:224
DummyField< bool, BOOLEAN > DummyBooleanField
Definition: Field.hpp:229
DummyField< double, NUMBER > DummyNumberField
Definition: Field.hpp:214
Virtual base class for a Field creator.
Definition: Creator.hpp:23
virtual Field * create(Type t, size_t n, bool dummy) const =0
Virtual base class for a describing a field.
Definition: Field.hpp:23