Monarch  v3.8.2
Project 8 Data File Format Library
M3Record.cc
Go to the documentation of this file.
1 /*
2  * M3Record.cc
3  *
4  * Created on: Dec 26, 2014
5  * Author: nsoblath
6  */
7 #define M3_API_EXPORTS
8 
9 #include "M3Record.hh"
10 
11 namespace monarch3
12 {
13  M3Record::M3Record( unsigned aNBytes ) :
14  fOwnsData( true ),
15  fRecordId( NULL ),
16  fTime( NULL ),
17  fData( NULL )
18  {
19  if( aNBytes != 0 )
20  {
21  fRecordId = new RecordIdType();
22  fTime = new TimeType();
23  fData = new byte_type[ aNBytes ];
24  }
25  }
26 
27  M3Record::M3Record( RecordIdType* aRecPtr, TimeType* aTimePtr, byte_type* aDataPtr ) :
28  fOwnsData( false ),
29  fRecordId( aRecPtr ),
30  fTime( aTimePtr ),
31  fData( aDataPtr )
32  {
33  }
34 
36  {
37  ClearData();
38  }
39 
41  {
42  ClearData();
43  return;
44  }
45 
46  void M3Record::Initialize( unsigned aNBytes )
47  {
48  ClearData();
49  fRecordId = new RecordIdType();
50  fTime = new TimeType();
51  SetRecordId( 0 );
52  SetTime( 0 );
53  fData = new byte_type[ aNBytes ];
54  return;
55  }
56 
57  void M3Record::Initialize( RecordIdType* aRecPtr, TimeType* aTimePtr, byte_type* aDataPtr )
58  {
59  ClearData();
60  fOwnsData = false;
61  fRecordId = aRecPtr;
62  fTime = aTimePtr;
63  fData = aDataPtr;
64  return;
65  }
66 
68  {
69  if( fOwnsData )
70  {
71  delete fRecordId;
72  delete fTime;
73  delete [] fData;
74  }
75  fRecordId = NULL;
76  fTime = NULL;
77  fData = NULL;
78  fOwnsData = true;
79  return;
80  }
81 
82  void M3Record::UpdateDataPtr( const byte_type* aDataPtr ) const
83  {
84  const_cast< M3Record* >(this)->UpdateDataPtr( const_cast< byte_type* >( aDataPtr ) );
85  return;
86  }
87 
89  {
90  if( fOwnsData )
91  {
92  throw M3Exception() << "Cannot update data pointer when the record owns the data";
93  }
94  fData = aDataPtr;
95  return;
96  }
97 
98 }
Contains the information that makes up a record.
Definition: M3Record.hh:35
byte_type * fData
Definition: M3Record.hh:75
void Initialize()
Allocate no memory for the record; data pointer is to NULL.
Definition: M3Record.cc:40
uint8_t byte_type
Definition: M3Types.hh:22
RecordIdType * fRecordId
Definition: M3Record.hh:72
void SetRecordId(RecordIdType aId)
Definition: M3Record.hh:89
M3Record(unsigned aNBytes=0)
Definition: M3Record.cc:13
void SetTime(TimeType aTime)
Definition: M3Record.hh:105
uint64_t RecordIdType
Definition: M3Types.hh:25
uint64_t TimeType
Definition: M3Types.hh:26
Specialized exception class for Monarch3.
Definition: M3Exception.hh:28
void UpdateDataPtr(const byte_type *aDataPtr) const
Definition: M3Record.cc:82
TimeType * fTime
Definition: M3Record.hh:73