Attribute.h
Go to the documentation of this file.
1 /****
2  * Attribute.h
3  *
4  * Created: April 2021
5  *
6  * Copyright 2021 mikee47 <mike@sillyhouse.net>
7  *
8  * This file is part of the IFS Library
9  *
10  * This library is free software: you can redistribute it and/or modify it under the terms of the
11  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with this library.
18  * If not, see <https://www.gnu.org/licenses/>.
19  *
20  ****/
21 
22 #pragma once
23 
24 #include <WString.h>
25 #include "TimeStamp.h"
26 #include "FileAttributes.h"
27 #include "Access.h"
28 #include "Compression.h"
29 
30 namespace IFS
31 {
32 #define IFS_ATTRIBUTE_TAG_MAP(XX) \
33  XX(ModifiedTime, sizeof(TimeStamp)) \
34  XX(FileAttributes, sizeof(FileAttributes)) \
35  XX(ReadAce, sizeof(UserRole)) \
36  XX(WriteAce, sizeof(UserRole)) \
37  XX(Compression, sizeof(Compression)) \
38  XX(Md5Hash, 16) \
39  XX(VolumeIndex, sizeof(uint8_t)) \
40  XX(Comment, 0)
41 
45 enum class AttributeTag : uint16_t {
46 #define XX(tag, size) tag,
48 #undef XX
49  User = 16,
50 };
51 
55 struct AttributeEnum {
56  AttributeTag tag{};
57  size_t size{0};
58  size_t attrsize{0};
59  void* buffer;
60  size_t bufsize;
61 
63  {
64  }
65 
66  void set(AttributeTag tag, const void* value, size_t valueSize)
67  {
68  this->tag = tag;
69  attrsize = valueSize;
70  size = std::min(attrsize, bufsize);
71  memcpy(buffer, value, size);
72  }
73 
74  template <typename T> void set(AttributeTag tag, const T& value)
75  {
76  set(tag, &value, sizeof(value));
77  }
78 };
79 
84 
86 {
87  unsigned tagValue = value + unsigned(AttributeTag::User);
88  return AttributeTag(tagValue);
89 }
90 
91 size_t getAttributeSize(AttributeTag tag);
92 
93 } // namespace IFS
94 
96 bool fromString(const char* name, IFS::AttributeTag& tag);
Attribute information passed to enumeration callback.
Definition: Attribute.h:74
size_t bufsize
User-provided buffer size.
Definition: Attribute.h:79
The String class.
Definition: WString.h:136
size_t getAttributeSize(AttributeTag tag)
void set(AttributeTag tag, const void *value, size_t valueSize)
Definition: Attribute.h:85
size_t attrsize
Actual attribute size.
Definition: Attribute.h:77
AttributeTag getUserAttributeTag(uint8_t value)
Definition: Attribute.h:104
Definition: DirectoryTemplate.h:36
#define IFS_ATTRIBUTE_TAG_MAP(XX)
Definition: Attribute.h:51
AttributeEnum(void *buffer, size_t bufsize)
Definition: Attribute.h:81
void * buffer
User-provided buffer with tag value.
Definition: Attribute.h:78
size_t size
Size of returned data, may be less than attrsize if buffer too small.
Definition: Attribute.h:76
String toString(IFS::AttributeTag tag)
AttributeTag tag
The attribute tag.
Definition: Attribute.h:75
AttributeTag
Identifies a specific attribute.
Definition: Attribute.h:64
bool fromString(const char *name, IFS::AttributeTag &tag)
Definition: Delegate.h:20
@ User
First user attribute.