sbFileSystemNode.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef sbFileSystemNode_h_
28 #define sbFileSystemNode_h_
29 
30 #include <nsAutoPtr.h>
31 #include <nsCOMPtr.h>
32 #include <nsStringAPI.h>
33 #include <nsTArray.h>
34 #include <nsISerializable.h>
35 #include <nsIClassInfo.h>
36 #include <map>
37 
39 typedef nsTArray<nsRefPtr<sbFileSystemNode> > sbNodeArray;
40 typedef std::map<nsString, nsRefPtr<sbFileSystemNode> > sbNodeMap;
41 typedef sbNodeMap::value_type sbNodeMapPair;
42 typedef sbNodeMap::const_iterator sbNodeMapIter;
43 
44 
45 //------------------------------------------------------------------------------
46 // A class to model a file-system resource node (w/ children)
47 //------------------------------------------------------------------------------
49  public nsIClassInfo
50 {
51 public:
53  virtual ~sbFileSystemNode();
54 
56  NS_DECL_NSISERIALIZABLE
57  NS_DECL_NSICLASSINFO
58 
59  //
60  // \brief Initialize a node with a given leaf name, directory flag, last
61  // modification time, and a parent node.
62  // \param aLeafName The leaf name to assign to the node, this can not be
63  // a empty string.
64  // \param aIsDir If this node is a directory.
65  // \param aLastModify The last modification time stamp for the node.
66  // \param aParentNode The parent node to assign to this node.
67  //
68  nsresult Init(const nsAString & aLeafName,
69  PRBool aIsDir,
70  PRUint64 aLastModify);
71 
72  //
73  // \brief Setters and getters for the child array of this node.
74  //
75  nsresult SetChildren(const sbNodeMap & aNodeMap);
77 
78  //
79  // \brief Setters and getters for the leaf name of this node.
80  //
81  nsresult SetLeafName(const nsAString & aLeafName);
82  nsresult GetLeafName(nsAString & aLeafName);
83 
84  //
85  // \brief Setters and getters for the directory flag of this node.
86  //
87  nsresult SetIsDir(const PRBool aIsDir);
88  nsresult GetIsDir(PRBool *aIsDir);
89 
90  //
91  // \brief Setters and getters of the last modification time stamp of
92  // this node.
93  //
94  nsresult SetLastModify(const PRInt64 aLastModify);
95  nsresult GetLastModify(PRInt64 *aLastModify);
96 
97  //
98  // \brief Add or remove a child node from this node.
99  //
100  nsresult AddChild(sbFileSystemNode *aNode);
101  nsresult RemoveChild(sbFileSystemNode *aNode);
102 
103  //
104  // \brief Get the number of children this node has.
105  // \param aChildCount The out-param of the number of children.
106  //
107  nsresult GetChildCount(PRUint32 *aChildCount);
108 
109  //
110  // \brief Replace a child node of the given leaf name with a new node.
111  // \pram aLeafName The leaf name of the node to replace
112  // \param aReplacementNode The new node pointer to replace the child with.
113  //
114  nsresult ReplaceNode(const nsAString & aLeafName,
115  sbFileSystemNode *aReplacementNode);
116 
117  //
118  // \brief Setter and getters of the node ID.
119  // This is only used for serialization and the value is never
120  // generated.
121  //
122  nsresult SetNodeID(PRUint32 aID);
123  nsresult GetNodeID(PRUint32 *aID);
124 
125  //
126  // \brief Getter and setters for the ID of the parent node.
127  // This is only used for serialization and the value is never
128  // generated.
129  //
130  nsresult SetParentID(const PRUint32 aID);
131  nsresult GetParentID(PRUint32 *aOutID);
132 
133 private:
134  sbNodeMap mChildMap;
135  nsString mLeafName;
136  PRUint32 mID;
137  PRUint32 mParentID;
138  PRBool mIsDir;
139  PRInt64 mLastModify;
140 };
141 
142 #endif
143 
nsresult SetNodeID(PRUint32 aID)
virtual ~sbFileSystemNode()
sbNodeMap * GetChildren()
nsresult AddChild(sbFileSystemNode *aNode)
sbNodeMap::value_type sbNodeMapPair
nsresult GetLeafName(nsAString &aLeafName)
nsresult RemoveChild(sbFileSystemNode *aNode)
nsresult SetLeafName(const nsAString &aLeafName)
std::map< nsString, nsRefPtr< sbFileSystemNode > > sbNodeMap
nsresult GetParentID(PRUint32 *aOutID)
sbNodeMap::const_iterator sbNodeMapIter
nsresult GetIsDir(PRBool *aIsDir)
nsISerializable
nsTArray< nsRefPtr< sbFileSystemNode > > sbNodeArray
nsresult SetIsDir(const PRBool aIsDir)
nsresult GetChildCount(PRUint32 *aChildCount)
nsresult GetNodeID(PRUint32 *aID)
nsresult ReplaceNode(const nsAString &aLeafName, sbFileSystemNode *aReplacementNode)
nsresult SetLastModify(const PRInt64 aLastModify)
nsresult SetParentID(const PRUint32 aID)
nsresult GetLastModify(PRInt64 *aLastModify)
nsresult SetChildren(const sbNodeMap &aNodeMap)
NS_DECL_ISUPPORTS NS_DECL_NSISERIALIZABLE NS_DECL_NSICLASSINFO nsresult Init(const nsAString &aLeafName, PRBool aIsDir, PRUint64 aLastModify)