Using With Class to Generate Visual C++ Code

Every once in a while when I'm programming, I complain to myself, "Do I really need to type so much?". I'm sure many programmers make the statement occasionally and even try to write macros to avoid the extra typing. I even had one Mac programmer tell me once that he never typed a single letter on the keyboard, but was able to construct all his programs with just a mouse. This of course seems to be a bit of an exaggeration, but exaggerating sometimes commands higher rates . The following article is an attempt to show you how to use With Class to shorten your development time. It shows you how to use With Class's unique scripting features to generate much of the needed drudgery.

The example I chose to use is a sound class. The sound class will be able to play a sound from the wave file is used to construct it. To make the object a little more interesting, we'll put a duration attribute in the object to allow you to determine how long the wave file will be played. The first step is to draw the class diagram in With Class. This is accomplished by using With Class's simple drawing tools:

We made Sound a subclass of CWnd so that we could take advantage of the timer feature of CWnd to cut out the duration of sound. Each of the attributes and operations of With Class are initially created by simply typing them into the class. Then the details of each are filled in by double-clicking on the class and filling the appropriate attribute and operation dialogs:

After all the details of With Class are filled in, we can show these by going to the View | Show Class menu and selecting Show Type, Show Parameters, etc.

Now we are ready to use the With Class Scripting language to generate some of the framework. The following is a minimal script for the header file:

Listing 1.

#ifndef __$CAPITALIZE_ALL$CLASS_NAME$_H
#define __$CAPITALIZE_ALL$CLASS_NAME$_H

> [
#ifndef __$CAPITALIZE_ALL$BASE_CLASS$_H
#include "$BASE_CLASS$.h"
#endif
]

[#include
]

class CLASS_NAME[NO_RETURN NO_REPEAT: NO_REPEAT public BASE_CLASS ,DELETE_LAST_SYMBOL]
{
[ATTRIBUTE_TYPE ATTRIBUTE_NAME;]
public:

[CPP_OPERATION_VIRTUAL CPP_OPERATION_STATIC OPERATION_RETURN_TYPE OPERATION_NAME
(CPP_OPERATION_PARAMETERS) CPP_OPERATION_CONSTANT CPP_OPERATION_PURE_VIRTUAL;]
};

#endif

The capitalized words are the keywords for with classes scripting languages. Brackets around keywords indicate repeat for each value. For example:

[ATTRIBUTE_TYPE ATTRIBUTE_NAME;]

This tells with class to write the attribute's type and attribute;s

The resulting code from the diagram four sound.h is:

Listing 2.

#ifndef __SOUND_H
#define __SOUND_H


#ifndef __CWND_H
#include "CWnd.h"
#endif

class Sound : public CWnd

{
int m_strFile;
int m_nDuration;
public:

Sound (CString& strFile, int nDuration = 0) ;
void Play () ;
void SetDuration (int nDuration) ;
void SetWaveFile (CString& strFile) ;
};

#endif
The user can also generate his CPP shell as well. For the CPP code, we will use the following script:
Listing 3.

#include "stdafx.h"
#include "$CLASS_NAME$.h"

[
// Function: OPERATION_NAME
// Purpose: OPERATION_COMMENT1
// Parameters: CPP_OPERATION_PARAMETERS
// Comments: OPERATION_COMMENT2
OPERATION_RETURN_TYPE CLASS_NAME::OPERATION_NAME(CPP_OPERATION_PARAMETERS) CPP_OPERATION_CONSTANT
{
OPERATION_CODE
}
]

The script will repeat for each method in With Class. OPERATION_COMMENT1 and OPERATION_COMMENT2 are used here for filling in the purpose and additional operation comments, but the user can use the fields for whatever they like. Note that the user can use the Code button in With Class to enter code so that the parameter OPERATION_CODE is filled in with any added code:


After the code is generated for the CPP file, the Import and Export C++ buttons can be used to import and export code to the same CPP file.

Well what do we get when we run the script? Here is the output generated by With Class:

Listing 4.

#include "stdafx.h"

#include "Sound.h"

// Function: Sound
// Purpose: Constructor for sound object
// Parameters: CString& strFile, int nDuration = 0
// Comments:
Sound::Sound(CString& strFile, int nDuration = 0)
{

}

// Function: Play
// Purpose: Play the Wave File Sound
// Parameters:
// Comments: This is limited to the m_nDuration variable
void Sound::Play()
{

}

// Function: SetDuration
// Purpose: Sets the duration of the sound
// Parameters: int nDuration
// Comments:
void Sound::SetDuration(int nDuration)
{
// code for set duration

m_nDuration = nDuration;

}

// Function: SetWaveFile
// Purpose: Set the wave file to be played
// Parameters: CString& strFile
// Comments:
void Sound::SetWaveFile(CString& strFile)
{

}

The SetDuration code was filled into our OPERATION_CODE keyword since we entered the code into With Class. Code can now be typed directly into the file sound.cpp and imported into With Class, or typed into With Class and exported into sound.cpp.

Additional code can be added to With Class to support the OnTimer function so that the sound object will jump into this function when the duration of the sound is up, and turn off the sound.

Conclusion: With Class's scripting language is flexible enough to allow the user to generate code however they wish. Additional script variables such as TAB_COLUMN allow the user to format code so that the code lines up properly. Look for future articles on With Class to give you more examples on using this powerful tool.

Michael Gold is a Software Developer at MicroGold Software.
He has been programming Visual C++ in the Financial and
Engineering industries for 4 ½ years. Feel free to write him
at 71543.1172@compuserve.com for any comments.

cialis link tw886to generic cialis prices best price viagra cialis cialis attorney cincinnati cialis lowest price generic cialis trial packs black buy casino cialis diet followup gambling health jack phentermine poker post viagra cialis and bodybuilding cialis medication free generic cialis samples black buy casino cialis diet followup gambling jack online order phentermine poker post viagra cialis black box cialis message boards generic cialis american express apotheke cialis cialis and levitra and viagra and generic cialis muscle ache generic cialis hong kong archive blog cialis inurl cialis and levitra cialis line mexico does cialis work for women allowed black buy casino cialis diet holdem jack online order phentermine poker tag texas viagra xhtml cialis and multiple coitus cialis no prescription generic cialis price best for premature ejaculation viagra cialis levitra cialis and women cialis link liracrogreekbostoncom generic cialis allowed casino cialis diet phentermine poker tag viagra xhtml cialis add url cialis lawyer ohio experience cialis without ed allowed cialis phentermine tag viagra xhtml cialis back pain cialis online order how to get free cialis sample black buy casino cialis diet gambling jack order phentermine poker tag viagra xhtml cialis discount cialis maximum dose international order for generic cialis blogid buy casino cialis generic inurl order phentermine poker viagra cialis and blood pressure cialis mexico is cialis for me blogid buy casino cialis inurl phentermine poker viagra cialis and grapefruit cialis levitra viagra discount cialis best buy cialis generic ciales rock climbing cialis international shipping does cialis or levitra work best for diabetics allowed black buy casino cialis diet health jack phentermine poker sex tag title viagra xhtml cheap viagra cialis cialis lawyer cincinnati effectiveness of cialis reported allowed black casino cialis diet gambling jack phentermine poker tag viagra xhtml cheapest and cialis and generic and lowest price cialis injury attorney ohio compare levitra and cialis add cialis link suggest catholic cult and cialis cialis lcos lily online free cialis approval cialis fda cialis and early ejaculation cialis levitra viagra interaction generic cialis cheap free shipping free consultation articles on cialis cheapest cialis cialis injury lawyer columbus generic cialis international shipping buy cheapest cialis cialis compare levitra viagra cialis line prescription generic cialis next day black buy casino cheap cialis diet followup gambling health jack online order phentermine poker post viagra ciales cialis international shipping contact number cialis add buy cialis url cialis 20mg tablet cialis liquid how long does cialis take to work black buy casino cialis diet gambling health jack phentermine poker tag viagra xhtml cialis and alcohol cialis lawyer cleveland effectiveness viagra cialis levitra allowed casino cialis phentermine tag viagra xhtml cheapest cialis free samples cialis levitra versus versus viagra fda pharmaceutical testing trials cialis anti cialis impotence cheapest cialis price cialis injury attorney columbus compare viagra cialis and levitra add cialis site cheapest cialis with no perscription cialis injury lawyer cleveland compare viagra to cialis achat ligne cialis cheap cialis link suggest cialis impotence drug cialis with no prescription add buy cialis site canada cialis online cialis information prescribing cialis viagra taken together where can i buy cialis online black buy casino cialis diet followup gambling jack order phentermine poker post viagra cialis blindness cialis link suggest diabeties viagra cialis levitra allowed black buy casino cialis diet gambling jack order phentermine poker tag viagra xhtml cheap cialis online cialis generic tadalafil cialis without prescriptions add cialis generic link cialis and levitra taken together cialis information clinical trial testing cialis for high blood preasure add cialis link online canada generic cialis cialis germany cialis strength time line to buy without prescription cialis or levitra in detrit area buy cialis submit=buy cialis cialis drug interaction cialis online liquid cialis black buy casino cialis diet followup gambling jack low online order phentermine poker viagra cialis attorney cleveland cialis injury lawyer cincinnati cialis vs viagra .. can you take cialis with viagra cialis home page cialis western open ticket add buy cialis link canada cialis generic cialis generic online cialis uprima viagra value pharmaceuticals cialis buy cialis order cialis eli lilly cialis pharmacy natural supplement like cialis