Using Code Templates
A code template is a ready-made body for a driver member: a method or property in an IVI.NET or IVI-COM driver, or a function or attribute in an IVI-C driver. Templates put a company’s own implementation conventions, such as its tracing, error handling, or simulation code, into every member a driver developer adds, instead of Nimbus’s stub being edited by hand each time.
Code templates are available for all three driver types: IVI.NET, IVI-COM, and IVI-C.
How templates are used
Section titled “How templates are used”A template reaches a member’s body in one of two ways:
- As a default, for new members. A driver’s template set can mark one template as the default for each member kind. Every member of that kind created afterward gets the template’s body in place of Nimbus’s stub. Changing the default affects only members created afterward. Existing members are never changed.
- Applied to existing members. The Apply Code Template command in the Driver Designer replaces the bodies of the selected members with a template’s body. See Applying a Template to Existing Members.
A default template is used wherever Nimbus would otherwise write its stub for a Manual member:
- when a member is added in the Driver Designer
- for the members a new driver is created with
- when an instrument class or a class-compliant interface is added to an existing driver
- when a property or attribute gains an accessor it did not have, for example when a read-only property is made read/write
Members whose code Nimbus generates, such as inherent capabilities, Instrument command and Automatic members, Direct I/O members, and repeated capability management members, are not affected. In an IVI.NET driver, only members of the classes that implement the driver’s interfaces get templates. In an IVI-COM driver, the functions of the IVI-C wrapper keep Nimbus’s stubs. An IVI.NET driver’s linked IVI-C driver is not a wrapper, and gets templates like any other IVI-C driver. See Linked IVI-C drivers.
What a template is
Section titled “What a template is”- Verbatim code. A template’s text is written into the body exactly as it is, indented to fit. There are no replacement tags: a tag such as the member’s name would be baked into text that the next rename or parameter change leaves stale.
- Written once. Once a template’s text is written into a body, the body is ordinary manual code. Nimbus treats it exactly as it treats any other Manual member, and never applies the template to it again.
- Optional. Nimbus ships no templates. A driver with no template set, or whose set marks no default for a member kind, gets exactly the stubs Nimbus has always generated.
| Term | Meaning |
|---|---|
| Template | One body, with a name and a preamble setting. A method or function template is one file. A property or attribute template is a getter file, a setter file, or both. |
| Default template | The template a set marks as the default for its member kind. New members of that kind get its body. |
| Template set | A collection of templates for one driver type, described by a manifest.yaml file. |
| Machine catalog | The template sets available on a machine, each in a folder named for the set. A set in the catalog can have a part for each driver type. |
| The driver’s template set | The single set a driver carries, in the driver project’s CodeTemplateSet folder. An IVI.NET driver with a linked IVI-C driver carries it in two such folders, one in each driver project. |
Where template sets live
Section titled “Where template sets live”The machine catalog is the folder
<ProgramData>\Pacific MindWorks\Nimbus\<version>\CodeTemplates
Each set in the catalog is a folder named for the set, holding a part for each driver type it supports: IviC,
IviCom, or IviNet. Like help templates, the catalog belongs to one Nimbus version, so sets must be deployed
again when that version changes.
A driver never uses a catalog set directly. Choosing a set copies its part for the driver’s type into the driver
project’s CodeTemplateSet folder, where it is under source control with the rest of the driver, so everyone
working on the driver gets the same bodies. The files are part of the project but are never compiled. Default
templates come only from the driver’s own set, because a catalog set may exist on only some machines.
A driver gets its template set in one of three ways:
- In the new driver wizard. The Code template set field on the wizard’s General page chooses the set the new driver starts with. It starts out as the set chosen in Tools > Options.
- In Tools > Options. The Template set for new drivers option on the General page for all drivers chooses the set the new driver wizard offers first.
- On the Code Templates page of Driver Settings. The page switches a driver to a catalog set, creates a new set in the driver, removes the driver’s set, and saves the driver’s set to the machine catalog. See The Code Templates Page.
Linked IVI-C drivers
Section titled “Linked IVI-C drivers”An IVI-C driver linked to an IVI.NET driver is a full IVI-C driver, whose functions and attributes are implemented
by hand like those of a standalone IVI-C driver, so it gets code templates in exactly the same way. The IVI.NET
driver’s template set then has two parts, each in the CodeTemplateSet folder of its own driver project: the
IVI.NET part in the IVI.NET driver project, and the IVI-C part in the IVI-C driver project. The IVI-C driver
project looks exactly as it would if the driver were not linked.
The two parts work as one set:
- Creating the driver. When the new IVI.NET driver wizard also creates a linked IVI-C driver, the IVI-C driver gets the chosen set’s IVI-C part, if the set has one. An IVI-C driver linked later, from the IVI-C page of Driver Settings, gets the IVI-C part of the set chosen in the wizard that creates it.
- New members. A method or property added to the IVI.NET driver gets the IVI.NET part’s default, and the IVI-C function or attribute linked to it gets the IVI-C part’s default.
- The Code Templates page shows both parts together, and its commands act on both. See Linked IVI-C drivers on that page.
- Apply Code Template offers the IVI-C part’s templates for the IVI-C driver’s functions and attributes. See The Apply Code Template dialog.
Topics in this section
Section titled “Topics in this section”- Template Set Format: the
manifest.yamlfile, the template files, and the preamble setting. - The Code Templates Page: viewing, choosing, creating, and sharing a driver’s template set.
- Applying a Template to Existing Members: the Apply Code Template command in the Driver Designer.