Raw.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 00 Debug Routines */
10 
11 #ifndef SQUID_SRC_BASE_RAW_H
12 #define SQUID_SRC_BASE_RAW_H
13 
14 #include <iosfwd>
15 
20 class Raw
21 {
22 public:
23  Raw(const char *label, const char *data, const size_t size):
24  level(-1), label_(label), data_(data), size_(size), useHex_(false), useGap_(true) {}
25 
27  Raw &minLevel(const int aLevel) { level = aLevel; return *this; }
28 
30  Raw &hex() { useHex_ = true; return *this; }
31 
32  Raw &gap(bool useGap = true) { useGap_ = useGap; return *this; }
33 
40  std::ostream &print(std::ostream &os) const;
41 
45  int level;
46 
47 private:
48  void printHex(std::ostream &os) const;
49 
50  const char *label_;
51  const char *data_;
52  size_t size_;
53  bool useHex_;
54  bool useGap_;
55 };
56 
57 inline std::ostream &
58 operator <<(std::ostream &os, const Raw &raw)
59 {
60  raw.print(os);
61  return os;
62 }
63 
64 #endif /* SQUID_SRC_BASE_RAW_H */
65 
#define true
Definition: GnuRegex.c:234
#define false
Definition: GnuRegex.c:233
int size
Definition: ModDevPoll.cc:75
std::ostream & operator<<(std::ostream &os, const Raw &raw)
Definition: Raw.h:58
Definition: Raw.h:21
bool useGap_
whether to print leading space if label is missing
Definition: Raw.h:54
bool useHex_
whether hex() has been called
Definition: Raw.h:53
std::ostream & print(std::ostream &os) const
Definition: Raw.cc:17
const char * label_
optional data name or ID; triggers size printing
Definition: Raw.h:50
Raw & hex()
print data using two hex digits per byte (decoder: xxd -r -p)
Definition: Raw.h:30
void printHex(std::ostream &os) const
Raw(const char *label, const char *data, const size_t size)
Definition: Raw.h:23
const char * data_
raw data to be printed
Definition: Raw.h:51
Raw & minLevel(const int aLevel)
limit data printing to at least the given debugging level
Definition: Raw.h:27
int level
Definition: Raw.h:45
Raw & gap(bool useGap=true)
Definition: Raw.h:32
size_t size_
data length
Definition: Raw.h:52

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors