0

I am using Visual Assist X in Visual Studio 2008. I am defining a bunch of forward declaration files, all of which have basically the same format:

namespace ns1 { namespace ns2 {
    class SampleClassName;
    boost::shared_ptr<SampleClassName> SampleClassNamePtr;
}}

Obviously, I'm also putting in a header guard, a generated file comment, and other things as required by our coding standard (and the namespaces aren't placeholders).

Here's the issue: we name these files SampleClassNameForward.h so using the $FILE_BASE$ placeholder won't exactly work. Is there a way for me to apply a regex and remove the "Forward" from $FILE_BASE$ after it has been expanded, but prior to the snippet being pasted into my file? If I could do that, then I could fully automate generating these forward declarations and save myself (and my colleagues) a ton of time.

iamtheddrman
  • 623
  • 5
  • 16

1 Answers1

1

No, Visual Assist does not have any tools that would support regex modification of the file name as you are looking to do.

An alternative approach would be to create a VA Snippet that you use to create the block of code in a temporary file.

  • Create a VA Snippet that has all the boilerplate code.
  • add $SymbolName$Forward.h to the top of the code.
  • Invoke the snippet in the empty temporary file.
  • Cut the generated FooForward.h text at the top of the editor.
  • Select all (ctrl+a).
  • Invoke VAssistX | Refactoring | Move Selection to New File
  • At that point you would be prompted for the name of the new file and can paste the previously cut text (FooForward.h).

Move Selection To New File will create the new file in the same directory as the current file and add it to the same projects it is in.

sean e
  • 11,792
  • 3
  • 44
  • 56
  • Thanks for the alternative solution. We use a custom CMake toolkit to generate our VS solutions, so Move Selection to New File doesn't quite do what I need to add a file to a project. That said, your suggestion still works. I typically create the 3 files (header, forward header, source) and run my snippets for boilerplate code before adding them to CMake. I can just define the forward snippet, run it in the normal header, cut the code, run the normal header snippet, and paste the cut code into the forward file. Better than typing it all by hand! – iamtheddrman Feb 27 '14 at 21:51