Skip to content

Commit c6697d6

Browse files
committed
several years of daqman upgrades that were never backported
1 parent 20b82bf commit c6697d6

16 files changed

+757
-258
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ libMessageHandler.so: src/MessageHandler.o
4242
@$(CXX) $(LDFLAGS) $(LIBFLAGS) $^ -o $@
4343
@mv $@ lib/$@
4444

45-
libParameterList.so: src/MessageHandler.o src/VParameterNode.o src/ParameterList.o
45+
libParameterList.so: src/MessageHandler.o src/VParameterNode.o src/ParameterList.o src/ParameterIOimpl.o
4646
@echo " Generating shared library $@"
4747
@$(CXX) $(LDFLAGS) $(LIBFLAGS) $^ -o $@
4848
@mv $@ lib/$@
4949

50-
libConfigHandler.so: src/MessageHandler.o src/VParameterNode.o src/ParameterList.o src/ConfigHandler.o
50+
libConfigHandler.so: src/MessageHandler.o src/VParameterNode.o src/ParameterList.o src/ParameterIOimpl.o src/ConfigHandler.o
5151
@echo " Generating shared library $@"
5252
@$(CXX) $(LDFLAGS) $(LIBFLAGS) $^ -o $@
5353
@mv $@ lib/$@

include/CommandSwitchFunctions.hh

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <sstream>
1414
#include <string>
1515
#include "VParameterNode.hh"
16-
16+
#include "ConfigHandler.hh"
17+
1718
/** @namespace CommandSwitch
1819
@brief Defines commonly used functors for command switches
1920
@ingroup ConfigHandler
@@ -54,7 +55,12 @@ namespace CommandSwitch{
5455
public:
5556
LoadConfigFile(VParameterNode* par) : l(par) {}
5657
int operator()(const char* file)
57-
{ return l->ReadFromFile(file); }
58+
{
59+
std::string filepath = ConfigHandler::GetInstance()->FindConfigFile(file);
60+
if(filepath=="")
61+
return 1;
62+
return l->ReadFromFile(filepath.c_str());
63+
}
5864
};
5965

6066
/** @class SetValue

include/ConfigFunctor.hh

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
2828
@ingroup ConfigHandler
2929
*/
30+
31+
#include "ParameterIOimpl.hh"
32+
3033
template <typename readfunc, typename writefunc>
3134
class ConfigFunctor : public VParameterNode{
3235
public:
@@ -36,8 +39,11 @@ public:
3639
~ConfigFunctor(){}
3740

3841
std::istream& ReadFrom(std::istream& in, bool dummy=0){ return reader(in);}
39-
std::ostream& WriteTo(std::ostream& out, bool dummy1=0, int dummy=0)
42+
std::ostream& WriteTo(std::ostream& out, bool dummy1=0, int dummy=0) const
4043
{ return writer(out);}
44+
45+
ConfigFunctor<readfunc, writefunc>* Clone(const void* from, void* to) const
46+
{ return new ConfigFunctor<readfunc, writefunc>(*this); }
4147
private:
4248
readfunc reader;
4349
writefunc writer;
@@ -49,8 +55,11 @@ struct ConfigFunctorDummyRead{
4955
};
5056
/// Null-op utility class for ConfigFunctors that don't need write functionality
5157
struct ConfigFunctorDummyWrite{
52-
std::ostream& operator()(std::ostream& out){ return out; }
58+
std::ostream& operator()(std::ostream& out) const{ return out; }
5359
};
5460

61+
template<class T> struct DeprecatedParameter{
62+
std::istream& operator()(std::istream& in){ T t; return ParameterIOimpl::read(in,t); }
63+
};
5564

5665
#endif

include/ConfigHandler.hh

+18-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public:
8080
std::string GetProgramDescription(){ return _program_description; }
8181

8282
///Process the command line for the registered switches.
83-
///Returns the number of non-switch arguments remaining, neg value if error
83+
///Returns 0 in case of success
8484
int ProcessCommandLine(int& argc, char** argv);
8585

8686
///Get the number of non-switch arguments to the command line.
@@ -111,13 +111,23 @@ public:
111111
/// Get the default config file
112112
const std::string& GetDefaultCfgFile(){ return _default_cfg_file; }
113113

114+
//search multiple paths for a config file
115+
std::string FindConfigFile(const std::string& fname);
116+
117+
///Should we hide all children of disabled lists when printing?
118+
void CollapseDisabledLists(bool collapse) { _collapse_disabled = collapse; }
119+
120+
114121
private:
115122
std::string _program_usage; ///< String detailing how to use program
116123
std::string _program_description; ///< String describing the program
117124

118-
phrase _notes; ///< specify comments in a config file
125+
std::string _notes; ///< specify comments in a config file
119126
std::string _default_cfg_file; ///< default config file for this program
120127
std::string _saved_cfg; ///< name of old config file
128+
129+
std::vector<std::string> _cfg_paths; ///<list of paths to search for cfg files
130+
121131
/// Default constructor is private; singleton implementation
122132
ConfigHandler();
123133
/// Destructor also private
@@ -126,6 +136,7 @@ private:
126136
/// Copy constructor private
127137
ConfigHandler(const ConfigHandler& right) : ParameterList(),
128138
_switches(right._switches) {}
139+
129140
/// Copy constructor private
130141
ConfigHandler& operator=(const ConfigHandler& right)
131142
{ _switches = right._switches; return *this; }
@@ -158,15 +169,15 @@ private:
158169
159170
Holds the user-defined function to call when the switch is read
160171
*/
161-
template<class Action> class CommandSwitch : public VCommandSwitch{
172+
template<class Action> class TCommandSwitch : public VCommandSwitch{
162173
Action do_action;
163174
public:
164-
CommandSwitch(char short_name, const std::string& long_name,
175+
TCommandSwitch(char short_name, const std::string& long_name,
165176
const std::string& help_text, const std::string& par,
166177
Action action) :
167178
VCommandSwitch(short_name, long_name, help_text, par),
168179
do_action(action) {}
169-
virtual ~CommandSwitch() {}
180+
virtual ~TCommandSwitch() {}
170181
virtual int Process(const char* arg);
171182
};
172183

@@ -205,14 +216,14 @@ int ConfigHandler::AddCommandSwitch(char shortname,
205216
return -3;
206217
}
207218
}
208-
_switches.insert(new CommandSwitch<Action>(shortname, longname, helptext,
219+
_switches.insert(new TCommandSwitch<Action>(shortname, longname, helptext,
209220
parameter, action) );
210221
return 0;
211222
}
212223

213224

214225
template<class Action> inline
215-
int ConfigHandler::CommandSwitch<Action>::Process(const char* arg)
226+
int ConfigHandler::TCommandSwitch<Action>::Process(const char* arg)
216227
{
217228
return do_action(arg);
218229
}

include/MessageHandler.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum MESSAGE_LEVEL {DEBUG3=0, DEBUG2, DEBUG, INFO, WARNING, ERROR,
3434
CRITICAL, EXCEPTION, N_MESSAGE_LEVELS};
3535
//MESSAGE_LEVEL needs streaming and increment/decrement operators
3636
/// ostream overload for MESSAGE_LEVEL
37-
std::ostream& operator<<(std::ostream& out, MESSAGE_LEVEL& level);
37+
std::ostream& operator<<(std::ostream& out, const MESSAGE_LEVEL& level);
3838
/// istream overload for MESSAGE_LEVEL
3939
std::istream& operator>>(std::istream& in, MESSAGE_LEVEL& level);
4040
/// increment operator for MESSAGE_LEVEL

include/Parameter.hh

+40-118
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,28 @@
1111
#ifndef PARAMETER_h
1212
#define PARAMETER_h
1313
#include "VParameterNode.hh"
14+
#include "ParameterIOimpl.hh"
1415
#include "Message.hh"
16+
#include "phrase.hh"
17+
1518
#include <stdexcept>
1619
#include <string>
1720
#include <cstdlib>
1821
#include <typeinfo>
1922
#include <ctime>
2023
#include <cstdio>
2124

25+
26+
2227
/** @class Parameter
2328
@brief Template implementation of VParamterNode, allows any variable to be
2429
set/read via stl iostreams
2530
2631
@ingroup ConfigHandler
2732
*/
33+
34+
class ParameterList;
35+
2836
template<class T> class Parameter : public VParameterNode{
2937
public:
3038
/// DefaultConstructor
@@ -38,51 +46,60 @@ public:
3846
/// Assignment operator
3947
Parameter& operator=(const Parameter& right){ _val=right._val; return *this;}
4048
/// Return the underlying variable by reference
41-
const T& GetValue(){ return _val; }
49+
const T& GetValue() const { return _val; }
50+
///Return the underlying variable by pointer
51+
const T* GetPointer() const { return &_val; }
4252
/// Print information about this parameter
4353
virtual int PrintHelp(const std::string& myname="") const;
54+
55+
///Clone to new ParameterList
56+
virtual Parameter<T>* Clone(const void* from, void* to) const;
57+
58+
///access to the type of parameter for copy usage
59+
typedef T param_type;
4460
protected:
4561
/// Read the underlying variable from an istream
4662
virtual std::istream& ReadFrom( std::istream& in , bool single=false);
4763
/// Write the underlying variable to an ostream
48-
virtual std::ostream& WriteTo( std::ostream& out , bool, int);
49-
/// Read unsigned integers from istreams possibly in hex format
50-
virtual unsigned long ReadUnsignedInt(std::istream& in){
51-
std::string temp;
52-
in>>temp;
53-
if(temp[0] == '0' && (temp[1] == 'x' || temp[1] == 'X'))
54-
return std::strtoul(temp.c_str(),0,16);
55-
else
56-
return std::strtoul(temp.c_str(),0,10);
57-
}
64+
virtual std::ostream& WriteTo( std::ostream& out , bool showhelp=false,
65+
int indent=0) const;
66+
67+
//implementation of read/write is done with impls so we can overload
68+
/*std::istream& read_impl(std::istream& in, T& t){ return in>>t; }
69+
std::ostream& write_impl(std::ostream& out, T& t,
70+
bool showhelp=false, int indent=0){ return out<<t; }
71+
*/
72+
//specific impl overload
73+
5874
private:
5975
T& _val; ///< reference to the wrapped underyling variable
6076
};
61-
62-
//template members must go here so they'll actually get compiled
63-
template<class T>
77+
78+
template<class T>
6479
inline std::istream& Parameter<T>::ReadFrom(std::istream& in, bool)
6580
{
66-
if( !( in >> _val ) && !in.eof()){
81+
if( !ParameterIOimpl::read(in, _val) && !in.eof()){
6782
Message e(EXCEPTION);
6883
e<<"Error trying to read parameter with default key "<<_default_key<<"!\n";
6984
throw std::invalid_argument(e.str());
7085
}
7186
return in;
7287
}
7388

74-
template<class T>
75-
inline std::ostream& Parameter<T>::WriteTo(std::ostream& out, bool, int)
89+
template<class T>
90+
inline std::ostream& Parameter<T>::WriteTo(std::ostream& out, bool showhelp, int indent) const
7691
{
77-
return out<<_val;
92+
return ParameterIOimpl::write(out, _val, showhelp, indent);
7893
}
7994

8095
template<class T>
8196
inline int Parameter<T>::PrintHelp(const std::string& myname) const
8297
{
8398
VParameterNode::PrintHelp(myname);
8499
std::cout<<"Parameter type: "<<typeid(_val).name()<<"\n"
85-
<<"Current Value: "<<_val<<std::endl;
100+
<<"Current Value: ";
101+
ParameterIOimpl::write(std::cout, _val, true);
102+
std::cout<<std::endl;
86103
std::string dummy;
87104
std::cout<<"\nHit <enter> to continue.";
88105
std::getline(std::cin, dummy);
@@ -91,107 +108,12 @@ inline int Parameter<T>::PrintHelp(const std::string& myname) const
91108
return 0;
92109
}
93110

94-
/// Specific ostream overload for booleans
95-
template<> inline std::ostream& Parameter<bool>::WriteTo(std::ostream& out, bool, int)
111+
template<class T> inline
112+
Parameter<T>* Parameter<T>::Clone(const void* from, void* to) const
96113
{
97-
return out<<std::boolalpha<<_val<<std::noboolalpha;
114+
unsigned diff = (const char*)(GetPointer()) - (const char*)from;
115+
return new Parameter<T>((T&)(*( (char*)to+diff )), _default_key, _helptext);
98116
}
99117

100-
/// specific istream overload for booleans
101-
template<> inline std::istream& Parameter<bool>::ReadFrom(std::istream& in, bool)
102-
{
103-
std::string temp;
104-
in>>temp;
105-
if(temp == "1" || temp == "true" || temp == "TRUE")
106-
_val = true;
107-
else if( temp == "0" || temp == "false" || temp == "FALSE" )
108-
_val = false;
109-
else{
110-
Message e(EXCEPTION);
111-
e<<"Expected boolean value, got "<<temp<<std::endl;
112-
throw std::invalid_argument(e.str());
113-
}
114-
return in;
115-
}
116-
117-
/// Write the 0x prefix on unsigned integers
118-
template<> inline std::ostream& Parameter<unsigned>::WriteTo(std::ostream& out, bool, int)
119-
{
120-
return out<<std::hex<<std::showbase<<_val<<std::noshowbase<<std::dec;
121-
}
122-
123-
/// Write the 0x prefix on unsigned integers
124-
template<> inline std::ostream& Parameter<unsigned char>::WriteTo(std::ostream& out, bool,int)
125-
{
126-
return out<<std::hex<<std::showbase<<_val<<std::noshowbase<<std::dec;
127-
}
128-
129-
/// Write the 0x prefix on unsigned integers
130-
template<> inline std::ostream& Parameter<unsigned short>::WriteTo(std::ostream& out, bool, int)
131-
{
132-
return out<<std::hex<<std::showbase<<_val<<std::noshowbase<<std::dec;
133-
}
134118

135-
/// Write the 0x prefix on unsigned integers
136-
template<> inline std::ostream& Parameter<unsigned long>::WriteTo(std::ostream& out, bool, int)
137-
{
138-
return out<<std::hex<<std::showbase<<_val<<std::noshowbase<<std::dec;
139-
}
140-
141-
/// Write the 0x prefix on unsigned integers
142-
template<> inline std::ostream& Parameter<unsigned long long>::WriteTo(std::ostream& out, bool, int)
143-
{
144-
return out<<std::hex<<std::showbase<<_val<<std::noshowbase<<std::dec;
145-
}
146-
147-
/// Read unsigned ints either in decimal or hex format
148-
template<> inline std::istream& Parameter<unsigned>::ReadFrom(std::istream& in, bool)
149-
{
150-
_val = ReadUnsignedInt(in); return in;
151-
}
152-
153-
/// Read unsigned ints either in decimal or hex format
154-
template<> inline std::istream& Parameter<unsigned char>::ReadFrom(std::istream& in, bool)
155-
{
156-
_val = ReadUnsignedInt(in); return in;
157-
}
158-
159-
/// Read unsigned ints either in decimal or hex format
160-
template<> inline std::istream& Parameter<unsigned short>::ReadFrom(std::istream& in, bool)
161-
{
162-
_val = ReadUnsignedInt(in); return in;
163-
}
164-
165-
/// Read unsigned ints either in decimal or hex format
166-
template<> inline std::istream& Parameter<unsigned long>::ReadFrom(std::istream& in, bool)
167-
{
168-
_val = ReadUnsignedInt(in); return in;
169-
}
170-
171-
/// Read unsigned ints either in decimal or hex format
172-
template<> inline std::istream& Parameter<unsigned long long>::ReadFrom(std::istream& in, bool)
173-
{
174-
_val = ReadUnsignedInt(in); return in;
175-
}
176-
177-
///Override std::string's to let "" be an empty string
178-
template<> inline std::istream& Parameter<std::string>::ReadFrom(std::istream& in, bool)
179-
{
180-
std::string temp;
181-
if(in>>temp){
182-
if(temp == "\"\"")
183-
_val = "";
184-
else
185-
_val = temp;
186-
}
187-
return in;
188-
}
189-
190-
///Override std::string's to let "" be an empty string
191-
template<> inline std::ostream& Parameter<std::string>::WriteTo(std::ostream& out, bool, int)
192-
{
193-
if(_val == "")
194-
return out<<"\"\"";
195-
return out<<_val;
196-
}
197119
#endif

0 commit comments

Comments
 (0)