SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
Source.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
39 
40 #ifndef SOURCE_H_
41 #define SOURCE_H_
42 
43 #include <istream>
44 #include <string>
45 #include <sstream>
46 #include <vector>
47 
48 #include "detail/skelclDll.h"
49 
50 namespace skelcl {
51 
61 class SKELCL_DLL Source {
62 public:
63  Source();
64 
68  Source(const char* source);
69 
73  Source(const std::string& source);
74 
81  Source(std::istream& is);
82 
89  Source(std::istream&& is);
90 
94  ~Source();
95 
103  operator std::string() const;
104 
110  void append(const std::string& source);
111 
112 private:
114  std::string _source;
115 };
116 
117 
120 namespace detail {
121 
122 class SKELCL_DLL CommonDefinitions {
123 public:
124  enum Level : unsigned int {
125  PRAGMA,
126  USER_DEFINITION,
127  GENERATED_DEFINITION,
128  SIZE
129  };
130 
131  static CommonDefinitions& instance();
132 
133  static void append(const std::string& source, Level level);
134 
135  static Source getSource();
136 
137 
138 private:
139  CommonDefinitions();// = delete;
140 
141 
142  CommonDefinitions(const CommonDefinitions&);// = delete;
143  CommonDefinitions& operator=(const CommonDefinitions&) ;// = delete;
144 
145  std::vector<Source> _sources;
146 };
147 
148 class SKELCL_DLL RegisterCommonDefinition {
149 public:
150  RegisterCommonDefinition(const char* definition,
151  CommonDefinitions::Level level
152  = CommonDefinitions::Level::USER_DEFINITION);
153 };
154 
155 class RegisterCommonMacroDefinition {
156 public:
157  template <typename T>
158  RegisterCommonMacroDefinition(const char* name,
159  T&& value)
160  {
161  std::stringstream ss;
162  ss << "#define " << name << " " << value;
163  CommonDefinitions::append(ss.str(),
164  CommonDefinitions::Level::USER_DEFINITION);
165  }
166 };
167 
168 } // namespace detail
170 
171 } // namespace skelcl
172 
173 #endif // SOURCE_H_
This class is a unified wrapper for defining source code in SkelCL.
Definition: Source.h:61