pvif: DBCH cleanup
avoid some duplication
This commit is contained in:
16
common/sb.h
Normal file
16
common/sb.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef SB_H
|
||||
#define SB_H
|
||||
|
||||
#include <sstream>
|
||||
|
||||
// in-line string builder (eg. for exception messages)
|
||||
// throw std::runtime_error(SB()<<"Answer: !"<<42);
|
||||
struct SB {
|
||||
std::ostringstream strm;
|
||||
SB() {}
|
||||
operator std::string() const { return strm.str(); }
|
||||
template<typename T>
|
||||
SB& operator<<(T i) { strm<<i; return *this; }
|
||||
};
|
||||
|
||||
#endif // SB_H
|
@ -19,6 +19,7 @@
|
||||
#include <pv/reftrack.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "sb.h"
|
||||
#include "pvif.h"
|
||||
|
||||
#include <epicsExport.h>
|
||||
@ -37,22 +38,22 @@ namespace pvd = epics::pvData;
|
||||
|
||||
DBCH::DBCH(dbChannel *ch) :chan(ch)
|
||||
{
|
||||
if(!chan)
|
||||
throw std::invalid_argument("NULL channel");
|
||||
if(dbChannelOpen(chan)) {
|
||||
dbChannelDelete(chan);
|
||||
throw std::invalid_argument("Failed to open channel");
|
||||
}
|
||||
prepare();
|
||||
}
|
||||
|
||||
DBCH::DBCH(const std::string& name)
|
||||
:chan(dbChannelCreate(name.c_str()))
|
||||
{
|
||||
prepare();
|
||||
}
|
||||
|
||||
void DBCH::prepare()
|
||||
{
|
||||
if(!chan)
|
||||
throw std::invalid_argument("NULL channel");
|
||||
if(dbChannelOpen(chan)) {
|
||||
dbChannelDelete(chan);
|
||||
throw std::invalid_argument("Failed to open channel "+name);
|
||||
throw std::invalid_argument(SB()<<"Failed to open channel "<<dbChannelName(chan));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@ struct epicsShareClass DBCH {
|
||||
private:
|
||||
DBCH(const DBCH&);
|
||||
DBCH& operator=(const DBCH&);
|
||||
void prepare();
|
||||
};
|
||||
|
||||
struct pdbRecordInfo {
|
||||
|
Reference in New Issue
Block a user