CorsikaBlock.cc
Go to the documentation of this file.
1 #include <io/CorsikaBlock.h>
2 #include <io/CorsikaIOException.h>
3 #include <utl/ErrorLogger.h>
4 
5 #include <string>
6 #include <sstream>
7 
8 #include <cstddef>
9 #include <string.h> // the C-language header
10 
11 using namespace io::Corsika;
12 using std::ostringstream;
13 using std::endl;
14 using std::string;
15 
16 
17 void
18 BlockID::SetID(const char* const id)
19 {
20  if (strlen(id) != kLength) {
21  ostringstream msg;
22  msg << "Length of string \"" << id
23  << "\" is different from " << kLength;
24  FATAL(msg);
25  throw CorsikaIOException(msg.str());
26  }
27 
28  strncpy(fID, id, kLength);
29 }
30 
31 
32 bool
33 BlockID::Is(const char* const id)
34  const
35 {
36  return strncmp(fID, id, kLength) == 0;
37 }
#define FATAL(message)
Macro for logging fatal messages.
Definition: ErrorLogger.h:167
Base for exceptions in the CORSIKA reader.
static const size_t kLength
Length of sub-block identifier.
Definition: CorsikaBlock.h:115
char fID[kLength]
Definition: CorsikaBlock.h:127
void SetID(const char *const theID)
set from c-string (for testing)
Definition: CorsikaBlock.cc:18
bool Is(const char *const theID) const
Compare ID&#39;s.
Definition: CorsikaBlock.cc:33

, generated on Tue Sep 26 2023.