Disabling Tokenizer in Derived Classes - after their constructors have been executed.
Hi, I have boost tokenizer and its iterator stored in my base class. The tokenizer got initialized with a const std::string&. I do the tokenization in my base class and provide the iterator, pointing to the first token, to the derived classes - but only to be used in their constructors. After the derived class constructor has been executed, the tokenizer and its iterator should not remain available - what can I do to accomplish that? Best regards, Asif
I have boost tokenizer and its iterator stored in my base class. The tokenizer got initialized with a const std::string&. I do the tokenization in my base class and provide the iterator, pointing to the first token, to the derived classes - but only to be used in their constructors. After the derived class constructor has been executed, the tokenizer and its iterator should not remain available - what can I do to accomplish that?
[This is less of a boost issue and more of a general design issue...] 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? Regards, Nate
Hi Nate,
On Thu, Aug 4, 2011 at 12:55 AM, Nathan Ridge
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
participants (2)
-
asif saeed
-
Nathan Ridge