0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DirEntryAttr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hyperspace_DirEntryAttr_h
23 #define Hyperspace_DirEntryAttr_h
24 
25 #include <Common/Compat.h>
26 #include <Common/StaticBuffer.h>
27 
28 #include <string>
29 #include <vector>
30 
31 namespace Hyperspace {
32 
33  using namespace Hypertable;
34 
35  /*
36  * Listing information for each node within a directory. A vector
37  * of these objects gets passed back to the application via a call to
38  * Readdirfileattr()
39  */
40  class DirEntryAttr {
41  public:
42 
44  // This copy constructor violates the const-ness of the parameter since
45  // this attr takes ownership of the other attr StaticBuffer
46  DirEntryAttr(const DirEntryAttr &other) : name(other.name), has_attr(other.has_attr), is_dir(other.is_dir), sub_entries(other.sub_entries) {
47  attr = (const_cast<DirEntryAttr&>(other)).attr;
48  }
49 
50  // This assignment operator violates the const-ness of the parameter since
51  // this attr takes ownership of the other attr StaticBuffer
53  name = other.name;
54  has_attr = other.has_attr;
55  is_dir = other.is_dir;
56  sub_entries = other.sub_entries;
57  attr.free();
58  attr = (const_cast<DirEntryAttr&>(other)).attr;
59  return *this;
60  }
61 
62  std::string name;
65  bool has_attr;
66  bool is_dir;
67 
68  std::vector<DirEntryAttr> sub_entries;
69  };
70 
71  struct LtDirEntryAttr {
72  bool operator()(const class DirEntryAttr &x, const class DirEntryAttr &y) const {
73  if (x.name == y.name)
74  return (int)x.is_dir < (int)y.is_dir;
75  return x.name < y.name;
76  }
77  };
78 
85  size_t encoded_length_dir_entry_attr(const DirEntryAttr &entry);
86 
93  void encode_dir_entry_attr(uint8_t **buf_ptr, const DirEntryAttr &entry);
94 
103  DirEntryAttr &decode_dir_entry_attr(const uint8_t **buf_ptr, size_t *remaining_ptr,
104  DirEntryAttr &entry);
105 
106 }
107 
108 #endif // Hyperspace_DirEntryAttr_h
A memory buffer of static size.
Definition: StaticBuffer.h:45
bool is_dir
Definition: DirEntryAttr.h:66
StaticBuffer attr
Definition: DirEntryAttr.h:63
bool operator()(const class DirEntryAttr &x, const class DirEntryAttr &y) const
Definition: DirEntryAttr.h:72
Hyperspace definitions
Definition: DirEntryAttr.h:40
std::string name
Definition: DirEntryAttr.h:62
DirEntryAttr & operator=(const DirEntryAttr &other)
Definition: DirEntryAttr.h:52
bool has_attr
Boolean value indicating whether or not this entry is a directory.
Definition: DirEntryAttr.h:65
void encode_dir_entry_attr(uint8_t **bufp, const DirEntryAttr &entry)
Encodes (serializes) the given directory entry to a buffer.
Definition: DirEntryAttr.cc:42
Compatibility Macros for C/C++.
DirEntryAttr()
Definition: DirEntryAttr.h:43
A memory buffer of static size.
DirEntryAttr(const DirEntryAttr &other)
Definition: DirEntryAttr.h:46
void free()
Clears the data; if this object is owner of the data then the allocated buffer is delete[]d...
Definition: StaticBuffer.h:185
Hypertable definitions
DirEntryAttr & decode_dir_entry_attr(const uint8_t **bufp, size_t *remainp, DirEntryAttr &entry)
Decodes (unserializes) a directory entry from a buffer.
Definition: DirEntryAttr.cc:53
std::vector< DirEntryAttr > sub_entries
Definition: DirEntryAttr.h:68
size_t encoded_length_dir_entry_attr(const DirEntryAttr &entry)
Returns the number of bytes required to encode (serialize) the given directory entry.
Definition: DirEntryAttr.cc:35
Definition: DirEntryAttr.h:71