Swarm-NG  1.1
gpulog_ilogstream.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Mario Juric *
3  * mjuric@cfa.harvard.EDU *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
27 #ifndef bits_gpulog_ilogstream_h__
28 #define bits_gpulog_ilogstream_h__
29 
30 namespace gpulog
31 {
32 namespace internal
33 {
34 
35  struct unexpected_end_of_buffer_exception : std::exception {
36  const char * what() {
37  return "Unexpected end of buffer, the record retrieved is only half correct";
38  }
39  };
40 
42  struct ilogstream
43  {
44  protected:
45  header hend;
46 
47  protected:
48  const char *const ptr;
49  size_t at, len;
50 
51  public:
53  __device__ __host__ ilogstream(const char *ptr_, size_t len_) : ptr(ptr_), at(0), len(len_), hend(-1, 0) {}
55  __device__ __host__ ilogstream(const host_log &l) : ptr(l.internal_buffer()), at(0), len(l.size()), hend(-1, 0) {}
56 
58  __device__ __host__ logrecord next()
59  {
60  // if we're at the end
61  if(at == len) { return logrecord((char *)&hend); }
62 
63  // return next packet
64  logrecord rec(ptr + at);
65  at += rec.len();
66 
67 
68  return rec;
69  }
70 
71  const size_t& cursor(){
72  return at;
73  }
74 
75  };
76 
77 }
78 }
79 
80 #endif