INET Framework for OMNeT++/OMNEST
inet::SelfDoc Class Reference

#include <SelfDoc.h>

Public Member Functions

 SelfDoc ()
 
 ~SelfDoc () noexcept(false)
 
void insert (const std::string &text)
 

Static Public Member Functions

static bool notInInitialize ()
 
static bool notInInitialize (const char *methodFmt,...)
 
static const char * enterMethodInfo ()
 
static const char * enterMethodInfo (const char *methodFmt,...)
 
static std::string kindToStr (int kind, cProperties *properties1, const char *propName1, cProperties *properties2, const char *propName2)
 
static std::string val (const char *str)
 
static std::string val (const std::string &str)
 
static std::string keyVal (const std::string &key, const std::string &value)
 
static std::string tagsToJson (const char *key, cMessage *msg)
 
static std::string gateInfo (cGate *gate)
 

Static Public Attributes

static bool generateSelfdoc = false
 

Protected Attributes

std::set< std::string > textSet
 

Constructor & Destructor Documentation

◆ SelfDoc()

inet::SelfDoc::SelfDoc ( )
inline
23 {}

◆ ~SelfDoc()

inet::SelfDoc::~SelfDoc ( )
noexcept
38 {
39  if (generateSelfdoc) {
40  std::ofstream file;
41  file.open("/tmp/SelfDoc.txt", std::ofstream::out | std::ofstream::app);
42  if (file.fail())
43  throw std::ios_base::failure(std::strerror(errno));
44 
45  //make sure write fails with exception if something is wrong
46  file.exceptions(file.exceptions() | std::ios::failbit | std::ifstream::badbit);
47 
48  for (const auto& elem : textSet)
49  file << elem << ',' << std::endl;
50  file.close();
51  }
52 }

Member Function Documentation

◆ enterMethodInfo() [1/2]

static const char* inet::SelfDoc::enterMethodInfo ( )
inlinestatic
28 { return ""; }

◆ enterMethodInfo() [2/2]

const char * inet::SelfDoc::enterMethodInfo ( const char *  methodFmt,
  ... 
)
static
102 {
103  if (methodFmt == nullptr)
104  return "";
105  if (0 == strcmp("%s", methodFmt)) {
106  std::va_list args;
107  va_start(args, methodFmt);
108  const char *str = va_arg(args, const char *);
109  va_end(args);
110  return str;
111  }
112  else
113  return methodFmt;
114 }

◆ gateInfo()

std::string inet::SelfDoc::gateInfo ( cGate *  gate)
static
149 {
150  if (gate) {
151  std::ostringstream os;
152  os << gate->getName() << (gate->isVector() ? "[]" : "");
153  return os.str();
154  }
155  else
156  return "";
157 }

Referenced by inet::SelfDocumenterFingerprintCalculator::addEvent(), and inet::queueing::PacketProcessorBase::animate().

◆ insert()

void inet::SelfDoc::insert ( const std::string &  text)
inline

◆ keyVal()

static std::string inet::SelfDoc::keyVal ( const std::string &  key,
const std::string &  value 
)
inlinestatic

◆ kindToStr()

std::string inet::SelfDoc::kindToStr ( int  kind,
cProperties *  properties1,
const char *  propName1,
cProperties *  properties2,
const char *  propName2 
)
static
55 {
56  if (generateSelfdoc) {
57  if (properties1) {
58  auto prop = properties1->get(propName1);
59  if (!prop && properties2)
60  prop = properties2->get(propName2);
61  if (prop) {
62  if (auto propValue = prop->getValue()) {
63  if (auto e = omnetpp::cEnum::find(propValue)) {
64  if (auto t = e->getStringFor(kind)) {
65  std::ostringstream os;
66  os << kind << " (" << propValue << "::" << t << ")";
67  return os.str();
68  }
69  }
70  }
71  }
72  }
73  return std::to_string(kind);
74  }
75  else
76  return std::string("");
77 }

Referenced by inet::SelfDocumenterFingerprintCalculator::addEvent(), and inet::queueing::PacketProcessorBase::animate().

◆ notInInitialize() [1/2]

static bool inet::SelfDoc::notInInitialize ( )
inlinestatic
26 { return true; }

◆ notInInitialize() [2/2]

static bool inet::SelfDoc::notInInitialize ( const char *  methodFmt,
  ... 
)
inlinestatic
27 { return methodFmt != nullptr && (0 != strcmp(methodFmt, "initialize(%d)")); }

◆ tagsToJson()

std::string inet::SelfDoc::tagsToJson ( const char *  key,
cMessage *  msg 
)
static
126 {
127  std::set<std::string> tagSet;
128  std::ostringstream os;
129  auto tags = findTags(msg);
130  if (tags) {
131  auto cnt = tags->getNumTags();
132  for (int i=0; i < cnt; i++) {
133  auto tag = tags->getTag(i).get();
134  if (tag)
135  tagSet.insert(opp_typename(typeid(*tag)));
136  }
137  }
138  os << SelfDoc::val(key) << " : [ ";
139  const char *sep = "";
140  for (const auto& t : tagSet) {
141  os << sep << SelfDoc::val(t);
142  sep = ", ";
143  }
144  os << " ]";
145  return os.str();
146 }

Referenced by inet::SelfDocumenterFingerprintCalculator::addEvent(), and inet::queueing::PacketProcessorBase::animate().

◆ val() [1/2]

std::string inet::SelfDoc::val ( const char *  str)
static
80 {
81  std::ostringstream os;
82  os << '"';
83  char hexbuf[5];
84  while (*str) {
85  switch (*str) {
86  case '\b': os << "\\b"; break;
87  case '\f': os << "\\f"; break;
88  case '\n': os << "\\n"; break;
89  case '\r': os << "\\r"; break;
90  case '\t': os << "\\t"; break;
91  case '"': os << "\\\""; break;
92  case '\\': os << "\\\\"; break;
93  default: if (iscntrl(*str)) { sprintf(hexbuf,"\\x%2.2X",*str); os << hexbuf; } else { os << *str; } break;
94  }
95  str++;
96  }
97  os << '"';
98  return os.str();
99 }

Referenced by inet::SelfDocumenterFingerprintCalculator::addEvent(), inet::queueing::PacketProcessorBase::animate(), and tagsToJson().

◆ val() [2/2]

static std::string inet::SelfDoc::val ( const std::string &  str)
inlinestatic
33 { return val(str.c_str()); }

Referenced by val().

Member Data Documentation

◆ generateSelfdoc

◆ textSet

std::set<std::string> inet::SelfDoc::textSet
protected

Referenced by ~SelfDoc().


The documentation for this class was generated from the following files:
inet::SelfDoc::generateSelfdoc
static bool generateSelfdoc
Definition: SelfDoc.h:20
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
kind
removed DscpReq kind
Definition: IUdp-gates.txt:12
inet::SelfDoc::textSet
std::set< std::string > textSet
Definition: SelfDoc.h:17
tags
* tags
Definition: IUdp-gates.txt:3
inet::SelfDoc::val
static std::string val(const char *str)
Definition: SelfDoc.cc:79