mrfioc2  2.3.0
Functions
mrfCommon.cpp File Reference
#include <stdexcept>
#include <iomanip>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <epicsStdio.h>
#include <epicsExport.h>
#include "mrfCommon.h"
Include dependency graph for mrfCommon.cpp:

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &strm, const MRFVersion &ver)
 
epicsUInt32 roundToUInt (double val, epicsUInt32 max)
 
char * allocSNPrintf (size_t N, const char *fmt,...)
 
int epicsParseUInt32 (const char *str, epicsUInt32 *to, int base, char **units)
 

Function Documentation

◆ allocSNPrintf()

char* allocSNPrintf ( size_t  N,
const char *  fmt,
  ... 
)

Definition at line 59 of file mrfCommon.cpp.

60 {
61  char *mem = (char*)calloc(1, N);
62  if(!mem)
63  throw std::bad_alloc();
64 
65  va_list args;
66 
67  va_start(args, fmt);
68 
69  epicsVsnprintf(mem, N, fmt, args);
70 
71  va_end(args);
72 
73  mem[N-1] = '\0';
74 
75  return mem;
76 }
Definition: evrdump.c:37

◆ epicsParseUInt32()

int epicsParseUInt32 ( const char *  str,
epicsUInt32 *  to,
int  base,
char **  units 
)

Definition at line 113 of file mrfCommon.cpp.

114 {
115  unsigned long value;
116  int status = epicsParseULong(str, &value, base, units);
117 
118  if (status)
119  return status;
120 
121 #if (ULONG_MAX > 0xffffffffULL)
122  if (value > 0xffffffffUL && value <= ~0xffffffffUL)
123  return S_stdlib_overflow;
124 #endif
125 
126  *to = (epicsUInt32) value;
127  return 0;
128 }
#define S_stdlib_overflow
Definition: mrfCommon.h:378

◆ operator<<()

std::ostream& operator<< ( std::ostream &  strm,
const MRFVersion &  ver 
)

Definition at line 33 of file mrfCommon.cpp.

34 {
35  strm<<std::hex<<ver.firmware()
36  <<std::hex<<std::setfill('0')<<std::setw(2)<<ver.revision()
37  <<'.'
38  <<((ver.subrelease()<0) ? "-" : "")
39  <<abs(ver.subrelease());
40  return strm;
41 }

◆ roundToUInt()

epicsUInt32 roundToUInt ( double  val,
epicsUInt32  max 
)

Definition at line 43 of file mrfCommon.cpp.

44 {
45  if(!isfinite(val))
46  throw std::range_error("Value not finite");
47 
48  else if(val<0)
49  throw std::range_error("Negative value not allowed");
50 
51  val+=0.5;
52 
53  if(val>(double)max)
54  throw std::range_error("Value too large");
55 
56  return (epicsUInt32)val;
57 }
#define isfinite
Definition: mrfCommon.h:326