Boost logo

Boost Users :

Subject: Re: [Boost-users] Disabling Tokenizer in Derived Classes - after their constructors have been executed.
From: asif saeed (asif.lse2_at_[hidden])
Date: 2011-08-04 01:24:59


Hi Nate,

On Thu, Aug 4, 2011 at 12:55 AM, Nathan Ridge <zeratul976_at_[hidden]>wrote:

> Why do the tokenizer and the iterator need to be in the base class at all?
> Why not just construct them on the stack in the derived constructor?
>

Basically, the derived class instances have very short life - all objects
are created on stack. And, all the derived class need to parse tokens and
have to create a Tokenizer, character separator, etc., anyway. Putting
Boost.Tokenizer and character separator in Base class free me (and others)
from having to create Tokenizer in the derived classes (there are too many)
and I can just repeatedly use the nextToken() that I have defined in the
base class to get all the tokens. Anyway, my problem is solved now -
iterators become invalid after execution of the derived class constructors.
Basically, I don't want anyone to write monolithic functions that do
everything in the world. So, I don't want them to mix business domain logic
with parsing code and vice versa and, in handling callbacks, I don't want
them to parse. Just a small measure for maintainability. Since
Boost.Tokenizer and character_separator will be created anyway and since
derived classes have very short life and all derived classes' objects get
created on stack, I think there is no harm in putting the Tokenizer &
character separator in the base class - I am not separately storing the
string-to-be-passed in the base class though as that apparently gets stored
by the Tokenizer itself.

Thanks & regards, Asif



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net