XRootD
XrdPfc::snprintf_wrapper Struct Reference

#include <XrdPfc.hh>

+ Collaboration diagram for XrdPfc::snprintf_wrapper:

Public Member Functions

 snprintf_wrapper (const std::string &exc_prefix, int size=1024)
 
const char * c_str () const
 
void operator() (const char *fmt,...)
 

Public Attributes

std::string f_exc_prefix
 
size_t f_pos
 
std::vector< char > f_string
 

Static Public Attributes

static const size_t s_MAX_SIZE = 10 * 1024 * 1024
 

Detailed Description

Definition at line 162 of file XrdPfc.hh.

Constructor & Destructor Documentation

◆ snprintf_wrapper()

XrdPfc::snprintf_wrapper::snprintf_wrapper ( const std::string &  exc_prefix,
int  size = 1024 
)

Definition at line 75 of file XrdPfcConfiguration.cc.

75  :
76  f_exc_prefix(exc_prefix)
77 {
78  if (size < 64) size = 64;
79  f_string.resize(size);
80  f_string[0] = 0;
81  f_pos = 0;
82 }
std::string f_exc_prefix
Definition: XrdPfc.hh:165
std::vector< char > f_string
Definition: XrdPfc.hh:163

References f_pos, and f_string.

Member Function Documentation

◆ c_str()

const char* XrdPfc::snprintf_wrapper::c_str ( ) const
inline

Definition at line 173 of file XrdPfc.hh.

173 { return f_string.data(); }

References f_string.

Referenced by XrdPfc::Cache::Config().

+ Here is the caller graph for this function:

◆ operator()()

void XrdPfc::snprintf_wrapper::operator() ( const char *  fmt,
  ... 
)

Definition at line 84 of file XrdPfcConfiguration.cc.

85 {
86  va_list ap;
87  bool done = false;
88  while ( ! done) {
89  va_start(ap, fmt);
90  size_t space_left = f_string.size() - f_pos;
91  int rc = vsnprintf(f_string.data() + f_pos, space_left, fmt, ap);
92  va_end(ap);
93  if (rc < 0) {
94  throw std::runtime_error(f_exc_prefix + " - vsnprintf failure: " + std::to_string(rc));
95  }
96  size_t would_write = (size_t) rc;
97  if (would_write >= space_left) {
98  size_t new_size = f_string.size() * 2;
99  if (new_size > s_MAX_SIZE) {
100  throw std::runtime_error(f_exc_prefix + " - exceeding " + std::to_string(s_MAX_SIZE) + " bytes limit");
101  }
102  f_string.resize(f_string.size() * 2);
103  } else {
104  f_pos += would_write;
105  done = true;
106  }
107  }
108 }
static const size_t s_MAX_SIZE
Definition: XrdPfc.hh:167

References f_exc_prefix, f_pos, f_string, and s_MAX_SIZE.

Member Data Documentation

◆ f_exc_prefix

std::string XrdPfc::snprintf_wrapper::f_exc_prefix

Definition at line 165 of file XrdPfc.hh.

Referenced by operator()().

◆ f_pos

size_t XrdPfc::snprintf_wrapper::f_pos

Definition at line 164 of file XrdPfc.hh.

Referenced by snprintf_wrapper(), and operator()().

◆ f_string

std::vector<char> XrdPfc::snprintf_wrapper::f_string

Definition at line 163 of file XrdPfc.hh.

Referenced by snprintf_wrapper(), c_str(), and operator()().

◆ s_MAX_SIZE

const size_t XrdPfc::snprintf_wrapper::s_MAX_SIZE = 10 * 1024 * 1024
static

Definition at line 167 of file XrdPfc.hh.

Referenced by operator()().


The documentation for this struct was generated from the following files: