xref: /haiku/src/kits/tracker/AttributeStream.h (revision 9437e677ba3d5f813929944ae2b09fc37feb8d2d)
102be5353SAxel Dörfler /*
202be5353SAxel Dörfler Open Tracker License
302be5353SAxel Dörfler 
402be5353SAxel Dörfler Terms and Conditions
502be5353SAxel Dörfler 
602be5353SAxel Dörfler Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler 
802be5353SAxel Dörfler Permission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörfler this software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörfler the Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfler use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörfler of the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörfler so, subject to the following conditions:
1402be5353SAxel Dörfler 
1502be5353SAxel Dörfler The above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörfler and shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler 
1802be5353SAxel Dörfler THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1902be5353SAxel Dörfler IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2002be5353SAxel Dörfler FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2102be5353SAxel Dörfler BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2202be5353SAxel Dörfler AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2302be5353SAxel Dörfler WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2402be5353SAxel Dörfler 
2502be5353SAxel Dörfler Except as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörfler used in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörfler this Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler 
2902be5353SAxel Dörfler Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörfler of Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörfler names are registered trademarks or trademarks of their respective holders.
3202be5353SAxel Dörfler All rights reserved.
3302be5353SAxel Dörfler */
3402be5353SAxel Dörfler 
3502be5353SAxel Dörfler //	attribute streams allow copying/filtering/transformation of attributes
3602be5353SAxel Dörfler //	between file and/or memory nodes
3702be5353SAxel Dörfler //
3802be5353SAxel Dörfler //	for example one can use constructs of nodes like:
3902be5353SAxel Dörfler //
4002be5353SAxel Dörfler // 	destinationNode << transformer << buffer << filter << sourceNode
4102be5353SAxel Dörfler //
42ea001e58SJohn Scipione //	transformer may for instance perform endian-swapping or offsetting of
43ea001e58SJohn Scipione //	a B_RECT attribute filter may withold certain attributes buffer is a
44ea001e58SJohn Scipione //	memory allocated snapshot of attributes, may be repeatedly streamed into
4502be5353SAxel Dörfler //	other files, buffers
4602be5353SAxel Dörfler //
47ea001e58SJohn Scipione //	In addition to the whacky (but usefull) << syntax, calls like Read, Write
48ea001e58SJohn Scipione //	are also available
4902be5353SAxel Dörfler #ifndef __ATTRIBUTE_STREAM__
5002be5353SAxel Dörfler #define __ATTRIBUTE_STREAM__
5102be5353SAxel Dörfler 
52b05aa8b5SJohn Scipione 
5302be5353SAxel Dörfler #include <Node.h>
5402be5353SAxel Dörfler #include <Rect.h>
5502be5353SAxel Dörfler #include <String.h>
5602be5353SAxel Dörfler #include <TypeConstants.h>
5702be5353SAxel Dörfler 
5802be5353SAxel Dörfler #include <fs_attr.h>
5902be5353SAxel Dörfler 
6002be5353SAxel Dörfler #include "ObjectList.h"
6102be5353SAxel Dörfler 
62b05aa8b5SJohn Scipione 
6302be5353SAxel Dörfler namespace BPrivate {
6402be5353SAxel Dörfler 
6502be5353SAxel Dörfler struct AttributeTemplate {
6602be5353SAxel Dörfler 	// used for read-only attribute source
6702be5353SAxel Dörfler 	const char* fAttributeName;
6802be5353SAxel Dörfler 	uint32 fAttributeType;
6902be5353SAxel Dörfler 	off_t fSize;
7002be5353SAxel Dörfler 	const char* fBits;
7102be5353SAxel Dörfler };
7202be5353SAxel Dörfler 
7302be5353SAxel Dörfler 
7402be5353SAxel Dörfler class AttributeInfo {
7502be5353SAxel Dörfler 	// utility class for internal attribute description
7602be5353SAxel Dörfler public:
7702be5353SAxel Dörfler 	AttributeInfo()
7802be5353SAxel Dörfler 		{}
7902be5353SAxel Dörfler 	AttributeInfo(const AttributeInfo &);
8002be5353SAxel Dörfler 	AttributeInfo(const char*, attr_info);
8102be5353SAxel Dörfler 	AttributeInfo(const char*, uint32, off_t);
8202be5353SAxel Dörfler 
8302be5353SAxel Dörfler 	void SetTo(const AttributeInfo &);
8402be5353SAxel Dörfler 	void SetTo(const char*, attr_info);
8502be5353SAxel Dörfler 	void SetTo(const char*, uint32, off_t);
8602be5353SAxel Dörfler 	const char* Name() const;
8702be5353SAxel Dörfler 	uint32 Type() const;
8802be5353SAxel Dörfler 	off_t Size() const;
8902be5353SAxel Dörfler 
9002be5353SAxel Dörfler private:
9102be5353SAxel Dörfler 	BString fName;
9202be5353SAxel Dörfler 	attr_info fInfo;
9302be5353SAxel Dörfler };
9402be5353SAxel Dörfler 
95b05aa8b5SJohn Scipione 
9602be5353SAxel Dörfler class AttributeStreamNode {
9702be5353SAxel Dörfler public:
9802be5353SAxel Dörfler 	AttributeStreamNode();
9902be5353SAxel Dörfler 	virtual ~AttributeStreamNode();
10002be5353SAxel Dörfler 
10102be5353SAxel Dörfler 	AttributeStreamNode &operator<<(AttributeStreamNode &source);
10202be5353SAxel Dörfler 		// workhorse call
10302be5353SAxel Dörfler 		// to the outside makes this node a part of the stream, passing on
10402be5353SAxel Dörfler 		// any data it has, gets, transforms, doesn't filter out
10502be5353SAxel Dörfler 		//
10602be5353SAxel Dörfler 		// under the hood sets up streaming into the next node; hooking
107ea001e58SJohn Scipione 		// up source and destination, forces the stream head to start
108ea001e58SJohn Scipione 		// streaming
10902be5353SAxel Dörfler 
11002be5353SAxel Dörfler 	virtual void Rewind();
11102be5353SAxel Dörfler 		// get ready to start all over again
11202be5353SAxel Dörfler 	virtual void MakeEmpty() {}
11302be5353SAxel Dörfler 		// remove any attributes the node may have
11402be5353SAxel Dörfler 
11502be5353SAxel Dörfler 	virtual off_t Contains(const char*, uint32);
11602be5353SAxel Dörfler 		// returns size of attribute if found
11702be5353SAxel Dörfler 
118a51764c5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
119a51764c5SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
12002be5353SAxel Dörfler 		// read from this node
121a51764c5SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
122a51764c5SJohn Scipione 		uint32 type, off_t size, const void* buffer);
12302be5353SAxel Dörfler 		// write to this node
12402be5353SAxel Dörfler 
12502be5353SAxel Dörfler 	// work calls
12602be5353SAxel Dörfler 	virtual bool Drive();
12702be5353SAxel Dörfler 		// node at the head of the stream makes the entire stream
12802be5353SAxel Dörfler 		// feed it
12902be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
13002be5353SAxel Dörfler 		// give me the next attribute in the stream
13102be5353SAxel Dörfler 	virtual const char* Get();
132ea001e58SJohn Scipione 		// give me the data of the attribute in the stream that was just
133ea001e58SJohn Scipione 		// returned by Next assumes there is a buffering node somewhere on the
134ea001e58SJohn Scipione 		// way to the source, from which the resulting buffer is borrowed
13502be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
136ea001e58SJohn Scipione 		// fill the buffer with data of the attribute in the stream that was
137ea001e58SJohn Scipione 		// just returned by next <buffer> is big enough to hold the entire
138ea001e58SJohn Scipione 		// attribute data
13902be5353SAxel Dörfler 
14002be5353SAxel Dörfler 	virtual bool CanFeed() const { return false; }
14102be5353SAxel Dörfler 		// return true if can work as a source for the entire stream
14202be5353SAxel Dörfler 
14302be5353SAxel Dörfler private:
14402be5353SAxel Dörfler 	bool Start();
14502be5353SAxel Dörfler 		// utility call, used to start up the stream by finding the ultimate
14602be5353SAxel Dörfler 		// target of the stream and calling Drive on it
14702be5353SAxel Dörfler 
14802be5353SAxel Dörfler 	void Detach();
14902be5353SAxel Dörfler 
15002be5353SAxel Dörfler protected:
15102be5353SAxel Dörfler 	AttributeStreamNode* fReadFrom;
15202be5353SAxel Dörfler 	AttributeStreamNode* fWriteTo;
15302be5353SAxel Dörfler };
15402be5353SAxel Dörfler 
155b05aa8b5SJohn Scipione 
15602be5353SAxel Dörfler class AttributeStreamFileNode : public AttributeStreamNode {
15702be5353SAxel Dörfler 	// handles reading and writing attributes to and from the
15802be5353SAxel Dörfler 	// stream
15902be5353SAxel Dörfler public:
16002be5353SAxel Dörfler 	AttributeStreamFileNode();
16102be5353SAxel Dörfler 	AttributeStreamFileNode(BNode*);
16202be5353SAxel Dörfler 
16302be5353SAxel Dörfler 	virtual void MakeEmpty();
16402be5353SAxel Dörfler 	virtual void Rewind();
16502be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
166b05aa8b5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName, uint32 type,
167b05aa8b5SJohn Scipione 		off_t size, void* buffer, void (*swapFunc)(void*) = 0);
168b05aa8b5SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName, uint32 type,
169b05aa8b5SJohn Scipione 		off_t size, const void* buffer);
17002be5353SAxel Dörfler 
17102be5353SAxel Dörfler 	void SetTo(BNode*);
17202be5353SAxel Dörfler 
17302be5353SAxel Dörfler 	BNode* Node()
17402be5353SAxel Dörfler 		{ return fNode; }
17502be5353SAxel Dörfler 
17602be5353SAxel Dörfler protected:
17702be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
17802be5353SAxel Dörfler 
17902be5353SAxel Dörfler 	virtual bool Drive();
18002be5353SAxel Dörfler 		// give me all the attributes, I'll write them into myself
18102be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
18202be5353SAxel Dörfler 		// return the info for the next attribute I can read for you
18302be5353SAxel Dörfler 	virtual const char* Get();
18402be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
18502be5353SAxel Dörfler 
18602be5353SAxel Dörfler private:
18702be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
18802be5353SAxel Dörfler 	BNode* fNode;
18902be5353SAxel Dörfler 
19002be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
19102be5353SAxel Dörfler };
19202be5353SAxel Dörfler 
193b05aa8b5SJohn Scipione 
19402be5353SAxel Dörfler class AttributeStreamMemoryNode : public AttributeStreamNode {
19502be5353SAxel Dörfler 	// in memory attribute buffer; can be both target of writing and source
19602be5353SAxel Dörfler 	// of reading at the same time
19702be5353SAxel Dörfler public:
19802be5353SAxel Dörfler 	AttributeStreamMemoryNode();
19902be5353SAxel Dörfler 
20002be5353SAxel Dörfler 	virtual void MakeEmpty();
20102be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
202ea001e58SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
203ea001e58SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
204ea001e58SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
205ea001e58SJohn Scipione 		uint32 type, off_t size, const void* buffer);
20602be5353SAxel Dörfler 
20702be5353SAxel Dörfler protected:
20802be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
20902be5353SAxel Dörfler 	virtual void Rewind();
21002be5353SAxel Dörfler 	virtual bool Drive();
21102be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
21202be5353SAxel Dörfler 	virtual const char* Get();
21302be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
21402be5353SAxel Dörfler 
21502be5353SAxel Dörfler 	class AttrNode {
21602be5353SAxel Dörfler 	public:
21702be5353SAxel Dörfler 		AttrNode(const char* name, uint32 type, off_t size, char* data)
218*9437e677SJohn Scipione 		:
219*9437e677SJohn Scipione 		fAttr(name, type, size),
22002be5353SAxel Dörfler 		fData(data)
22102be5353SAxel Dörfler 		{
22202be5353SAxel Dörfler 		}
22302be5353SAxel Dörfler 
22402be5353SAxel Dörfler 		~AttrNode()
22502be5353SAxel Dörfler 		{
22602be5353SAxel Dörfler 			delete[] fData;
22702be5353SAxel Dörfler 		}
22802be5353SAxel Dörfler 
22902be5353SAxel Dörfler 		AttributeInfo fAttr;
23002be5353SAxel Dörfler 		char* fData;
23102be5353SAxel Dörfler 	};
23202be5353SAxel Dörfler 
23302be5353SAxel Dörfler 		// utility calls
23402be5353SAxel Dörfler 	virtual AttrNode* BufferingGet();
23502be5353SAxel Dörfler 	virtual AttrNode* BufferingGet(const char* name, uint32 type, off_t size);
23602be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
23702be5353SAxel Dörfler 
23802be5353SAxel Dörfler private:
23902be5353SAxel Dörfler 	BObjectList<AttrNode> fAttributes;
24002be5353SAxel Dörfler 	int32 fCurrentIndex;
24102be5353SAxel Dörfler 
24202be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
24302be5353SAxel Dörfler };
24402be5353SAxel Dörfler 
245b05aa8b5SJohn Scipione 
24602be5353SAxel Dörfler class AttributeStreamTemplateNode : public AttributeStreamNode {
24702be5353SAxel Dörfler 	// in read-only memory attribute source
24802be5353SAxel Dörfler 	// can only be used as a source for Next and Get
24902be5353SAxel Dörfler public:
25002be5353SAxel Dörfler 	AttributeStreamTemplateNode(const AttributeTemplate*, int32 count);
25102be5353SAxel Dörfler 
25202be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
25302be5353SAxel Dörfler 
25402be5353SAxel Dörfler protected:
25502be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
25602be5353SAxel Dörfler 	virtual void Rewind();
25702be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
25802be5353SAxel Dörfler 	virtual const char* Get();
25902be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
26002be5353SAxel Dörfler 
26102be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
26202be5353SAxel Dörfler 
26302be5353SAxel Dörfler private:
26402be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
26502be5353SAxel Dörfler 	const AttributeTemplate* fAttributes;
26602be5353SAxel Dörfler 	int32 fCurrentIndex;
26702be5353SAxel Dörfler 	int32 fCount;
26802be5353SAxel Dörfler 
26902be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
27002be5353SAxel Dörfler };
27102be5353SAxel Dörfler 
272b05aa8b5SJohn Scipione 
27302be5353SAxel Dörfler class AttributeStreamFilterNode : public AttributeStreamNode {
27402be5353SAxel Dörfler 	// filter node may not pass thru specified attributes
27502be5353SAxel Dörfler public:
27602be5353SAxel Dörfler 	AttributeStreamFilterNode()
27702be5353SAxel Dörfler 		{}
27802be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
279ea001e58SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
280ea001e58SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
281ea001e58SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
282ea001e58SJohn Scipione 		uint32 type, off_t size, const void* buffer);
28302be5353SAxel Dörfler 
28402be5353SAxel Dörfler protected:
28502be5353SAxel Dörfler 	virtual bool Reject(const char* name, uint32 type, off_t size);
28602be5353SAxel Dörfler 		// override to implement filtering
28702be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
28802be5353SAxel Dörfler 
28902be5353SAxel Dörfler private:
29002be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
29102be5353SAxel Dörfler };
29202be5353SAxel Dörfler 
293b05aa8b5SJohn Scipione 
29402be5353SAxel Dörfler class NamesToAcceptAttrFilter : public AttributeStreamFilterNode {
29502be5353SAxel Dörfler 	// filter node that only passes thru attributes that match
29602be5353SAxel Dörfler 	// a list of names
29702be5353SAxel Dörfler public:
29802be5353SAxel Dörfler 	NamesToAcceptAttrFilter(const char**);
29902be5353SAxel Dörfler 
30002be5353SAxel Dörfler protected:
30102be5353SAxel Dörfler 	virtual bool Reject(const char* name, uint32 type, off_t size);
30202be5353SAxel Dörfler 
30302be5353SAxel Dörfler private:
30402be5353SAxel Dörfler 	const char** fNameList;
30502be5353SAxel Dörfler };
30602be5353SAxel Dörfler 
307b05aa8b5SJohn Scipione 
30802be5353SAxel Dörfler class SelectiveAttributeTransformer : public AttributeStreamNode {
30902be5353SAxel Dörfler 	// node applies a transformation on specified attributes
31002be5353SAxel Dörfler public:
311a51764c5SJohn Scipione 	SelectiveAttributeTransformer(const char* attributeName,
312a51764c5SJohn Scipione 		bool (*)(const char*, uint32 , off_t , void*, void*), void* params);
31302be5353SAxel Dörfler 	virtual ~SelectiveAttributeTransformer();
31402be5353SAxel Dörfler 
315a51764c5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName, uint32 type,
316a51764c5SJohn Scipione 		off_t size, void* buffer, void (*swapFunc)(void*) = 0);
31702be5353SAxel Dörfler 
31802be5353SAxel Dörfler 	virtual void Rewind();
31902be5353SAxel Dörfler 
32002be5353SAxel Dörfler protected:
321a51764c5SJohn Scipione 	virtual bool WillTransform(const char* name, uint32 type, off_t size,
322a51764c5SJohn Scipione 		const char* data) const;
323ea001e58SJohn Scipione 		// override to implement filtering, should only return true if
324ea001e58SJohn Scipione 		// transformation will occur
325a51764c5SJohn Scipione 	virtual char* CopyAndApplyTransformer(const char* name, uint32 type,
326a51764c5SJohn Scipione 		off_t size, const char* data);
32702be5353SAxel Dörfler 		// makes a copy of data
328a51764c5SJohn Scipione 	virtual bool ApplyTransformer(const char* name, uint32 type, off_t size,
329a51764c5SJohn Scipione 		char* data);
33002be5353SAxel Dörfler 		// transforms in place
33102be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
33202be5353SAxel Dörfler 	virtual const char* Get();
33302be5353SAxel Dörfler 
33402be5353SAxel Dörfler private:
33502be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
33602be5353SAxel Dörfler 	const char* fAttributeNameToTransform;
33702be5353SAxel Dörfler 	bool (*fTransformFunc)(const char*, uint32 , off_t , void*, void*);
33802be5353SAxel Dörfler 	void* fTransformParams;
33902be5353SAxel Dörfler 
34002be5353SAxel Dörfler 	BObjectList<char> fTransformedBuffers;
34102be5353SAxel Dörfler 
34202be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
34302be5353SAxel Dörfler };
34402be5353SAxel Dörfler 
345b05aa8b5SJohn Scipione 
34602be5353SAxel Dörfler template <class Type>
34702be5353SAxel Dörfler class AttributeStreamConstValue : public AttributeStreamNode {
34802be5353SAxel Dörfler public:
349a51764c5SJohn Scipione 	AttributeStreamConstValue(const char* name, uint32 attributeType,
350a51764c5SJohn Scipione 		Type value);
35102be5353SAxel Dörfler 
352b05aa8b5SJohn Scipione protected:
35302be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
35402be5353SAxel Dörfler 	virtual void Rewind() { fRewound = true; }
35502be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
35602be5353SAxel Dörfler 	virtual const char* Get();
35702be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
35802be5353SAxel Dörfler 
35902be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
36002be5353SAxel Dörfler 
36102be5353SAxel Dörfler private:
36202be5353SAxel Dörfler 	AttributeInfo fAttr;
36302be5353SAxel Dörfler 	Type fValue;
36402be5353SAxel Dörfler 	bool fRewound;
36502be5353SAxel Dörfler 
36602be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
36702be5353SAxel Dörfler };
36802be5353SAxel Dörfler 
369b05aa8b5SJohn Scipione 
37002be5353SAxel Dörfler template<class Type>
37102be5353SAxel Dörfler AttributeStreamConstValue<Type>::AttributeStreamConstValue(const char* name,
37202be5353SAxel Dörfler 	uint32 attributeType, Type value)
37302be5353SAxel Dörfler 	:	fAttr(name, attributeType, sizeof(Type)),
37402be5353SAxel Dörfler 		fValue(value),
37502be5353SAxel Dörfler 		fRewound(true)
37602be5353SAxel Dörfler {
37702be5353SAxel Dörfler }
37802be5353SAxel Dörfler 
379b05aa8b5SJohn Scipione 
38002be5353SAxel Dörfler template<class Type>
38102be5353SAxel Dörfler const AttributeInfo*
38202be5353SAxel Dörfler AttributeStreamConstValue<Type>::Next()
38302be5353SAxel Dörfler {
38402be5353SAxel Dörfler 	if (!fRewound)
38502be5353SAxel Dörfler 		return NULL;
38602be5353SAxel Dörfler 
38702be5353SAxel Dörfler 	fRewound = false;
38802be5353SAxel Dörfler 	return &fAttr;
38902be5353SAxel Dörfler }
39002be5353SAxel Dörfler 
391b05aa8b5SJohn Scipione 
39202be5353SAxel Dörfler template<class Type>
39302be5353SAxel Dörfler const char*
39402be5353SAxel Dörfler AttributeStreamConstValue<Type>::Get()
39502be5353SAxel Dörfler {
39602be5353SAxel Dörfler 	return (const char*)&fValue;
39702be5353SAxel Dörfler }
39802be5353SAxel Dörfler 
399b05aa8b5SJohn Scipione 
40002be5353SAxel Dörfler template<class Type>
40102be5353SAxel Dörfler bool
40202be5353SAxel Dörfler AttributeStreamConstValue<Type>::Fill(char* buffer) const
40302be5353SAxel Dörfler {
40402be5353SAxel Dörfler 	memcpy(buffer, &fValue, sizeof(Type));
40502be5353SAxel Dörfler 	return true;
40602be5353SAxel Dörfler }
40702be5353SAxel Dörfler 
408b05aa8b5SJohn Scipione 
40902be5353SAxel Dörfler template<class Type>
41002be5353SAxel Dörfler int32
41102be5353SAxel Dörfler AttributeStreamConstValue<Type>::Find(const char* name, uint32 type) const
41202be5353SAxel Dörfler {
413fc7c01a1SRene Gollent 	if (strcmp(fAttr.Name(), name) == 0 && type == fAttr.Type())
41402be5353SAxel Dörfler 		return 0;
41502be5353SAxel Dörfler 
41602be5353SAxel Dörfler 	return -1;
41702be5353SAxel Dörfler }
41802be5353SAxel Dörfler 
419b05aa8b5SJohn Scipione 
42002be5353SAxel Dörfler class AttributeStreamBoolValue : public AttributeStreamConstValue<bool> {
42102be5353SAxel Dörfler public:
42202be5353SAxel Dörfler 	AttributeStreamBoolValue(const char* name, bool value)
42302be5353SAxel Dörfler 		:	AttributeStreamConstValue<bool>(name, B_BOOL_TYPE, value)
42402be5353SAxel Dörfler 		{}
42502be5353SAxel Dörfler };
42602be5353SAxel Dörfler 
427b05aa8b5SJohn Scipione 
42802be5353SAxel Dörfler class AttributeStreamInt32Value : public AttributeStreamConstValue<int32> {
42902be5353SAxel Dörfler public:
43002be5353SAxel Dörfler 	AttributeStreamInt32Value(const char* name, int32 value)
43102be5353SAxel Dörfler 		:	AttributeStreamConstValue<int32>(name, B_INT32_TYPE, value)
43202be5353SAxel Dörfler 		{}
43302be5353SAxel Dörfler };
43402be5353SAxel Dörfler 
435b05aa8b5SJohn Scipione 
43602be5353SAxel Dörfler class AttributeStreamInt64Value : public AttributeStreamConstValue<int64> {
43702be5353SAxel Dörfler public:
43802be5353SAxel Dörfler 	AttributeStreamInt64Value(const char* name, int64 value)
43902be5353SAxel Dörfler 		:	AttributeStreamConstValue<int64>(name, B_INT64_TYPE, value)
44002be5353SAxel Dörfler 		{}
44102be5353SAxel Dörfler };
44202be5353SAxel Dörfler 
443b05aa8b5SJohn Scipione 
44402be5353SAxel Dörfler class AttributeStreamRectValue : public AttributeStreamConstValue<BRect> {
44502be5353SAxel Dörfler public:
44602be5353SAxel Dörfler 	AttributeStreamRectValue(const char* name, BRect value)
44702be5353SAxel Dörfler 		:	AttributeStreamConstValue<BRect>(name, B_RECT_TYPE, value)
44802be5353SAxel Dörfler 		{}
44902be5353SAxel Dörfler };
45002be5353SAxel Dörfler 
451b05aa8b5SJohn Scipione 
45202be5353SAxel Dörfler class AttributeStreamFloatValue : public AttributeStreamConstValue<float> {
45302be5353SAxel Dörfler public:
45402be5353SAxel Dörfler 	AttributeStreamFloatValue(const char* name, float value)
45502be5353SAxel Dörfler 		:	AttributeStreamConstValue<float>(name, B_FLOAT_TYPE, value)
45602be5353SAxel Dörfler 		{}
45702be5353SAxel Dörfler };
45802be5353SAxel Dörfler 
459b05aa8b5SJohn Scipione } // namespace BPrivate
46002be5353SAxel Dörfler 
46102be5353SAxel Dörfler using namespace BPrivate;
46202be5353SAxel Dörfler 
46302be5353SAxel Dörfler #endif
464