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 
52  DirectoryTemplate(IDataSourceStream* source, Directory* dir) : SectionTemplate(source), directory(dir)
53  {
54  }
55 
57  {
58  delete directory;
59  }
60 
62  {
63  return *directory;
64  }
65 
66  bool nextRecord() override
67  {
68  if(sectionIndex() == 1) {
69  return directory->next();
70  }
71 
72  return recordIndex() < 0;
73  }
74 
75 protected:
76  String getValue(const char* name) override;
77 
78 private:
79  Directory* directory;
80 };
81 
82 } // namespace IFS
DirectoryTemplate(IDataSourceStream *source, Directory *dir)
Definition: DirectoryTemplate.h:52
int recordIndex() const
Definition: SectionTemplate.h:137
Field
Definition: DirectoryTemplate.h:45
Base class for read-only stream.
Definition: DataSourceStream.h:40
Directory stream class.
Definition: DirectoryTemplate.h:42
~DirectoryTemplate()
Definition: DirectoryTemplate.h:56
bool nextRecord() override
Move to next record.
Definition: DirectoryTemplate.h:66
Directory & dir()
Definition: DirectoryTemplate.h:61
The String class.
Definition: WString.h:136
Wrapper class for enumerating a directory.
Definition: Directory.h:31
Definition: DirectoryTemplate.h:36
String getValue(const char *name) override
Fetch a templated value.
Provides enhanced template tag processing for use with a SectionStream.
Definition: SectionTemplate.h:71
#define DIRSTREAM_FIELD_MAP(XX)
Definition: DirectoryTemplate.h:19
int sectionIndex() const
Definition: SectionTemplate.h:127