[iostreams] how to say a filter is closable
I want to write a filter but this filter needs to do some things when the stream is ending. Is it enough to do the following? I want the close function to be called at the end of the stream. Do I need to category_flag to inherit from (closable_tag)? class my_filter : public io::dual_use_filter { public: template<typename Source> int get(Source&) ; template<typename Sink> bool put(Sink&, int) ; template<typename Device> void close(Device&, std::ios_base::openmode) ; } ; Fred Avis : Ce message et toute pièce jointe sont la propriété d'Alcan et sont destinés seulement aux personnes ou à l'entité à qui le message est adressé. Si vous avez reçu ce message par erreur, veuillez le détruire et en aviser l'expéditeur par courriel. Si vous n'êtes pas le destinataire du message, vous n'êtes pas autorisé à utiliser, à copier ou à divulguer le contenu du message ou ses pièces jointes en tout ou en partie. Notice: This message and any attachments are the property of Alcan and are intended solely for the named recipients or entity to whom this message is addressed. If you have received this message in error please inform the sender via e-mail and destroy the message. If you are not the intended recipient you are not allowed to use, copy or disclose the contents or attachments in whole or in part.
boost-users-bounces@lists.boost.org, le 8 janvier 2008 06:40:
I want to write a filter but this filter needs to do some things when the stream is ending. Is it enough to do the following? I want the close function to be called at the end of the stream. Do I need to category_flag to inherit from (closable_tag)?
class my_filter : public io::dual_use_filter { public: template<typename Source> int get(Source&) ; template<typename Sink> bool put(Sink&, int) ; template<typename Device> void close(Device&, std::ios_base::openmode) ; } ;
Well, there's nothing like trying it out but, from the docs:
- A dual_use_filter is a typedef for filter
frederic.bron@alcan.com wrote:
I want to write a filter but this filter needs to do some things when the stream is ending. Is it enough to do the following? I want the close function to be called at the end of the stream. Do I need to category_flag to inherit from (closable_tag)?
class my_filter : public io::dual_use_filter { public: template<typename Source> int get(Source&) ; template<typename Sink> bool put(Sink&, int) ; template<typename Device> void close(Device&, std::ios_base::openmode) ; } ;
Hi Fred, Eric is correct: the convenience base class dual_use_filter has category convertible to closable_tag, and a no-op implementation of close. -- Jonathan Turkanis CodeRage http://www.coderage.com
ok, I have seen this now, thanks. However, I must create a derived class from dual_use_filter and those no-op operation are not virtual and it is good practice not to redefine non-virtual member functions. So what's happening whenever I use a pointer or reference to a base class? Maybe this never happens because chain.push takes a template parameter... am I right? Regards, F. Bron boost-users-bounces@lists.boost.org a écrit sur 08/01/2008 22:12:21 :
frederic.bron@alcan.com wrote:
I want to write a filter but this filter needs to do some things
when the stream is ending.
Is it enough to do the following? I want the close function to be called at the end of the stream. Do I need to category_flag to inherit from (closable_tag)?
class my_filter : public io::dual_use_filter { public: template<typename Source> int get(Source&) ; template<typename Sink> bool put(Sink&, int) ; template<typename Device> void close(Device&, std::ios_base::openmode) ; } ;
Hi Fred,
Eric is correct: the convenience base class dual_use_filter has category convertible to closable_tag, and a no-op implementation of close.
-- Jonathan Turkanis CodeRage http://www.coderage.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Avis : Ce message et toute pièce jointe sont la propriété d'Alcan et sont destinés seulement aux personnes ou à l'entité à qui le message est adressé. Si vous avez reçu ce message par erreur, veuillez le détruire et en aviser l'expéditeur par courriel. Si vous n'êtes pas le destinataire du message, vous n'êtes pas autorisé à utiliser, à copier ou à divulguer le contenu du message ou ses pièces jointes en tout ou en partie. Notice: This message and any attachments are the property of Alcan and are intended solely for the named recipients or entity to whom this message is addressed. If you have received this message in error please inform the sender via e-mail and destroy the message. If you are not the intended recipient you are not allowed to use, copy or disclose the contents or attachments in whole or in part.
frederic.bron@alcan.com wrote:
ok, I have seen this now, thanks. However, I must create a derived class from dual_use_filter and those no-op operation are not virtual and it is good practice not to redefine non-virtual member functions.
So what's happening whenever I use a pointer or reference to a base class?
sink, source, filter, dual_use_filter, etc., are designed specifically to allow user-defined components to inherit a partial implementation; they are like std::iterator or std::unary function in this respect. A pointer to the base class would be useless, because the base does not actually model any of the Boost.Iostreams concepts. dual_use_filter is not actually a model of Dual Use Filter; it is just a helper. If you feel uncomfortable using the convenience classes, it is simple enough to define a component from scratch by defining suitable member types char_type and category.
Maybe this never happens because chain.push takes a template parameter... am I right?
Yes
Regards,
F. Bron
Best Regards, -- Jonathan Turkanis CodeRage http://www.coderage.com
participants (3)
-
Eric MALENFANT
-
frederic.bron@alcan.com
-
Jonathan Turkanis