2 * Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
6 /*! \class SimpleMessageFilter
7 \brief This is a BMessageFilter that can filter multiple \a what values.
9 This class extends the BMessageFilter's ability of handling one \a what value
10 to handling multiple \a what values.
13 #include "SimpleMessageFilter.h"
17 /*! \brief Creates a copy of the \a what array.
19 \param what A pointer to an array of \a what values that should be filtered.
20 The end-of-list indicator is an element valued 0 (zero).
21 \param target The target for messages matching one of the \a what values.
22 If \a target == NULL the messages will be discarded.
24 SimpleMessageFilter::SimpleMessageFilter(const uint32
*what
, BHandler
*target
)
25 : BMessageFilter(B_ANY_DELIVERY
, B_ANY_SOURCE
),
33 // include the trailing zero in the copy
35 while(what
[count
++] != 0)
37 fWhatArray
= new uint32
[count
];
38 memcpy(fWhatArray
, what
, count
* sizeof(uint32
));
42 //! Frees the copied \a what array.
43 SimpleMessageFilter::~SimpleMessageFilter()
49 //! Filters all messages that match the \a what array given in the constructor.
51 SimpleMessageFilter::Filter(BMessage
*message
, BHandler
**target
)
53 for(int32 index
= 0; fWhatArray
[index
] != 0; index
++)
54 if(fWhatArray
[index
] == message
->what
) {
56 return B_SKIP_MESSAGE
;
62 return B_DISPATCH_MESSAGE
;