Re: C++: conditional static data member possible?



Hola Carlos,

Here's the puzzle I'm trying to solve:

Say that I have a shared library with, among other things,
a class A of which an application may or may not
instantiate objects.

I'm trying to enforce the guarantee that by the end of the
application, at least one object of class A has executed a
given action.

That part was easy: static data member that acts like a
flag --- the given action (which is one of class A methods)
notifies that static data member to that the flag is set.
That static object is implemented through a class whose
destructor verifies that the action has taken place, and
if not, it logs an error.

Now, the real puzzle I'm facing: if the application does
not *declare* a single object of class A, I do not want to
enforce anything (i.e., I do not want to report/log an
error because no object of class A has executed the action).

Perhaps my idea is too simplistic. But why you don't just extend the
flag as follows:

- in the constructor of the static object, flag is set the
'NotInstancied'.
- in the constructor constructor of object A, flag is set to
'Instancied'.
- in the given method of class A corresponding to the action to
execute, flag is set to 'Done'

Then, in the destructor of the static object, you react depending on
the flag value:

flag==NotInstancied => do nothing
flag==Instancied => log error (action has not be called)
flag==Done => Ok.

HTH,
Loic.

.



Relevant Pages

  • Re: C++: conditional static data member possible?
    ... in the constructor of the static object, flag is set the ... in the constructor constructor of object A, ... Then, in the destructor of the static object, you react depending on ...
    (comp.os.linux.development.apps)
  • Re: which book to start with...?
    ... The CPU *would* execute it, ... find that Nasm puts its name in a .comment section...). ... but i dont understand how the previous test will set the sign flag. ... Not a bad idea - I find Nasm's version of the instruction set reference useful, even though it isn't up-to-date. ...
    (alt.lang.asm)
  • Re: Determining whether an applications has thrown some error ...
    ... set some flag and check the flag whether error is thrown or not ... ... It depends on where the error happens and what type it is versus where you want to execute the code. ... If the error is an exception (as your use of the word "thrown" implies) you can put the code in a catch block and it will execute "immediately" after the error is thrown (depending on the rest of the code). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Looping in MS SQL 2000 DTS
    ... i think this behaviour and your code is correct, only the flag does not ... 'Set oPkg = DTSGlobalVariables.Parent ... 'Do not execute task 2, ... times trough that should not really be a replacement for sleep. ...
    (microsoft.public.sqlserver.dts)
  • Re: Question regarding UNIX access() call
    ... (Solaris, e.g., has eaccess() ... and a secret "E_OK" flag which you can or in to the access flags) ... you can execute a program before you actually executed it. ...
    (comp.unix.programmer)