Name.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef NAME_H
  2. #define NAME_H
  3. #include <memory>
  4. #include <sstream>
  5. #include <string>
  6. #include <vector>
  7. namespace Network {
  8. namespace Dns {
  9. class NameImpl;
  10. class Name
  11. {
  12. public:
  13. Name();
  14. template<typename ...Args>
  15. Name(const Args& ...args) :
  16. Name(toStringVector(args...))
  17. {
  18. }
  19. Name(const std::vector<std::string>& labels);
  20. std::string GetFirstLabel() const;
  21. std::string GetName() const;
  22. bool empty() const;
  23. bool endsWith(const Name& suffix) const;
  24. void append(const std::string& label);
  25. void prepend(const std::string& label);
  26. void swap(Name& x) noexcept;
  27. bool operator==(const Name& name) const;
  28. bool operator!=(const Name& name) const;
  29. bool operator<(const Name& name) const;
  30. private:
  31. Name(std::shared_ptr<NameImpl> pNameImpl);
  32. NameImpl* PImpl() const;
  33. private:
  34. template <class T>
  35. std::string toString(T&& t)
  36. {
  37. std::stringstream s;
  38. s << std::forward<T>(t);
  39. return s.str();
  40. }
  41. template <class... T>
  42. std::vector<std::string> toStringVector(T&&... args)
  43. {
  44. std::vector<std::string> res { toString(std::forward<T>(args))... };
  45. return res;
  46. }
  47. private:
  48. friend class Query;
  49. friend class ResourceRecord;
  50. private:
  51. std::shared_ptr<NameImpl> m_pNameImpl;
  52. };
  53. } // namespace Dns
  54. } // namespace Network
  55. #endif // NAME_H