xref: /haiku/src/apps/cortex/RouteApp/NodeSetIOContext.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 // NodeSetIOContext.h
2 // * PURPOSE
3 //   Store state info for import & export of a set
4 //   of media node descriptions.  Provide hooks for
5 //   import/export of associated UI state info.
6 //   To be used as a mix-in w/ derived ImportContext
7 //   and ExportContext classes.
8 //
9 // * HISTORY
10 //   e.moon			7dec99		Begun
11 
12 #ifndef __NodeSetIOContext_H__
13 #define __NodeSetIOContext_H__
14 
15 #include "NodeKey.h"
16 
17 #include <MediaDefs.h>
18 #include <vector>
19 #include <utility>
20 
21 #include "cortex_defs.h"
22 __BEGIN_CORTEX_NAMESPACE
23 
24 
25 class NodeSetIOContext {
26 public:														// *** dtor/ctor
27 	virtual ~NodeSetIOContext();
28 	NodeSetIOContext();
29 
30 public:														// *** hooks
31 	virtual void importUIState(
32 		const BMessage*							archive) {}
33 
34 	virtual void exportUIState(
35 		BMessage*										archive) {}
36 
37 public:														// *** operations
38 	// The node must be valid (!= media_node::null.node).
39 	// If no key is given, a new one will be generated.
40 	status_t addNode(
41 		media_node_id									node,
42 		const char*										key=0);
43 
44 	status_t removeNode(
45 		media_node_id									node);
46 
47 	status_t removeNodeAt(
48 		uint32												index);
49 
50 	uint32 countNodes() const;
51 
52 	// returns 0 if out of range
53 	media_node_id nodeAt(
54 		uint32												index) const;
55 
56 	const char* keyAt(
57 		uint32												index) const;
58 
59 	status_t getKeyFor(
60 		media_node_id									node,
61 		const char**									outKey) const;
62 
63 	status_t getNodeFor(
64 		const char*										key,
65 		media_node_id*								outNode) const;
66 
67 private:													// implementation
68 
69 	// the node/key set
70 	typedef pair<BString,media_node_id> node_entry;
71 	typedef vector<node_entry>			node_set;
72 	node_set												m_nodes;
73 
74 	// next node key value
75 	int16														m_nodeKeyIndex;
76 };
77 
78 __END_CORTEX_NAMESPACE
79 #endif /*__NodeSetIOContext_H__*/