Dateivorlage Visual Studio 2008 mit Parameter



  • Hi,

    hab eine neue Dateivorlage für Headerdatein (n bissl vorformattiert mit Kommentaren etc...) erstellt. Klappt soweit auch alles wunderbar. Jez gehts darum, dass ich n Klassenstub aufsetzen wollte. Bestenfalls mit dem Namen, den ich beim Erstellen der Datei angebe. Visual Studio stellt da n paar Parameter bereit (itemsafenameitemsafename, projectsafenameprojectsafename, ...). Diese müssen aber erst freigeschaltet werden in der zugehörigen vstemplate-Datei, was in der msdn nachzulesen ist. Jez das problem:

    Das ganze wollte ich vor C++-Projekte machen (Also Cpp und H-Datei erstellen). Diese vstemplate-Datein gibts aber nur für Web und C#. Daher habe ich dann auhc tatsächlich sowas in meinem erstellem Header:

    class itemsafenameitemsafename
    {
    };

    Weiß da jemand rat, wie ich da weiterkomme? Gibts diese Möglichkeit für C++-Projekte eigentlich/auch anders?

    Grüße heck



  • Ich verwende nen PythonScript dafür. War wesentlich zeitsparender zu implementieren^^.



  • Hab sowas auch schon mit Autoit geschrieben. Klappt auch ganz gu, aber jez wollte ihc ieg was direkt aus der IDE machen und nicht immer ein externes Skript dazu aufrufen.



  • So, hatte vorhin nicht viel Zeit.
    Hier mal das \1:

    #!/usr/bin/env Python
    
    #--------------------------------------------------------
    # File      : create.py
    # Author    : scorcher24
    # Purpose   : Creates a new class
    # Usage     : create.py -n classname.
    #--------------------------------------------------------
    from string import *
    from optparse import OptionParser
    from sys import exit
    from os import mkdir
    from os.path import exists
    
    gSOURCE_FOLDER = "NightLightDLL/"
    gINCLUDE_FOLDER = "NightLightDLL/"
    
    #--------------------------------------------------------
    # License
    #--------------------------------------------------------
    sLicense = """/*
      Project Nightlight
      Copyright (C) 2011 Scorcher24
      All rights reserved.                          
    
      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions
      are met:
    
        1. Redistributions of source code must retain the above copyright
           notice, this list of conditions and the following disclaimer.
    
        2. Redistributions in binary form must reproduce the above copyright
           notice, this list of conditions and the following disclaimer in the
           documentation and/or other materials provided with the distribution.
    
        3. The names of its contributors may not be used to endorse or promote 
           products derived from this software without specific prior written 
           permission.
    
      Scorcher24
      <email censored>
     */
    """
    
    #--------------------------------------------------------
    # Function: WriteHeader
    # Purpose : Writes a header to the disk,
    #           containing all necessary stuff.
    #--------------------------------------------------------
    def WriteHeader(name, path):
        path = path + ".hpp"
        print ("Creating " + path)
        sIncludeGuard = name    
        sIncludeGuard += "_HPP"
        sIncludeGuard = sIncludeGuard.upper()
    
        fpHeader = open(path, "w")
        fpHeader.write(sLicense)
        fpHeader.write("#ifndef " + sIncludeGuard + "\n")
        fpHeader.write("#define " + sIncludeGuard + "\n\n")
        fpHeader.write("namespace NightLight{\n\n")
        fpHeader.write("class " + name + "\n")
        fpHeader.write("{\n")
        fpHeader.write("};\n\n")
        fpHeader.write("}//namespace NightLight\n")
        fpHeader.write("#endif /* " + sIncludeGuard + " */\n")
        fpHeader.close();
    
    #--------------------------------------------------------
    # Function: WriteSource
    # Purpose : Writes the Source-File to the disk
    #           if mode is 'class'.
    #--------------------------------------------------------
    def WriteSource(path):
        path = path + ".cpp"
        print ("Creating " + path)
        fpSource = open(path, "w")
        fpSource.write(sLicense)
        fpSource.write("#include \"NightLight.hpp\"\n")
        fpSource.write("namespace NightLight{\n\n")
        fpSource.write("}//Namespace\n")
        fpSource.close();
    
    parser = OptionParser("%prog [options]")
    parser.add_option("-n", "--name", dest="name", help="Name of the class")
    (options, args) = parser.parse_args()
    
    if ( not options.name ):
        print("You must enter a name for the class.")
        parser.print_help()
        exit()
    else:
        WriteSource(gSOURCE_FOLDER + options.name )
        WriteHeader(options.name, gINCLUDE_FOLDER + options.name )
        exit()
    

    Ist halt angepasst auf ein Projekt von mir, aber das ist ja nicht das Problem. Man kann das bestimmt noch dynamischer machen wie Angabe von Namespace, Construcor/Destructor und und und.
    Aber mir taugts soweit.



  • freaker schrieb:

    Hab sowas auch schon mit Autoit geschrieben. Klappt auch ganz gu, aber jez wollte ihc ieg was direkt aus der IDE machen und nicht immer ein externes Skript dazu aufrufen.

    Total überlesen lol.
    Naja, das geht schon. Aber mit dem VB in Visual Studio komm ich nicht so gut zurecht. Und hmm, ich hab nicht so das Problem damit die Dateien manuell hinzuzufügen. Ich hab eh immer ne Shell offen.



  • Mit Python ists auch wesentlich angenehmer als mit Autoit, soviel schonmal dazu. Hab mich jez mal mit nem eigenen Add-In fürs VS versucht. Nuja sehr kompliziert und im Netz gibts zumeist nur Tutorials für C#. Würde zur Not aber auch noch gehen.


Anmelden zum Antworten