xref: /haiku/src/apps/cortex/RouteApp/NodeKey.h (revision 19ae20e67e91fc09cc9fc5c0e60e21e24e7a53eb)
1 /*
2  * Copyright (c) 1999-2000, Eric Moon.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions, and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 // NodeKey.h
33 // * PURPOSE +++++ SUPERCEDED BY LiveNodeIO 20dec99 +++++
34 //
35 //   An IPersistent implementation that stores a string
36 //   identifier (key) for a media node whose description
37 //   is being imported from or exported to a stream.
38 //
39 //   A NodeKey may refer to a user-created node or one
40 //   of the following system-defined nodes:
41 //
42 //   AUDIO_INPUT
43 //   AUDIO_OUTPUT
44 //   AUDIO_MIXER
45 //   VIDEO_INPUT
46 //   VIDEO_OUTPUT
47 //   DAC_TIME_SOURCE
48 //   SYSTEM_TIME_SOURCE
49 //
50 // * HISTORY
51 //   e.moon			7dec99		Begun
52 
53 #ifndef __NodeKey_H__
54 #define __NodeKey_H__
55 
56 #include <MediaDefs.h>
57 #include "StringContent.h"
58 
59 #include "cortex_defs.h"
60 
61 __BEGIN_CORTEX_NAMESPACE
62 
63 class NodeKey :
64 	public	StringContent {
65 
66 public:														// content access
67 
key()68 	const char* key() const { return content.String(); }
69 
70 	// if the corresponding node doesn't exist, returns 0
node()71 	media_node_id node() const { return m_node; }
72 
73 public:														// *** dtor, default ctors
~NodeKey()74 	virtual ~NodeKey() {}
NodeKey()75 	NodeKey() : m_node(0) {}
NodeKey(const NodeKey & clone)76 	NodeKey(
77 		const NodeKey&								clone) { _clone(clone); }
78 	NodeKey& operator=(
79 		const NodeKey&								clone) { _clone(clone); return *this; }
80 
81 	bool operator<(
82 		const NodeKey&								other) const {
83 		return key() < other.key();
84 	}
85 
86 public:														// *** IPersistent
87 
88 	// EXPORT
89 
90 	virtual void xmlExportBegin(
91 		ExportContext&								context) const;
92 
93 	virtual void xmlExportAttributes(
94 		ExportContext&								context) const;
95 
96 	virtual void xmlExportContent(
97 		ExportContext&								context) const;
98 
99 	virtual void xmlExportEnd(
100 		ExportContext&								context) const;
101 
102 
103 private:
104 	friend class RouteAppNodeManager;
105 
NodeKey(const char * _key,media_node_id _node)106 	NodeKey(
107 		const char*										_key,
108 		media_node_id									_node) :
109 		StringContent(_key),
110 		m_node(_node) {}
111 
112 private:
_clone(const NodeKey & clone)113 	inline void _clone(
114 		const NodeKey&								clone) {
115 		content = clone.content;
116 		m_node = clone.m_node;
117 	}
118 
119 	media_node_id										m_node;
120 
121 	static const char* const				s_element;
122 };
123 
124 __END_CORTEX_NAMESPACE
125 #endif /*__NodeKey_H__ */
126