45 #include <pvsutil/Assert.h>
56 Source::Source(
const char* source)
59 ASSERT_MESSAGE(!_source.empty(),
60 "Tried to create source object with empty user source.");
63 Source::Source(
const std::string& source)
66 ASSERT_MESSAGE(!_source.empty(),
67 "Tried to create source object with empty user source.");
70 Source::Source(std::istream& is)
71 : _source( (std::istreambuf_iterator<char>(is)),
72 std::istreambuf_iterator<char>() )
74 ASSERT_MESSAGE(!_source.empty(),
75 "Tried to create source object with empty user source.");
78 Source::Source(std::istream&& is)
79 : _source( (std::istreambuf_iterator<char>(is)),
80 std::istreambuf_iterator<char>() )
82 ASSERT_MESSAGE(!_source.empty(),
83 "Tried to create source object with empty user source.");
90 Source::operator std::string()
const
97 _source.append(
"\n" + source);
102 CommonDefinitions::CommonDefinitions()
103 : _sources(Level::SIZE)
107 CommonDefinitions& CommonDefinitions::instance()
109 static CommonDefinitions instance;
113 void CommonDefinitions::append(
const std::string& source, Level level)
115 CommonDefinitions::instance()._sources[level].append(source);
118 Source CommonDefinitions::getSource()
120 auto& instance = CommonDefinitions::instance();
121 auto s = instance._sources[0];
122 for (
unsigned int i = 1; i < Level::SIZE; ++i) {
123 s.append(instance._sources[i]);
128 RegisterCommonDefinition::RegisterCommonDefinition(
const char* definition,
129 CommonDefinitions::Level l)
132 if (std::string(definition).find(
"double") != std::string::npos) {
133 CommonDefinitions::append(
134 "#if defined(cl_khr_fp64)\n"
135 "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n"
136 "#elif defined(cl_amd_fp64)\n"
137 "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n"
139 CommonDefinitions::PRAGMA);
141 CommonDefinitions::append(definition, l);
void append(const std::string &source)
Append the given string to the source code.
~Source()
Default destructor.