1be2b0592SFredrik Modeen/*
21ecf19b8SJohn Scipione * Copyright 1999-2009 Haiku, Inc. All rights reserved.
3be2b0592SFredrik Modeen * Distributed under the terms of the MIT License.
4be2b0592SFredrik Modeen *
5be2b0592SFredrik Modeen * Authors:
6be2b0592SFredrik Modeen *		Jeremy Friesner
7be2b0592SFredrik Modeen */
81ecf19b8SJohn Scipione#ifndef _BIT_FIELD_TESTERS_H
91ecf19b8SJohn Scipione#define _BIT_FIELD_TESTERS_H
10be2b0592SFredrik Modeen
11be2b0592SFredrik Modeen
12be2b0592SFredrik Modeen#include <Archivable.h>
13be2b0592SFredrik Modeen#include <List.h>
14be2b0592SFredrik Modeen#include <Message.h>
15be2b0592SFredrik Modeen
16be2b0592SFredrik Modeen
171ecf19b8SJohn Scipione// This file contains various BitTester classes, each of which defines a
18be2b0592SFredrik Modeen// sequence of bit testing logics to do on a uint32.
19be2b0592SFredrik Modeen
20be2b0592SFredrik Modeen// The abstract base class. Defines the interface.
21be2b0592SFredrik Modeen_EXPORT class BitFieldTester;
22be2b0592SFredrik Modeenclass BitFieldTester : public BArchivable {
23be2b0592SFredrik Modeenpublic:
241ecf19b8SJohn Scipione								BitFieldTester();
251ecf19b8SJohn Scipione								BitFieldTester(BMessage* from);
26be2b0592SFredrik Modeen
271ecf19b8SJohn Scipione	virtual bool				IsMatching(uint32 field) = 0;
281ecf19b8SJohn Scipione	virtual status_t			Archive(BMessage* into,
291ecf19b8SJohn Scipione									bool deep = true) const;
30be2b0592SFredrik Modeen};
31be2b0592SFredrik Modeen
32be2b0592SFredrik Modeen
33be2b0592SFredrik Modeen// This version always returns the value specified in the constructor.
34be2b0592SFredrik Modeen_EXPORT class ConstantFieldTester;
35be2b0592SFredrik Modeenclass ConstantFieldTester : public BitFieldTester {
36be2b0592SFredrik Modeenpublic:
371ecf19b8SJohn Scipione								ConstantFieldTester(bool result);
381ecf19b8SJohn Scipione								ConstantFieldTester(BMessage* from);
39be2b0592SFredrik Modeen
401ecf19b8SJohn Scipione	virtual	status_t			Archive(BMessage* into,
411ecf19b8SJohn Scipione									bool deep = true) const;
421ecf19b8SJohn Scipione	static	BArchivable*		Instantiate(BMessage* from);
431ecf19b8SJohn Scipione	virtual	bool				IsMatching(uint32 field);
44be2b0592SFredrik Modeen
45be2b0592SFredrik Modeenprivate:
461ecf19b8SJohn Scipione			bool				fResult;
47be2b0592SFredrik Modeen};
48be2b0592SFredrik Modeen
49be2b0592SFredrik Modeen
50be2b0592SFredrik Modeen// This version matches if all requiredBits are found in the field,
51be2b0592SFredrik Modeen// and no forbiddenBits are found.
52be2b0592SFredrik Modeen_EXPORT class HasBitsFieldTester;
53be2b0592SFredrik Modeenclass HasBitsFieldTester : public BitFieldTester {
54be2b0592SFredrik Modeenpublic:
551ecf19b8SJohn Scipione								HasBitsFieldTester(uint32 requiredBits,
561ecf19b8SJohn Scipione									uint32 forbiddenBits = 0);
571ecf19b8SJohn Scipione								HasBitsFieldTester(BMessage* from);
58be2b0592SFredrik Modeen
591ecf19b8SJohn Scipione	virtual	status_t			Archive(BMessage* into,
601ecf19b8SJohn Scipione									bool deep = true) const;
611ecf19b8SJohn Scipione	static	BArchivable*		Instantiate(BMessage* from);
621ecf19b8SJohn Scipione	virtual	bool				IsMatching(uint32 field);
63be2b0592SFredrik Modeen
64be2b0592SFredrik Modeenprivate:
651ecf19b8SJohn Scipione			uint32				fRequiredBits;
661ecf19b8SJohn Scipione			uint32				fForbiddenBits;
67be2b0592SFredrik Modeen};
68be2b0592SFredrik Modeen
69be2b0592SFredrik Modeen
70be2b0592SFredrik Modeen// This one negates the tester it holds.
71be2b0592SFredrik Modeen_EXPORT class NotFieldTester;
72be2b0592SFredrik Modeenclass NotFieldTester : public BitFieldTester {
73be2b0592SFredrik Modeenpublic:
74be2b0592SFredrik Modeen	// (slave) should be allocated with new, becomes property of this object.
751ecf19b8SJohn Scipione								NotFieldTester(BitFieldTester* slave);
761ecf19b8SJohn Scipione								NotFieldTester(BMessage* from);
771ecf19b8SJohn Scipione	virtual						~NotFieldTester();
78be2b0592SFredrik Modeen
791ecf19b8SJohn Scipione	virtual	status_t			Archive(BMessage* into,
801ecf19b8SJohn Scipione									bool deep = true) const;
811ecf19b8SJohn Scipione	static	BArchivable*		Instantiate(BMessage* from);
821ecf19b8SJohn Scipione	virtual	bool				IsMatching(uint32 field);
83be2b0592SFredrik Modeen
84be2b0592SFredrik Modeenprivate:
851ecf19b8SJohn Scipione			BitFieldTester*		fSlave;
86be2b0592SFredrik Modeen};
87be2b0592SFredrik Modeen
88be2b0592SFredrik Modeen
89be2b0592SFredrik Modeen// The most interesting class: This one returns true if at least (minNum) of
903bf15c7fSAugustin Cavalier// its slaves return true. It can be used for OR (i.e. minNum==1), AND
91be2b0592SFredrik Modeen// (i.e. minNum==numberofchildren), or anything in between!
92be2b0592SFredrik Modeen_EXPORT class MinMatchFieldTester;
93be2b0592SFredrik Modeenclass MinMatchFieldTester : public BitFieldTester {
94be2b0592SFredrik Modeenpublic:
951ecf19b8SJohn Scipione								MinMatchFieldTester(int32 minNum,
961ecf19b8SJohn Scipione									bool deleteSlaves = true);
971ecf19b8SJohn Scipione									MinMatchFieldTester(BMessage* from);
981ecf19b8SJohn Scipione	virtual						~MinMatchFieldTester();
99be2b0592SFredrik Modeen
100be2b0592SFredrik Modeen	// (slave) should be allocated with new, becomes property of this object.
1011ecf19b8SJohn Scipione			void				AddSlave(const BitFieldTester* slave);
102be2b0592SFredrik Modeen
1031ecf19b8SJohn Scipione	virtual	status_t			Archive(BMessage* into, bool deep = true) const;
1041ecf19b8SJohn Scipione	static	BArchivable*		Instantiate(BMessage* from);
1051ecf19b8SJohn Scipione	virtual	bool				IsMatching(uint32 field);
106be2b0592SFredrik Modeen
107be2b0592SFredrik Modeenprivate:
1081ecf19b8SJohn Scipione			BList				fSlaves;
1091ecf19b8SJohn Scipione			int32				fMinNum;
110be2b0592SFredrik Modeen
111be2b0592SFredrik Modeen	// true if we should delete all our slaves when we are deleted.
1121ecf19b8SJohn Scipione			bool				fDeleteSlaves;
113be2b0592SFredrik Modeen};
114be2b0592SFredrik Modeen
1151ecf19b8SJohn Scipione
1161ecf19b8SJohn Scipione#endif	// _BIT_FIELD_TESTERS_H
117