proxygen
folly::symbolizer::Dwarf::Path Class Reference

#include <Dwarf.h>

Public Member Functions

 Path ()
 
 Path (folly::StringPiece baseDir, folly::StringPiece subDir, folly::StringPiece file)
 
folly::StringPiece baseDir () const
 
folly::StringPiece subDir () const
 
folly::StringPiece file () const
 
size_t size () const
 
size_t toBuffer (char *buf, size_t bufSize) const
 
void toString (std::string &dest) const
 
std::string toString () const
 

Private Attributes

folly::StringPiece baseDir_
 
folly::StringPiece subDir_
 
folly::StringPiece file_
 

Detailed Description

Represent a file path a s collection of three parts (base directory, subdirectory, and file).

Definition at line 64 of file Dwarf.h.

Constructor & Destructor Documentation

folly::symbolizer::Dwarf::Path::Path ( )
inline

Definition at line 66 of file Dwarf.h.

References baseDir(), file(), and subDir().

Referenced by folly::symbolizer::Dwarf::findLocation().

66 {}
folly::symbolizer::Dwarf::Path::Path ( folly::StringPiece  baseDir,
folly::StringPiece  subDir,
folly::StringPiece  file 
)

Definition at line 167 of file Dwarf.cpp.

References baseDir_, folly::Range< Iter >::clear(), folly::Range< Iter >::empty(), file_, subDir_, folly::f14::swap(), and folly::swap().

171  : baseDir_(baseDir), subDir_(subDir), file_(file) {
172  using std::swap;
173 
174  // Normalize
175  if (file_.empty()) {
176  baseDir_.clear();
177  subDir_.clear();
178  return;
179  }
180 
181  if (file_[0] == '/') {
182  // file_ is absolute
183  baseDir_.clear();
184  subDir_.clear();
185  }
186 
187  if (!subDir_.empty() && subDir_[0] == '/') {
188  baseDir_.clear(); // subDir_ is absolute
189  }
190 
191  simplifyPath(baseDir_);
192  simplifyPath(subDir_);
193  simplifyPath(file_);
194 
195  // Make sure it's never the case that baseDir_ is empty, but subDir_ isn't.
196  if (baseDir_.empty()) {
198  }
199 }
folly::StringPiece subDir_
Definition: Dwarf.h:107
folly::StringPiece file_
Definition: Dwarf.h:108
void clear()
Definition: Range.h:411
constexpr bool empty() const
Definition: Range.h:443
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
folly::StringPiece baseDir_
Definition: Dwarf.h:106
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414

Member Function Documentation

folly::StringPiece folly::symbolizer::Dwarf::Path::baseDir ( ) const
inline

Definition at line 73 of file Dwarf.h.

References baseDir_.

Referenced by Path().

73  {
74  return baseDir_;
75  }
folly::StringPiece baseDir_
Definition: Dwarf.h:106
folly::StringPiece folly::symbolizer::Dwarf::Path::file ( ) const
inline

Definition at line 79 of file Dwarf.h.

References upload::dest, file_, size(), string, toBuffer(), and toString().

Referenced by Path().

79  {
80  return file_;
81  }
folly::StringPiece file_
Definition: Dwarf.h:108
size_t folly::symbolizer::Dwarf::Path::size ( ) const

Definition at line 201 of file Dwarf.cpp.

References baseDir_, folly::Range< Iter >::empty(), folly::Range< Iter >::endsWith(), file_, folly::Range< Iter >::size(), and subDir_.

Referenced by file(), toBuffer(), and toString().

201  {
202  size_t size = 0;
203  bool needsSlash = false;
204 
205  if (!baseDir_.empty()) {
206  size += baseDir_.size();
207  needsSlash = !baseDir_.endsWith('/');
208  }
209 
210  if (!subDir_.empty()) {
211  size += needsSlash;
212  size += subDir_.size();
213  needsSlash = !subDir_.endsWith('/');
214  }
215 
216  if (!file_.empty()) {
217  size += needsSlash;
218  size += file_.size();
219  }
220 
221  return size;
222 }
folly::StringPiece subDir_
Definition: Dwarf.h:107
folly::StringPiece file_
Definition: Dwarf.h:108
constexpr size_type size() const
Definition: Range.h:431
constexpr bool empty() const
Definition: Range.h:443
folly::StringPiece baseDir_
Definition: Dwarf.h:106
bool endsWith(const const_range_type &other) const
Definition: Range.h:849
folly::StringPiece folly::symbolizer::Dwarf::Path::subDir ( ) const
inline

Definition at line 76 of file Dwarf.h.

References subDir_.

Referenced by Path().

76  {
77  return subDir_;
78  }
folly::StringPiece subDir_
Definition: Dwarf.h:107
size_t folly::symbolizer::Dwarf::Path::toBuffer ( char *  buf,
size_t  bufSize 
) const

Copy the Path to a buffer of size bufSize.

toBuffer behaves like snprintf: It will always null-terminate the buffer (so it will copy at most bufSize-1 bytes), and it will return the number of bytes that would have been written if there had been enough room, so, if toBuffer returns a value >= bufSize, the output was truncated.

Definition at line 224 of file Dwarf.cpp.

References append(), baseDir_, folly::Range< Iter >::empty(), folly::Range< Iter >::endsWith(), file_, min, size(), and subDir_.

Referenced by file(), and folly::symbolizer::SymbolizePrinter::print().

224  {
225  size_t totalSize = 0;
226  bool needsSlash = false;
227 
228  auto append = [&](folly::StringPiece sp) {
229  if (bufSize >= 2) {
230  size_t toCopy = std::min(sp.size(), bufSize - 1);
231  memcpy(buf, sp.data(), toCopy);
232  buf += toCopy;
233  bufSize -= toCopy;
234  }
235  totalSize += sp.size();
236  };
237 
238  if (!baseDir_.empty()) {
239  append(baseDir_);
240  needsSlash = !baseDir_.endsWith('/');
241  }
242  if (!subDir_.empty()) {
243  if (needsSlash) {
244  append("/");
245  }
246  append(subDir_);
247  needsSlash = !subDir_.endsWith('/');
248  }
249  if (!file_.empty()) {
250  if (needsSlash) {
251  append("/");
252  }
253  append(file_);
254  }
255  if (bufSize) {
256  *buf = '\0';
257  }
258  assert(totalSize == size());
259  return totalSize;
260 }
folly::StringPiece subDir_
Definition: Dwarf.h:107
folly::StringPiece file_
Definition: Dwarf.h:108
void append(std::unique_ptr< IOBuf > &buf, StringPiece str)
Definition: IOBufTest.cpp:37
constexpr bool empty() const
Definition: Range.h:443
LogLevel min
Definition: LogLevel.cpp:30
folly::StringPiece baseDir_
Definition: Dwarf.h:106
bool endsWith(const const_range_type &other) const
Definition: Range.h:849
void folly::symbolizer::Dwarf::Path::toString ( std::string dest) const

Definition at line 262 of file Dwarf.cpp.

References baseDir_, folly::Range< Iter >::begin(), folly::Range< Iter >::empty(), folly::Range< Iter >::end(), file_, size(), and subDir_.

Referenced by folly::symbolizer::operator<<(), and folly::symbolizer::test::TEST().

262  {
263  size_t initialSize = dest.size();
264  dest.reserve(initialSize + size());
265  if (!baseDir_.empty()) {
266  dest.append(baseDir_.begin(), baseDir_.end());
267  }
268  if (!subDir_.empty()) {
269  if (!dest.empty() && dest.back() != '/') {
270  dest.push_back('/');
271  }
272  dest.append(subDir_.begin(), subDir_.end());
273  }
274  if (!file_.empty()) {
275  if (!dest.empty() && dest.back() != '/') {
276  dest.push_back('/');
277  }
278  dest.append(file_.begin(), file_.end());
279  }
280  assert(dest.size() == initialSize + size());
281 }
folly::StringPiece subDir_
Definition: Dwarf.h:107
folly::StringPiece file_
Definition: Dwarf.h:108
dest
Definition: upload.py:394
constexpr bool empty() const
Definition: Range.h:443
constexpr Iter end() const
Definition: Range.h:455
constexpr Iter begin() const
Definition: Range.h:452
folly::StringPiece baseDir_
Definition: Dwarf.h:106
std::string folly::symbolizer::Dwarf::Path::toString ( ) const
inline

Definition at line 97 of file Dwarf.h.

References s, and string.

Referenced by file().

97  {
98  std::string s;
99  toString(s);
100  return s;
101  }
const char * string
Definition: Conv.cpp:212
static set< string > s
std::string toString() const
Definition: Dwarf.h:97

Member Data Documentation

folly::StringPiece folly::symbolizer::Dwarf::Path::baseDir_
private

Definition at line 106 of file Dwarf.h.

Referenced by baseDir(), Path(), size(), toBuffer(), and toString().

folly::StringPiece folly::symbolizer::Dwarf::Path::file_
private

Definition at line 108 of file Dwarf.h.

Referenced by file(), Path(), size(), toBuffer(), and toString().

folly::StringPiece folly::symbolizer::Dwarf::Path::subDir_
private

Definition at line 107 of file Dwarf.h.

Referenced by Path(), size(), subDir(), toBuffer(), and toString().


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