SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Dirent.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_fs_Dirent_h
7 #define swcdb_fs_Dirent_h
8 
9 
10 #include "swcdb/core/Compat.h"
12 
13 
14 namespace SWC { namespace FS {
15 
17 struct Dirent final {
18 
20  Dirent() noexcept : name(), last_modification_time(), is_dir(), length() { }
21 
23  Dirent(const char* s, int64_t mod_time, bool a_is_dir, uint64_t a_length)
24  : name(s), last_modification_time(mod_time),
25  is_dir(a_is_dir), length(a_length) {
26  }
27 
29  Dirent(Dirent&& other) noexcept
30  : name(std::move(other.name)),
31  last_modification_time(other.last_modification_time),
32  is_dir(other.is_dir), length(other.length) {
33  }
34 
36  Dirent(const Dirent& other)
37  : name(other.name),
39  is_dir(other.is_dir), length(other.length) {
40  }
41 
42  ~Dirent() noexcept { }
43 
45  Dirent& operator=(Dirent&& other) noexcept {
46  name = std::move(other.name);
47  last_modification_time = other.last_modification_time;
48  is_dir = other.is_dir;
49  length = other.length;
50  return *this;
51  }
52 
53  Dirent& operator=(const Dirent&) = delete;
54 
56  std::string name;
60  bool is_dir;
62  uint64_t length;
63 
64  std::string to_string() const;
65 
67  size_t encoded_length() const noexcept {
70  + 1
72  }
73 
75  void encode(uint8_t** bufp) const {
76  Serialization::encode_bytes(bufp, name.c_str(), name.size());
79  if(!is_dir)
81  }
82 
84  void decode(const uint8_t** bufp, size_t* remainp) {
87  is_dir = Serialization::decode_bool(bufp, remainp);
88  length = is_dir ? 0 : Serialization::decode_vi64(bufp, remainp);
89  }
90 
91 };
92 
94 }}
95 
96 
97 
98 #ifdef SWC_IMPL_SOURCE
99 #include "swcdb/fs/Dirent.cc"
100 #endif
101 
102 
103 #endif // swcdb_fs_Dirent_h
SWC::FS::Dirent::~Dirent
~Dirent() noexcept
Definition: Dirent.h:42
SWC::FS::Dirent::Dirent
SWC_CAN_INLINE Dirent(const char *s, int64_t mod_time, bool a_is_dir, uint64_t a_length)
Definition: Dirent.h:23
SWC::FS::Dirent::operator=
Dirent & operator=(const Dirent &)=delete
SWC::Serialization::encoded_length_bytes
constexpr SWC_CAN_INLINE size_t encoded_length_bytes(size_t len) noexcept
Definition: Serialization.h:537
SWC::FS::Dirent::to_string
std::string to_string() const
Definition: Dirent.cc:14
SWC::FS::Dirent::is_dir
bool is_dir
Whether a directory.
Definition: Dirent.h:60
SWC::Serialization::encode_bytes
SWC_CAN_INLINE void encode_bytes(uint8_t **bufp, const void *data, size_t len)
Definition: Serialization.h:542
SWC::Serialization::encode_bool
constexpr SWC_CAN_INLINE void encode_bool(uint8_t **bufp, bool bval) noexcept
Definition: Serialization.h:102
SWC::FS::Dirent
Directory entry.
Definition: Dirent.h:17
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::FS::Dirent::last_modification_time
int64_t last_modification_time
Last modification time.
Definition: Dirent.h:58
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::FS::Dirent::Dirent
SWC_CAN_INLINE Dirent(const Dirent &other)
Definition: Dirent.h:36
Compat.h
SWC::FS::Dirent::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: Dirent.h:84
SWC::Serialization::decode_bool
constexpr SWC_CAN_INLINE bool decode_bool(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:107
SWC::FS::Dirent::name
std::string name
File or Directory name.
Definition: Dirent.h:56
Serialization.h
SWC::Serialization::encoded_length_vi64
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi64(uint64_t val) noexcept
Definition: Serialization.h:272
SWC::FS::Dirent::operator=
SWC_CAN_INLINE Dirent & operator=(Dirent &&other) noexcept
Definition: Dirent.h:45
SWC::FS::DirentList
Core::Vector< Dirent > DirentList
Definition: Dirent.h:93
SWC::FS::Dirent::Dirent
SWC_CAN_INLINE Dirent() noexcept
Definition: Dirent.h:20
SWC::Core::Vector< Dirent >
Dirent.cc
SWC::Serialization::decode_bytes_string
SWC_CAN_INLINE std::string decode_bytes_string(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:558
SWC::Serialization::decode_vi64
constexpr SWC_CAN_INLINE uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:302
SWC::FS::Dirent::length
uint64_t length
Length of file.
Definition: Dirent.h:62
SWC::FS::Dirent::Dirent
SWC_CAN_INLINE Dirent(Dirent &&other) noexcept
Definition: Dirent.h:29
SWC::Serialization::encode_vi64
constexpr SWC_CAN_INLINE void encode_vi64(uint8_t **bufp, uint64_t val)
Definition: Serialization.h:286
SWC::FS::Dirent::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: Dirent.h:75
SWC::FS::Dirent::encoded_length
SWC_CAN_INLINE size_t encoded_length() const noexcept
Definition: Dirent.h:67