Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Snippet GUID variation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mwalshe
New Member

United Kingdom
9 Posts

Posted - Oct 21 2010 :  05:40:23 AM  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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?
Go to Top of Page

mwalshe
New Member

United Kingdom
9 Posts

Posted - Oct 22 2010 :  10:22:21 AM  Show Profile  Reply with Quote
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.
Go to Top of Page

holedigger
Whole Tomato Software

145 Posts

Posted - Oct 22 2010 :  5:10:02 PM  Show Profile  Reply with Quote
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
Go to Top of Page

GKarRacer
Ketchup Master

USA
58 Posts

Posted - Oct 28 2010 :  4:18:11 PM  Show Profile  Reply with Quote
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.
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Oct 29 2010 :  03:08:27 AM  Show Profile  Reply with Quote
#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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000