DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Util.cpp
Go to the documentation of this file.
1#include <stdio.h>
2
5
6void
7ers::tokenize( const std::string & text,
8 const std::string & separators,
9 std::vector<std::string> & result )
10{
11 std::string::size_type start_p, end_p;
12 start_p = 0;
13 do
14 {
15 end_p = text.find_first_of(separators,start_p);
16 if (end_p == std::string::npos)
17 {
18 end_p = text.length();
19 }
20 result.push_back( text.substr( start_p, end_p - start_p ) );
21 start_p = text.find_first_not_of( separators, end_p );
22 }
23 while( start_p != std::string::npos );
24}
25
26int
27ers::read_from_environment( const char * name, int default_value )
28{
29 int value = default_value;
30 const char * env = ::getenv( name );
31 if ( env )
32 {
33 if ( sscanf( env, "%d", &value ) != 1 )
34 {
35 ERS_INTERNAL_ERROR( "Wrong value \"" << env
36 << "\" is given for the \"" << name << "\" environment" )
37 }
38 }
39 return value;
40}
41
42const char *
43ers::read_from_environment( const char * name, const char * default_value )
44{
45 const char * env = ::getenv( name );
46 return ( env ? env : default_value);
47}
48
49
50
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:52
int read_from_environment(const char *name, int default_value)
Definition Util.cpp:27
void tokenize(const std::string &text, const std::string &separators, std::vector< std::string > &tokens)
Definition Util.cpp:7