Swarm-NG  1.1
host_array_writer.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Eric Ford and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
29 #include "../common.hpp"
30 #include "../types/config.hpp"
31 #include "../plugin.hpp"
32 
33 #include "io.hpp"
34 #include "writer.h"
35 
36 namespace swarm { namespace log {
38 template<int NumData>
40 {
41 public:
42  typedef double data_type[NumData];
43  int bodid1, bodid2;
44  double time;
45  data_type data;
46  event_record(const int b, const double t, const double* d)
47  : bodid1(b), bodid2(-1), time(t)
48  {
49  for(int i=0;i<NumData;++i) data[i] = d[i];
50  }
51 
53  event_record(const int b1, const int b2, const double t, const double* d)
54  : bodid1(b1), bodid2(b2), time(t)
55  {
56  for(int i=0;i<NumData;++i) data[i] = d[i];
57  }
58 
60  int get_num_data() const
61  { return NumData; };
62 
63 };
64 
66 template<> class event_record<-1>
67 {
68 public:
69  typedef std::vector<double> data_type;
70  int bodid1, bodid2;
71  double time;
72  data_type data;
73 
75  event_record(const int b, const double t, const data_type& d)
76  : bodid1(b), bodid2(-1), time(t), data(d.size())
77  {
78  for(int i=0;i<data.size();++i) data[i] = d[i];
79  }
80 
82  event_record(const int b1, const int b2, const double t, const data_type& d)
83  : bodid1(b1), bodid2(b2), time(t), data(d.size())
84  {
85  for(int i=0;i<data.size();++i) data[i] = d[i];
86  }
87 
89  int get_num_data() const
90  { return data.size(); }
91 };
92 
94 template<> class event_record<0>
95 {
96 public:
97  typedef std::vector<double> data_type;
98  int bodid1, bodid2;
99  double time;
100 
102  event_record(const int b, const double t)
103  : bodid1(b), bodid2(-1), time(t)
104  { }
105 
107  event_record(const int b1, const int b2, const double t)
108  : bodid1(b1), bodid2(b2), time(t)
109  { }
110 
112  int get_num_data() const
113  { return 0; }
114 };
115 
123 class host_array_writer : public writer
124 {
125 public:
126  static const int max_num_doubles_per_event = 2;
128 protected:
129  std::vector<int> event_codes_to_log;
130  typedef std::vector<event_record_type> event_log_one_system_type;
131  typedef std::vector<event_log_one_system_type> event_log_one_code_type;
132  std::vector<event_log_one_code_type> event_log;
133  int debug;
134 
135 public:
136 
138  host_array_writer(const config &cfg);
139 
141  void add_event_type_to_log(const int et);
142 
144  event_log_one_code_type& get_event_log_all_systems(const int i)
145  { return event_log[i]; }
146 
148  const event_log_one_code_type& get_event_log_all_systems(const int i) const
149  { return event_log[i]; }
150 
152  event_log_one_system_type& get_event_log(const int i, const int sys)
153  { return event_log[i][sys]; }
154 
156  const event_log_one_system_type& get_event_log(const int i, const int sys) const
157  { return event_log[i][sys]; }
158 
160  int get_event_type(const int i) const
161  {
162  if((i>=0) && (i<event_codes_to_log.size()))
163  return event_codes_to_log[i];
164  else
165  return 0;
166  }
167 
168 
169  void reset()
170  {
171  for(int i=0;i<event_log.size();++i)
172  {
173  for(int sys=0;sys<event_log[i].size();++sys)
174  {
175  event_log[i][sys].clear();
176  }
177  }
178  }
179 
180 
183  { }
184 
185  virtual void process(const char *log_data, size_t length);
186 };
187 
188 
189 //writer_plugin_initializer< host_array_writer >
190 // host_array_writer_plugin("host_array", "This stores selected events in simple arrays on the host");
191 
192 } } // namespcae log::swarm
193