aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plpdirent.h
blob: d10c76ac4dbd5bf4f2c0dc2110f3444f2cb76a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef _PLP_DIRENT_H_
#define _PLP_DIRENT_H_

#include <string>
#include <psitime.h>
#include <rfsv.h>

class PlpUID
{
	friend inline bool operator<(const PlpUID &u1, const PlpUID &u2);
public:
	PlpUID();
	PlpUID(const long u1, const long u2, const long u3);

	long operator[](int idx);

private:
	long uid[3];
};

inline bool operator<(const PlpUID &u1, const PlpUID &u2) {
	return (memcmp(u1.uid, u2.uid, sizeof(u1.uid)) < 0);
}

/**
 * A class, representing a directory entry of the Psion.
 * Objects of this type are used by @ref rfsv::readdir and
 * @ref rfsv::dir for returning the entries of a directory.
 */
class PlpDirent {
	friend class rfsv32;
	friend class rfsv16;

public:
	/**
	 * Default constructor
	 */
	PlpDirent() : size(0), attr(0), name(""), time(0L), attrstr("") { };

	/**
	 * A copy constructor.
	 * Mainly used by STL container classes.
	 *
	 * @param d The object to be used as initializer.
	 */
	PlpDirent(const PlpDirent &d);

	/**
	 * Default destructor.
	 */
	~PlpDirent() {};

	/**
	 * Retrieves the file size of a directory entry.
	 *
	 * @returns The file size in bytes.
	 */
	long getSize();

	/**
	 * Retrieves the file attributes of a directory entry.
	 *
	 * @returns The generic attributes ( @ref rfsv:file_attribs ).
	 */
	long getAttr();

	/**
	 * Retrieves the UIDs of a directory entry.
	 * This method returns always 0 with a Series3.
	 *
	 * @param uididx The index of the UID to retrieve (0 .. 2).
	 *
	 * @returns The selected UID or 0 if the index is out of range.
	 */
	long getUID(int uididx);

	/**
	 * Retrieves the @ref PlpUID object of a directory entry.
	 *
	 * @returns The PlpUID object.
	 */
	PlpUID &getUID();

	/**
	 * Retrieve the file name of a directory entry.
	 *
	 * @returns The name of the file.
	 */
	const char *getName();

	/**
	 * Retrieve the modification time of a directory entry.
	 *
	 * @returns A @ref PsiTime object, representing the time.
	 */
	PsiTime getPsiTime();

	/**
	 * Set the file name of a directory entry.
	 * This is currently used in plpbackup only for
	 * changing the name to the full path. It does NOT
	 * change the name of the corresponding file on
	 * the Psion.
	 *
	 * @param str The new name of the file.
	 */
	void setName(const char *str);

	/**
	 * Assignment operator
	 * Mainly used by STL container classes.
	 *
	 * @param e The new value to assign.
	 *
	 * @returns The modified object.
	 */
	PlpDirent &operator=(const PlpDirent &e);

	/**
	 * Prints the object contents.
	 * The output is in human readable similar to the
	 * output of a "ls" command.
	 */
	friend ostream &operator<<(ostream &o, const PlpDirent &e);

private:
	long    size;
	long    attr;
	PlpUID  UID;
	PsiTime time;
	string  attrstr;
	string  name;
};
#endif