xref: /haiku/src/kits/tracker/AttributeStream.h (revision 54e2dd7272db551cab02cc678bd45bc4131dd867)
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
497ec2c512SJohn Scipione #ifndef _ATTRIBUTE_STREAM_H
507ec2c512SJohn Scipione #define _ATTRIBUTE_STREAM_H
5102be5353SAxel Dörfler 
52b05aa8b5SJohn Scipione 
537ec2c512SJohn Scipione #include <ObjectList.h>
5402be5353SAxel Dörfler #include <Node.h>
5502be5353SAxel Dörfler #include <Rect.h>
5602be5353SAxel Dörfler #include <String.h>
5702be5353SAxel Dörfler #include <TypeConstants.h>
5802be5353SAxel Dörfler 
5902be5353SAxel Dörfler #include <fs_attr.h>
6002be5353SAxel Dörfler 
61b05aa8b5SJohn Scipione 
6202be5353SAxel Dörfler namespace BPrivate {
6302be5353SAxel Dörfler 
6402be5353SAxel Dörfler struct AttributeTemplate {
6502be5353SAxel Dörfler 	// used for read-only attribute source
6602be5353SAxel Dörfler 	const char* fAttributeName;
6702be5353SAxel Dörfler 	uint32 fAttributeType;
6802be5353SAxel Dörfler 	off_t fSize;
6902be5353SAxel Dörfler 	const char* fBits;
7002be5353SAxel Dörfler };
7102be5353SAxel Dörfler 
7202be5353SAxel Dörfler 
7302be5353SAxel Dörfler class AttributeInfo {
7402be5353SAxel Dörfler 	// utility class for internal attribute description
7502be5353SAxel Dörfler public:
7649d5d59cSJohn Scipione 	AttributeInfo();
77d069f646SJohn Scipione 	AttributeInfo(const AttributeInfo& other);
78d069f646SJohn Scipione 	AttributeInfo(const char* name, attr_info info);
79d069f646SJohn Scipione 	AttributeInfo(const char* name, uint32 type, off_t size);
8002be5353SAxel Dörfler 
81d069f646SJohn Scipione 	void SetTo(const AttributeInfo& other);
82d069f646SJohn Scipione 	void SetTo(const char* name, attr_info info);
83d069f646SJohn Scipione 	void SetTo(const char* name, uint32 type, off_t size);
8402be5353SAxel Dörfler 	const char* Name() const;
8502be5353SAxel Dörfler 	uint32 Type() const;
8602be5353SAxel Dörfler 	off_t Size() const;
8702be5353SAxel Dörfler 
8802be5353SAxel Dörfler private:
8902be5353SAxel Dörfler 	BString fName;
9002be5353SAxel Dörfler 	attr_info fInfo;
9102be5353SAxel Dörfler };
9202be5353SAxel Dörfler 
93b05aa8b5SJohn Scipione 
9402be5353SAxel Dörfler class AttributeStreamNode {
9502be5353SAxel Dörfler public:
9602be5353SAxel Dörfler 	AttributeStreamNode();
9702be5353SAxel Dörfler 	virtual ~AttributeStreamNode();
9802be5353SAxel Dörfler 
9902be5353SAxel Dörfler 	AttributeStreamNode &operator<<(AttributeStreamNode &source);
10002be5353SAxel Dörfler 		// workhorse call
10102be5353SAxel Dörfler 		// to the outside makes this node a part of the stream, passing on
10202be5353SAxel Dörfler 		// any data it has, gets, transforms, doesn't filter out
10302be5353SAxel Dörfler 		//
10402be5353SAxel Dörfler 		// under the hood sets up streaming into the next node; hooking
105ea001e58SJohn Scipione 		// up source and destination, forces the stream head to start
106ea001e58SJohn Scipione 		// streaming
10702be5353SAxel Dörfler 
10802be5353SAxel Dörfler 	virtual void Rewind();
10902be5353SAxel Dörfler 		// get ready to start all over again
MakeEmpty()11002be5353SAxel Dörfler 	virtual void MakeEmpty() {}
11102be5353SAxel Dörfler 		// remove any attributes the node may have
11202be5353SAxel Dörfler 
11302be5353SAxel Dörfler 	virtual off_t Contains(const char*, uint32);
11402be5353SAxel Dörfler 		// returns size of attribute if found
11502be5353SAxel Dörfler 
116a51764c5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
117a51764c5SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
11802be5353SAxel Dörfler 		// read from this node
119a51764c5SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
120a51764c5SJohn Scipione 		uint32 type, off_t size, const void* buffer);
12102be5353SAxel Dörfler 		// write to this node
12202be5353SAxel Dörfler 
12302be5353SAxel Dörfler 	// work calls
12402be5353SAxel Dörfler 	virtual bool Drive();
12502be5353SAxel Dörfler 		// node at the head of the stream makes the entire stream
12602be5353SAxel Dörfler 		// feed it
12702be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
12802be5353SAxel Dörfler 		// give me the next attribute in the stream
12902be5353SAxel Dörfler 	virtual const char* Get();
130ea001e58SJohn Scipione 		// give me the data of the attribute in the stream that was just
131ea001e58SJohn Scipione 		// returned by Next assumes there is a buffering node somewhere on the
132ea001e58SJohn Scipione 		// way to the source, from which the resulting buffer is borrowed
13302be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
134ea001e58SJohn Scipione 		// fill the buffer with data of the attribute in the stream that was
135ea001e58SJohn Scipione 		// just returned by next <buffer> is big enough to hold the entire
136ea001e58SJohn Scipione 		// attribute data
13702be5353SAxel Dörfler 
CanFeed()13802be5353SAxel Dörfler 	virtual bool CanFeed() const { return false; }
13902be5353SAxel Dörfler 		// return true if can work as a source for the entire stream
14002be5353SAxel Dörfler 
14102be5353SAxel Dörfler private:
14202be5353SAxel Dörfler 	bool Start();
14302be5353SAxel Dörfler 		// utility call, used to start up the stream by finding the ultimate
14402be5353SAxel Dörfler 		// target of the stream and calling Drive on it
14502be5353SAxel Dörfler 
14602be5353SAxel Dörfler 	void Detach();
14702be5353SAxel Dörfler 
14802be5353SAxel Dörfler protected:
14902be5353SAxel Dörfler 	AttributeStreamNode* fReadFrom;
15002be5353SAxel Dörfler 	AttributeStreamNode* fWriteTo;
15102be5353SAxel Dörfler };
15202be5353SAxel Dörfler 
153b05aa8b5SJohn Scipione 
15402be5353SAxel Dörfler class AttributeStreamFileNode : public AttributeStreamNode {
15502be5353SAxel Dörfler 	// handles reading and writing attributes to and from the
15602be5353SAxel Dörfler 	// stream
15702be5353SAxel Dörfler public:
15802be5353SAxel Dörfler 	AttributeStreamFileNode();
15902be5353SAxel Dörfler 	AttributeStreamFileNode(BNode*);
16002be5353SAxel Dörfler 
16102be5353SAxel Dörfler 	virtual void MakeEmpty();
16202be5353SAxel Dörfler 	virtual void Rewind();
16302be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
164b05aa8b5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName, uint32 type,
165b05aa8b5SJohn Scipione 		off_t size, void* buffer, void (*swapFunc)(void*) = 0);
166b05aa8b5SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName, uint32 type,
167b05aa8b5SJohn Scipione 		off_t size, const void* buffer);
16802be5353SAxel Dörfler 
16902be5353SAxel Dörfler 	void SetTo(BNode*);
17002be5353SAxel Dörfler 
Node()171*54e2dd72SJohn Scipione 	BNode* Node() { return fNode; }
17202be5353SAxel Dörfler 
17302be5353SAxel Dörfler protected:
CanFeed()17402be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
17502be5353SAxel Dörfler 
17602be5353SAxel Dörfler 	virtual bool Drive();
17702be5353SAxel Dörfler 		// give me all the attributes, I'll write them into myself
17802be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
17902be5353SAxel Dörfler 		// return the info for the next attribute I can read for you
18002be5353SAxel Dörfler 	virtual const char* Get();
18102be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
18202be5353SAxel Dörfler 
18302be5353SAxel Dörfler private:
18402be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
18502be5353SAxel Dörfler 	BNode* fNode;
18602be5353SAxel Dörfler 
18702be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
18802be5353SAxel Dörfler };
18902be5353SAxel Dörfler 
190b05aa8b5SJohn Scipione 
19102be5353SAxel Dörfler class AttributeStreamMemoryNode : public AttributeStreamNode {
19202be5353SAxel Dörfler 	// in memory attribute buffer; can be both target of writing and source
19302be5353SAxel Dörfler 	// of reading at the same time
19402be5353SAxel Dörfler public:
19502be5353SAxel Dörfler 	AttributeStreamMemoryNode();
19602be5353SAxel Dörfler 
19702be5353SAxel Dörfler 	virtual void MakeEmpty();
19802be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
199ea001e58SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
200ea001e58SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
201ea001e58SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
202ea001e58SJohn Scipione 		uint32 type, off_t size, const void* buffer);
20302be5353SAxel Dörfler 
20402be5353SAxel Dörfler protected:
CanFeed()20502be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
20602be5353SAxel Dörfler 	virtual void Rewind();
20702be5353SAxel Dörfler 	virtual bool Drive();
20802be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
20902be5353SAxel Dörfler 	virtual const char* Get();
21002be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
21102be5353SAxel Dörfler 
21202be5353SAxel Dörfler 	class AttrNode {
21302be5353SAxel Dörfler 	public:
AttrNode(const char * name,uint32 type,off_t size,char * data)21402be5353SAxel Dörfler 		AttrNode(const char* name, uint32 type, off_t size, char* data)
2159437e677SJohn Scipione 		:
2169437e677SJohn Scipione 		fAttr(name, type, size),
21702be5353SAxel Dörfler 		fData(data)
21802be5353SAxel Dörfler 		{
21902be5353SAxel Dörfler 		}
22002be5353SAxel Dörfler 
~AttrNode()22102be5353SAxel Dörfler 		~AttrNode()
22202be5353SAxel Dörfler 		{
22302be5353SAxel Dörfler 			delete[] fData;
22402be5353SAxel Dörfler 		}
22502be5353SAxel Dörfler 
22602be5353SAxel Dörfler 		AttributeInfo fAttr;
22702be5353SAxel Dörfler 		char* fData;
22802be5353SAxel Dörfler 	};
22902be5353SAxel Dörfler 
23002be5353SAxel Dörfler 		// utility calls
23102be5353SAxel Dörfler 	virtual AttrNode* BufferingGet();
23202be5353SAxel Dörfler 	virtual AttrNode* BufferingGet(const char* name, uint32 type, off_t size);
23302be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
23402be5353SAxel Dörfler 
23502be5353SAxel Dörfler private:
23602be5353SAxel Dörfler 	BObjectList<AttrNode> fAttributes;
23702be5353SAxel Dörfler 	int32 fCurrentIndex;
23802be5353SAxel Dörfler 
23902be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
24002be5353SAxel Dörfler };
24102be5353SAxel Dörfler 
242b05aa8b5SJohn Scipione 
24302be5353SAxel Dörfler class AttributeStreamTemplateNode : public AttributeStreamNode {
24402be5353SAxel Dörfler 	// in read-only memory attribute source
24502be5353SAxel Dörfler 	// can only be used as a source for Next and Get
24602be5353SAxel Dörfler public:
24702be5353SAxel Dörfler 	AttributeStreamTemplateNode(const AttributeTemplate*, int32 count);
24802be5353SAxel Dörfler 
24902be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
25002be5353SAxel Dörfler 
25102be5353SAxel Dörfler protected:
CanFeed()25202be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
25302be5353SAxel Dörfler 	virtual void Rewind();
25402be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
25502be5353SAxel Dörfler 	virtual const char* Get();
25602be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
25702be5353SAxel Dörfler 
25802be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
25902be5353SAxel Dörfler 
26002be5353SAxel Dörfler private:
26102be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
26202be5353SAxel Dörfler 	const AttributeTemplate* fAttributes;
26302be5353SAxel Dörfler 	int32 fCurrentIndex;
26402be5353SAxel Dörfler 	int32 fCount;
26502be5353SAxel Dörfler 
26602be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
26702be5353SAxel Dörfler };
26802be5353SAxel Dörfler 
269b05aa8b5SJohn Scipione 
27002be5353SAxel Dörfler class AttributeStreamFilterNode : public AttributeStreamNode {
27102be5353SAxel Dörfler 	// filter node may not pass thru specified attributes
27202be5353SAxel Dörfler public:
AttributeStreamFilterNode()27302be5353SAxel Dörfler 	AttributeStreamFilterNode()
27402be5353SAxel Dörfler 		{}
27502be5353SAxel Dörfler 	virtual off_t Contains(const char* name, uint32 type);
276ea001e58SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName,
277ea001e58SJohn Scipione 		uint32 type, off_t size, void* buffer, void (*swapFunc)(void*) = 0);
278ea001e58SJohn Scipione 	virtual off_t Write(const char* name, const char* foreignName,
279ea001e58SJohn Scipione 		uint32 type, off_t size, const void* buffer);
28002be5353SAxel Dörfler 
28102be5353SAxel Dörfler protected:
28202be5353SAxel Dörfler 	virtual bool Reject(const char* name, uint32 type, off_t size);
28302be5353SAxel Dörfler 		// override to implement filtering
28402be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
28502be5353SAxel Dörfler 
28602be5353SAxel Dörfler private:
28702be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
28802be5353SAxel Dörfler };
28902be5353SAxel Dörfler 
290b05aa8b5SJohn Scipione 
29102be5353SAxel Dörfler class NamesToAcceptAttrFilter : public AttributeStreamFilterNode {
29202be5353SAxel Dörfler 	// filter node that only passes thru attributes that match
29302be5353SAxel Dörfler 	// a list of names
29402be5353SAxel Dörfler public:
29502be5353SAxel Dörfler 	NamesToAcceptAttrFilter(const char**);
29602be5353SAxel Dörfler 
29702be5353SAxel Dörfler protected:
29802be5353SAxel Dörfler 	virtual bool Reject(const char* name, uint32 type, off_t size);
29902be5353SAxel Dörfler 
30002be5353SAxel Dörfler private:
30102be5353SAxel Dörfler 	const char** fNameList;
30202be5353SAxel Dörfler };
30302be5353SAxel Dörfler 
304b05aa8b5SJohn Scipione 
30502be5353SAxel Dörfler class SelectiveAttributeTransformer : public AttributeStreamNode {
30602be5353SAxel Dörfler 	// node applies a transformation on specified attributes
30702be5353SAxel Dörfler public:
308a51764c5SJohn Scipione 	SelectiveAttributeTransformer(const char* attributeName,
309a51764c5SJohn Scipione 		bool (*)(const char*, uint32 , off_t , void*, void*), void* params);
31002be5353SAxel Dörfler 	virtual ~SelectiveAttributeTransformer();
31102be5353SAxel Dörfler 
312a51764c5SJohn Scipione 	virtual off_t Read(const char* name, const char* foreignName, uint32 type,
313a51764c5SJohn Scipione 		off_t size, void* buffer, void (*swapFunc)(void*) = 0);
31402be5353SAxel Dörfler 
31502be5353SAxel Dörfler 	virtual void Rewind();
31602be5353SAxel Dörfler 
31702be5353SAxel Dörfler protected:
318a51764c5SJohn Scipione 	virtual bool WillTransform(const char* name, uint32 type, off_t size,
319a51764c5SJohn Scipione 		const char* data) const;
320ea001e58SJohn Scipione 		// override to implement filtering, should only return true if
321ea001e58SJohn Scipione 		// transformation will occur
322a51764c5SJohn Scipione 	virtual char* CopyAndApplyTransformer(const char* name, uint32 type,
323a51764c5SJohn Scipione 		off_t size, const char* data);
32402be5353SAxel Dörfler 		// makes a copy of data
325a51764c5SJohn Scipione 	virtual bool ApplyTransformer(const char* name, uint32 type, off_t size,
326a51764c5SJohn Scipione 		char* data);
32702be5353SAxel Dörfler 		// transforms in place
32802be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
32902be5353SAxel Dörfler 	virtual const char* Get();
33002be5353SAxel Dörfler 
33102be5353SAxel Dörfler private:
33202be5353SAxel Dörfler 	AttributeInfo fCurrentAttr;
33302be5353SAxel Dörfler 	const char* fAttributeNameToTransform;
33402be5353SAxel Dörfler 	bool (*fTransformFunc)(const char*, uint32 , off_t , void*, void*);
33502be5353SAxel Dörfler 	void* fTransformParams;
33602be5353SAxel Dörfler 
33702be5353SAxel Dörfler 	BObjectList<char> fTransformedBuffers;
33802be5353SAxel Dörfler 
33902be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
34002be5353SAxel Dörfler };
34102be5353SAxel Dörfler 
342b05aa8b5SJohn Scipione 
34302be5353SAxel Dörfler template <class Type>
34402be5353SAxel Dörfler class AttributeStreamConstValue : public AttributeStreamNode {
34502be5353SAxel Dörfler public:
346a51764c5SJohn Scipione 	AttributeStreamConstValue(const char* name, uint32 attributeType,
347a51764c5SJohn Scipione 		Type value);
34802be5353SAxel Dörfler 
349b05aa8b5SJohn Scipione protected:
CanFeed()35002be5353SAxel Dörfler 	virtual bool CanFeed() const { return true; }
Rewind()35102be5353SAxel Dörfler 	virtual void Rewind() { fRewound = true; }
35202be5353SAxel Dörfler 	virtual const AttributeInfo* Next();
35302be5353SAxel Dörfler 	virtual const char* Get();
35402be5353SAxel Dörfler 	virtual bool Fill(char* buffer) const;
35502be5353SAxel Dörfler 
35602be5353SAxel Dörfler 	int32 Find(const char* name, uint32 type) const;
35702be5353SAxel Dörfler 
35802be5353SAxel Dörfler private:
35902be5353SAxel Dörfler 	AttributeInfo fAttr;
36002be5353SAxel Dörfler 	Type fValue;
36102be5353SAxel Dörfler 	bool fRewound;
36202be5353SAxel Dörfler 
36302be5353SAxel Dörfler 	typedef AttributeStreamNode _inherited;
36402be5353SAxel Dörfler };
36502be5353SAxel Dörfler 
366b05aa8b5SJohn Scipione 
36702be5353SAxel Dörfler template<class Type>
AttributeStreamConstValue(const char * name,uint32 attributeType,Type value)36802be5353SAxel Dörfler AttributeStreamConstValue<Type>::AttributeStreamConstValue(const char* name,
36902be5353SAxel Dörfler 	uint32 attributeType, Type value)
3707ec2c512SJohn Scipione 	:
3717ec2c512SJohn Scipione 	fAttr(name, attributeType, sizeof(Type)),
37202be5353SAxel Dörfler 	fValue(value),
37302be5353SAxel Dörfler 	fRewound(true)
37402be5353SAxel Dörfler {
37502be5353SAxel Dörfler }
37602be5353SAxel Dörfler 
377b05aa8b5SJohn Scipione 
37802be5353SAxel Dörfler template<class Type>
37902be5353SAxel Dörfler const AttributeInfo*
Next()38002be5353SAxel Dörfler AttributeStreamConstValue<Type>::Next()
38102be5353SAxel Dörfler {
38202be5353SAxel Dörfler 	if (!fRewound)
38302be5353SAxel Dörfler 		return NULL;
38402be5353SAxel Dörfler 
38502be5353SAxel Dörfler 	fRewound = false;
38602be5353SAxel Dörfler 	return &fAttr;
38702be5353SAxel Dörfler }
38802be5353SAxel Dörfler 
389b05aa8b5SJohn Scipione 
39002be5353SAxel Dörfler template<class Type>
39102be5353SAxel Dörfler const char*
Get()39202be5353SAxel Dörfler AttributeStreamConstValue<Type>::Get()
39302be5353SAxel Dörfler {
39402be5353SAxel Dörfler 	return (const char*)&fValue;
39502be5353SAxel Dörfler }
39602be5353SAxel Dörfler 
397b05aa8b5SJohn Scipione 
39802be5353SAxel Dörfler template<class Type>
39902be5353SAxel Dörfler bool
Fill(char * buffer)40002be5353SAxel Dörfler AttributeStreamConstValue<Type>::Fill(char* buffer) const
40102be5353SAxel Dörfler {
40202be5353SAxel Dörfler 	memcpy(buffer, &fValue, sizeof(Type));
40302be5353SAxel Dörfler 	return true;
40402be5353SAxel Dörfler }
40502be5353SAxel Dörfler 
406b05aa8b5SJohn Scipione 
40702be5353SAxel Dörfler template<class Type>
40802be5353SAxel Dörfler int32
Find(const char * name,uint32 type)40902be5353SAxel Dörfler AttributeStreamConstValue<Type>::Find(const char* name, uint32 type) const
41002be5353SAxel Dörfler {
411fc7c01a1SRene Gollent 	if (strcmp(fAttr.Name(), name) == 0 && type == fAttr.Type())
41202be5353SAxel Dörfler 		return 0;
41302be5353SAxel Dörfler 
41402be5353SAxel Dörfler 	return -1;
41502be5353SAxel Dörfler }
41602be5353SAxel Dörfler 
417b05aa8b5SJohn Scipione 
41802be5353SAxel Dörfler class AttributeStreamBoolValue : public AttributeStreamConstValue<bool> {
41902be5353SAxel Dörfler public:
AttributeStreamBoolValue(const char * name,bool value)42002be5353SAxel Dörfler 	AttributeStreamBoolValue(const char* name, bool value)
4217ec2c512SJohn Scipione 		:
4227ec2c512SJohn Scipione 		AttributeStreamConstValue<bool>(name, B_BOOL_TYPE, value)
4237ec2c512SJohn Scipione 	{
4247ec2c512SJohn Scipione 	}
42502be5353SAxel Dörfler };
42602be5353SAxel Dörfler 
427b05aa8b5SJohn Scipione 
42802be5353SAxel Dörfler class AttributeStreamInt32Value : public AttributeStreamConstValue<int32> {
42902be5353SAxel Dörfler public:
AttributeStreamInt32Value(const char * name,int32 value)43002be5353SAxel Dörfler 	AttributeStreamInt32Value(const char* name, int32 value)
4317ec2c512SJohn Scipione 		:
4327ec2c512SJohn Scipione 		AttributeStreamConstValue<int32>(name, B_INT32_TYPE, value)
4337ec2c512SJohn Scipione 	{
4347ec2c512SJohn Scipione 	}
43502be5353SAxel Dörfler };
43602be5353SAxel Dörfler 
437b05aa8b5SJohn Scipione 
43802be5353SAxel Dörfler class AttributeStreamInt64Value : public AttributeStreamConstValue<int64> {
43902be5353SAxel Dörfler public:
AttributeStreamInt64Value(const char * name,int64 value)44002be5353SAxel Dörfler 	AttributeStreamInt64Value(const char* name, int64 value)
4417ec2c512SJohn Scipione 		:
4427ec2c512SJohn Scipione 		AttributeStreamConstValue<int64>(name, B_INT64_TYPE, value)
4437ec2c512SJohn Scipione 	{
4447ec2c512SJohn Scipione 	}
44502be5353SAxel Dörfler };
44602be5353SAxel Dörfler 
447b05aa8b5SJohn Scipione 
44802be5353SAxel Dörfler class AttributeStreamRectValue : public AttributeStreamConstValue<BRect> {
44902be5353SAxel Dörfler public:
AttributeStreamRectValue(const char * name,BRect value)45002be5353SAxel Dörfler 	AttributeStreamRectValue(const char* name, BRect value)
4517ec2c512SJohn Scipione 		:
4527ec2c512SJohn Scipione 		AttributeStreamConstValue<BRect>(name, B_RECT_TYPE, value)
4537ec2c512SJohn Scipione 	{
4547ec2c512SJohn Scipione 	}
45502be5353SAxel Dörfler };
45602be5353SAxel Dörfler 
457b05aa8b5SJohn Scipione 
45802be5353SAxel Dörfler class AttributeStreamFloatValue : public AttributeStreamConstValue<float> {
45902be5353SAxel Dörfler public:
AttributeStreamFloatValue(const char * name,float value)46002be5353SAxel Dörfler 	AttributeStreamFloatValue(const char* name, float value)
4617ec2c512SJohn Scipione 		:
4627ec2c512SJohn Scipione 		AttributeStreamConstValue<float>(name, B_FLOAT_TYPE, value)
4637ec2c512SJohn Scipione 	{
4647ec2c512SJohn Scipione 	}
46502be5353SAxel Dörfler };
46602be5353SAxel Dörfler 
467b05aa8b5SJohn Scipione } // namespace BPrivate
46802be5353SAxel Dörfler 
46902be5353SAxel Dörfler using namespace BPrivate;
47002be5353SAxel Dörfler 
4717ec2c512SJohn Scipione 
4727ec2c512SJohn Scipione #endif	// _ATTRIBUTE_STREAM_H
473