weird macros

hello I’m trying to make a better logging class
http://oldlook.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20791532.html

but i have come across a problem, and i think i need a macro to finish it off.
When ever I use the log class i want the writeflags function to be called but I want it to be invisible so I don’t have to write that function line out every time.
i hope that makes sense

Normally
log.writeflags(__FILE__,__LINE__) << "something" ;

what i want
log << "something" ;

what i'm using right now
#define __FLAGS    writeflags(__FILE__,__LINE__)
log.__FLAGS << "something" ;  
LVL 2
funvillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tinchosCommented:
Hi funvill

I've read your post, but I quite don't get what the problem is............. I guess that what you posted is correct

#define __FLAGS    writeflags(__FILE__,__LINE__)

log.__FLAGS << "something" ;  

with this piece of code,

before compiling, the preprocessor would replace all the ocurrences of __FLAGS with writeflags(__FILE__,__LINE__)

so, in

log.__FLAGS << "something" ;  

it would replace it with

log.writeflags(__FILE__,__LINE__)  << "something" ;  

and I guess that this is what you're looking for

and that's why I think that your piece of code is OK

Not sure if this helps.... hope it does

Tincho
0
funvillAuthor Commented:
i want it too look like this,

log << "something" ;

when the user is calling the log function i also whant it to call writeflags(__FILE__,__LINE__)  function before the opertator <<
and i do not want to have to type anything extra
so

i want this;
log.writeflags(__FILE__,__LINE__) << "something" ;

to turn in to this
log << "something" ;
0
tinchosCommented:
Well, actually there you have 2 different possibilities............

1) I'm not quite sure what the class of the log object is........ but if you reimplement operator<< for that class so that you include those writeflags there is one possibility...........

2) you can also, and similar to what you posted...........

#define LOG log.writeflags(__FILE__,__LINE__)

LOG << "something"

The problem with the first one is that I'm not sure if you can change the implementation of the operator<< as I'm not sure of which class it belongs to

The problem with the last one is that the preprocessor will replace all LOG with log.writeflags( __FILE__, __LINE__ )
so, your variable can only be called log and not with any other name.

Hope this helps

Tincho
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

osp70Commented:
what about overriding the operator << in your log class so that is takes in the string but then does the rest.
0
tinchosCommented:
Well, I guess that osp chooses option 1 then. :)

Tincho
0
osp70Commented:
yes, I read your answer and copied part of it in the hopes to grab some points

OR

I was reading the post before you submitted your answer and submitted mine.

:)
0
funvillAuthor Commented:
re: tinchos
[1]
my log is a class that opens a file when it is created and puts time stamps and stores the log file in a perditulare place. and yes i have  reimplement << 
writeflags(__FILE__,__LINE__) is a function that returns a refercen to a log obj after it writes the file and line to a file.

[2]
#define LOG log.writeflags(__FILE__,__LINE__)

this will not work because, what if they make a log object called errorlog and other called userlog
log errorlog;
log userlog;
i should have stated that my class is called log

re: osp70

i cant implment it in the operator << because i need to call writeflags( __FILE__, __LINE__ ) from the file that is sending the log message

__FILE__
__LINE__
are macros http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/prepr_18.asp that have to be define in the file that they came from.
err if i where to put writeflags( __FILE__, __LINE__ ) in the implment for operator << it would just keep displaying the
__FILE__
__LINE__
with the line and file of the source for the implment of operator << 
0
funvillAuthor Commented:
sorry i should have done this first off

heres my source code
http://downloads.funvill.com/stuff/logy_v0.01aA.zip

in the main function i use
a.__flags << "something";

i don't want it have to write __flags every time. and i want it to look like this
a. << "something";


0
tinchosCommented:
osp:

please, don't take it wrong.......
just a joking......
I know it happens all the time

funvill:
I guess that if those macros must appear in that line, then your only choice is


#define LOG log.writeflags(__FILE__,__LINE__)

this will not work because, what if they make a log object called errorlog and other called userlog
log errorlog;
log userlog;
i should have stated that my class is called log

for which you can always say

#define ERRORLOG errorlog.writeflags(__FILE__,__LINE__)
#define USERLOG userlog.writeflags(__FILE__,__LINE__)

Hope this helps

Tincho
0
funvillAuthor Commented:
I’m am not just writing this for my self, when I deem it complete I will give it to my boss and it will become the coding slandered for my company.
When people look at this class they do not want to have to do any extra steps like

#define USERLOG userlog.writeflags(__FILE__,__LINE__)

So, sorry I do not want to have to ask them to make a #define for each different file
0
tinchosCommented:
Ok funvill

Sincerely I don't quite like this solution, I would be very happy to be able to program without any macro.

I'm not saying neither that there aren't any other possibilites, nor that this is a good one, just that it's the only that came to mi mind.

Finally one last suggestion in order to improve it a little more

#define LOG( varName ) varname.writeflags(__FILE__,__LINE__)

in this case you would just have to add the define in the log.h header class and you would just have to include it and call it with the variable name

calling it with

LOG( userLog );
LOG( errorLog );

Hope this helps

Tincho
0
funvillAuthor Commented:
re: tinchos
this might be a decent solution...
but I’m going to look around for the rest of the day for my perfect solution, if I don't find it then i will accept this one.
thank you very much for your help
0
tinchosCommented:
Ok funvill

I agree with you that this is a decent solution, not an optimal one.

Please, if you find a better one let me know....... ;)

Cheers

Tincho
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.