GeNN  2.2.3
GPU enhanced Neuronal Networks (GeNN)
CodeHelper.h
Go to the documentation of this file.
1 
2 #ifndef __CODE_HELPER_CC
3 #define __CODE_HELPER_CC
4 
5 #include <iostream>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <cstring>
9 #include <string>
10 #include <sstream>
11 #include <vector>
12 
13 #define SAVEP(X) "(" << X << ")"
14 
15 #define OB(X) hlp.openBrace(X) //shortcut nomenclature to open the Xth curly brace { plus a new line
16 #define CB(X) hlp.closeBrace(X) //shortcut nomenclature to close the Xth curly brace } plus a new line
17 #define ENDL hlp.endl()//shortcut nomenclature to generate a newline followed correct number of indentation characters for the current level
18 
19 class CodeHelper {
20 public:
21  CodeHelper(): verbose(false) {
22  braces.push_back(0);
23  }
24 
25  void setVerbose(bool isVerbose) {
26  verbose = isVerbose;
27  }
28  string openBrace(unsigned int level) {
29  braces.push_back(level);
30  if (verbose) printf("%sopen %u.\n",indentBy(braces.size() - 1).c_str(),level);
31  string result = " {\n";
32  result.append(indentBy(braces.size() - 1));
33  return result;
34  }
35 
36  string closeBrace(unsigned int level) {
37  if (braces.back()==level) {
38  if (verbose) printf("%sclose %u.\n",indentBy(braces.size() - 1).c_str(),level);
39  braces.pop_back();
40  string result = "}\n";
41  result.append(indentBy(braces.size() - 1));
42  return result;
43  } else {
44  cerr << "Code generation error: Attempted to close brace " << level << ", expecting brace " << braces.back() << "\n" ;
45  exit(1);
46  }
47  }
48 
49  string endl() const{
50  string result = "\n";
51  //put out right number of tabs for level depth
52  result.append(indentBy(braces.size() - 1));
53  return result;
54  }
55 
56 private:
57  string indentBy(unsigned int numIndents) const{
58  string result = "";
59  for (int i = 0; i < numIndents; i++) {
60  result.append(" ");
61  }
62  return result;
63  }
64 
65  vector<unsigned int> braces;
66  bool verbose;
67 };
68 
69 extern CodeHelper hlp;
70 
71 #endif
Definition: CodeHelper.h:19
CodeHelper hlp
Definition: generateALL.cc:42
string openBrace(unsigned int level)
Definition: CodeHelper.h:28
string closeBrace(unsigned int level)
Definition: CodeHelper.h:36
string endl() const
Definition: CodeHelper.h:49
void setVerbose(bool isVerbose)
Definition: CodeHelper.h:25
CodeHelper()
Definition: CodeHelper.h:21