DirectoryTemplate.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * DirectoryTemplate.h
8  *
9  * @author mikee47 <mike@sillyhouse.net> May 2019
10  *
11  *
12  ****/
13 
14 #pragma once
15 
16 #include "../SectionTemplate.h"
17 #include <IFS/Directory.h>
18 
19 #define DIRSTREAM_FIELD_MAP(XX) \
20  XX(file_id, "File identifier") \
21  XX(name, "Filename") \
22  XX(modified, "Date/time of file modification") \
23  XX(size, "File size in bytes") \
24  XX(original_size, "Original size of compressed file") \
25  XX(attr, "File attributes (brief)") \
26  XX(attr_long, "File attributes") \
27  XX(compression, "Compression type") \
28  XX(access, "File access information (brief)") \
29  XX(access_long, "File access information") \
30  XX(index, "Zero-based index of current file") \
31  XX(total_size, "Total size of files processed (in bytes)") \
32  XX(path, "Path to containing directory") \
33  XX(parent, "Path to parent directory (if any)") \
34  XX(last_error, "Last error message")
35 
36 namespace IFS
37 {
43 {
44 public:
45  enum class Field {
46  unknown = 0,
47 #define XX(name, comment) name,
49 #undef XX
50  };
51 
53  {
54  directory.reset(dir);
55  }
56 
58  {
59  return *directory;
60  }
61 
62  bool nextRecord() override
63  {
64  if(sectionIndex() == 1) {
65  return directory->next();
66  }
67 
68  return recordIndex() < 0;
69  }
70 
71 protected:
72  String getValue(const char* name) override;
73 
74 private:
75  std::unique_ptr<Directory> directory;
76 };
77 
78 } // namespace IFS
Base class for read-only stream.
Definition: DataSourceStream.h:45
Directory stream class.
Definition: DirectoryTemplate.h:42
#define DIRSTREAM_FIELD_MAP(XX)
Definition: DirectoryTemplate.h:19
The String class.
Definition: WString.h:136
Directory & dir()
Definition: DirectoryTemplate.h:57
int sectionIndex() const
Get the index for the current section.
Definition: SectionTemplate.h:156
Definition: DirectoryTemplate.h:36
Field
Definition: DirectoryTemplate.h:45
int recordIndex() const
Get current record index.
Definition: SectionTemplate.h:174
bool nextRecord() override
Move to next record.
Definition: DirectoryTemplate.h:62
Wrapper class for enumerating a directory.
Definition: Directory.h:50
DirectoryTemplate(IDataSourceStream *source, Directory *dir)
Definition: DirectoryTemplate.h:52
Provides enhanced template tag processing for use with a SectionStream.
Definition: SectionTemplate.h:73
String getValue(const char *name) override
Fetch a templated value.