Author |
Topic |
|
mwalshe
New Member
United Kingdom
9 Posts |
Posted - Oct 21 2010 : 05:40:23 AM
|
I'd like to use a code snippet to generate a uniqiue guard value for my C++ header files. I'm trying to use a GUID along with the filename to ensure I get a unique name:
e.g.
#if !defined(_Engine_H_C0F2B6DC_339B_4F1E_877D_A6DAB91FD296_INCLUDED_) #define _Engine_H_C0F2B6DC_339B_4F1E_877D_A6DAB91FD296_INCLUDED_
#endif // _Engine_H_C0F2B6DC_339B_4F1E_877D_A6DAB91FD296_INCLUDED_)
so the kind of snippet I would define is as follows
#ifndef _$FILE_BASE$_H_$GUID_STRING$_INCLUDED_ #define _$FILE_BASE$_H_$GUID_STRING$_INCLUDED_
#endif // _$FILE_BASE$_H_$GUID_STRING$_INCLUDED_
My problem is that whilst the substiution that $GUID_STRING$ makes is close to what I'm after it separates the guid elements with '-' character which the preprocessor rejects with an 'unexpected tokens' error. Would it be possible to add an extra $GUID_$ code that separates the guid elements with a character that is acceptable to the C++ preprocessor, e.g. '_'?
Great product. Can't use Visual Studio without it.
Thanks
Max
|
|
accord
Whole Tomato Software
United Kingdom
3287 Posts |
Posted - Oct 21 2010 : 2:40:54 PM
|
What about
_$FILE_BASE$_H_$YEAR$_$MONTH$_$DAY$_$HOUR$_$MINUTE$_$SECOND$
it produces something like this:
_someheader_H_2010_10_21_20_38_34
quite unique, isn't it? |
|
|
mwalshe
New Member
United Kingdom
9 Posts |
Posted - Oct 22 2010 : 10:22:21 AM
|
Indeed, an alternative that I had not considered.
The benefit of the $GUID_xxx$ approach is that I can ensure it's consist throught the snippet.
Would $SECOND$ for example remain consistent from start to end? If it is evaluated on demand then there is the possibilty that it could be different towards the end of the snippet. |
|
|
holedigger
Whole Tomato Software
145 Posts |
Posted - Oct 22 2010 : 5:10:02 PM
|
Yes, $SECOND$ will be constant within a snippet. The system time is queried once, and all instances of $SECOND$, $MINUTE$, etc, are updated with their respective values. |
Whole Tomato Software |
|
|
GKarRacer
Ketchup Master
USA
58 Posts |
Posted - Oct 28 2010 : 4:18:11 PM
|
Alternatively use
#pragma once
and then you never need the #ifdef guard blocks around the entire header ever again, except, of course, if you need cross-platform support with a compiler (other than VS) that doesn't support the #pragma once directive.
|
|
|
accord
Whole Tomato Software
United Kingdom
3287 Posts |
Posted - Oct 29 2010 : 03:08:27 AM
|
#pragma once is not standard but a lot of compilers support it, e.g. Intel compiler and GCC |
Edited by - accord on Oct 29 2010 03:10:56 AM |
|
|
|
Topic |
|