Debian Codegraph @

brian2/devices/cpp_standalone/templates/main.cpp

raw
1 #include <stdlib.h>
2 #include "objects.h"
3 #include <csignal>
4 #include <ctime>
5 #include <time.h>
6 {{ openmp_pragma('include') }}
7 #include "run.h"
8 #include "brianlib/common_math.h"
9
10 {% for codeobj in code_objects | sort(attribute='name') %}
11 #include "code_objects/{{codeobj.name}}.h"
12 {% for block in codeobj.before_after_blocks %}
13 #include "code_objects/{{block}}_{{codeobj.name}}.h"
14 {% endfor %}
15 {% endfor %}
16
17 {% for name in user_headers | sort %}
18 #include {{name}}
19 {% endfor %}
20
21 #include <iostream>
22 #include <fstream>
23 #include <string>
24
25 {{report_func|autoindent}}
26
27 void set_from_command_line(const std::vector<std::string> args)
28 {
29 for (const auto& arg : args) {
30 // Split into two parts
31 size_t equal_sign = arg.find("=");
32 auto name = arg.substr(0, equal_sign);
33 auto value = arg.substr(equal_sign + 1, arg.length());
34 brian::set_variable_by_name(name, value);
35 }
36 }
37
38 void _int_handler(int signal_num) {
39 if (Network::_globally_running && !Network::_globally_stopped) {
40 Network::_globally_stopped = true;
41 } else {
42 std::signal(signal_num, SIG_DFL);
43 std::raise(signal_num);
44 }
45 }
46
47 int main(int argc, char **argv)
48 {
49 {% if prefs.core.stop_on_keyboard_interrupt %}
50 std::signal(SIGINT, _int_handler);
51 {% endif %}
52 std::random_device _rd;
53 std::vector<std::string> args(argv + 1, argv + argc);
54 if (args.size() >=2 && args[0] == "--results_dir")
55 {
56 brian::results_dir = args[1];
57 #ifdef DEBUG
58 std::cout << "Setting results dir to '" << brian::results_dir << "'" << std::endl;
59 #endif
60 args.erase(args.begin(), args.begin()+2);
61 }
62 {{'\n'.join(code_lines['before_start'])|autoindent}}
63 brian_start();
64 {{'\n'.join(code_lines['after_start'])|autoindent}}
65 {
66 using namespace brian;
67
68 {{ openmp_pragma('set_num_threads') }}
69 {{main_lines|autoindent}}
70 }
71 {{'\n'.join(code_lines['before_end'])|autoindent}}
72 brian_end();
73 {{'\n'.join(code_lines['after_end'])|autoindent}}
74 return 0;
75 }