DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Util.cpp
Go to the documentation of this file.
1/*
2 * DUNE DAQ modification notice:
3 * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 * Renamed since fork: yes (from src/Util.cxx to src/Util.cpp).
6 *
7 * Original copyright:
8 * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9 * Licensed under the Apache License, Version 2.0.
10 */
11
12#include <stdio.h>
13
14#include <ers/internal/Util.hpp>
16
17void
18ers::tokenize( const std::string & text,
19 const std::string & separators,
20 std::vector<std::string> & result )
21{
22 std::string::size_type start_p, end_p;
23 start_p = 0;
24 do
25 {
26 end_p = text.find_first_of(separators,start_p);
27 if (end_p == std::string::npos)
28 {
29 end_p = text.length();
30 }
31 result.push_back( text.substr( start_p, end_p - start_p ) );
32 start_p = text.find_first_not_of( separators, end_p );
33 }
34 while( start_p != std::string::npos );
35}
36
37int
38ers::read_from_environment( const char * name, int default_value )
39{
40 int value = default_value;
41 const char * env = ::getenv( name );
42 if ( env )
43 {
44 if ( sscanf( env, "%d", &value ) != 1 )
45 {
46 ERS_INTERNAL_ERROR( "Wrong value \"" << env
47 << "\" is given for the \"" << name << "\" environment" )
48 }
49 }
50 return value;
51}
52
53const char *
54ers::read_from_environment( const char * name, const char * default_value )
55{
56 const char * env = ::getenv( name );
57 return ( env ? env : default_value);
58}
59
60
61
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:63
int read_from_environment(const char *name, int default_value)
Definition Util.cpp:38
void tokenize(const std::string &text, const std::string &separators, std::vector< std::string > &tokens)
Definition Util.cpp:18