Difference between revisions of "Ide/Creating new Project Items/Creating a Package"
m (remove v7 reference) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude>[[Category:Ide]]</noinclude> | <noinclude>[[Category:Ide/Create New Project Items]]</noinclude> | ||
The basic units of code organization accepted in Visual Prolog | == Creating a Package == | ||
The basic units of code organization accepted in Visual Prolog are ''packages''. We use packages in Visual Prolog to organize and structuring things. The use of packages ensures homogeneity in structuring principles among different projects. Packages define the standard for tool structuring, they ease sharing source code among projects. | |||
By default, the IDE organizes projects into packages. When you create a new package in a project, the IDE creates: | By default, the IDE organizes projects into packages. When you create a new package in a project, the IDE creates: | ||
* The subdirectory into which the package files will be placed. | * The subdirectory into which the package files will be placed. | ||
* The package header file (i.e. | * The package header file (i.e. <vp>NewPackage.ph</vp>) that describes the ''public'' view of the package. The package header file should be inserted by <vp>#include</vp> directives in all other packages that use the package. The package header file contains the list of ''public'' interfaces, the list of ''public'' classes, and some <vp>#requires</vp> directives.<br />Names declared in public interfaces and classes are seen outside the package in all places where the package header file is included. <vp>#requires</vp> directives are used to guaranty that all packages required to use the package are included into the project. | ||
* The package implementation file (i.e. | * The package implementation file (i.e. <vp>NewPackage.pack</vp>) produces a Visual Prolog compilation unit which is added to a set of project modules. | ||
=== How to Create a New Package? === | |||
To create a new package in a project you should select the IDE menu command '''File | New'''. In the left pane of the appeared '''Create Project Item''' dialog you should select '''Package'''. Then the dialog accepts the following shape: | To create a new package in a project you should select the IDE menu command '''File | New'''. In the left pane of the appeared '''Create Project Item''' dialog you should select '''Package'''. Then the dialog accepts the following shape: | ||
Line 16: | Line 18: | ||
'''Name:''' | '''Name:''' | ||
In the '''Name''' edit control you should type in the name of the package being created ( | :In the '''Name''' edit control you should type in the name of the package being created (<vp>NewPackage</vp> in the picture). | ||
'''Parent Directory''' | '''Parent Directory''' | ||
In the '''Parent Directory''' field you should type in or select (using the '''Browse''' button) the ''parent directory'' for the package. The package will be placed into the subdirectory of this ''parent directory''. By default, when you activate this dialog, '''Parent Directory''' displays the directory selected in the {{ide|Project Tree#The Project Tree|project tree}}. If this directory is one of project subdirectories, then its path is displayed relatively to the project root directory. | :In the '''Parent Directory''' field you should type in or select (using the '''Browse''' button) the ''parent directory'' for the package. The package will be placed into the subdirectory of this ''parent directory''. By default, when you activate this dialog, '''Parent Directory''' displays the directory selected in the {{ide|Project Tree#The Project Tree|project tree}}. If this directory is one of project subdirectories, then its path is displayed relatively to the project root directory. | ||
In this '''Parent Directory''' the IDE creates a new subdirectory with the name correspondent to the specified package name. The package will be placed into this subdirectory. | :In this '''Parent Directory''' the IDE creates a new subdirectory with the name correspondent to the specified package name. The package will be placed into this subdirectory. | ||
After you fill in all required settings for the package, you can press the '''Create''' button. Then the IDE creates the package subdirectory, the package header file | After you fill in all required settings for the package, you can press the '''Create''' button. Then the IDE creates the package subdirectory, the package header file <vp>NewPackage.ph</vp>, and the package implementation file <vp>NewPackage.pack</vp>. (They will appear in the {{ide|Project Tree#The Project Tree|project tree}} in the '''Project Window''' after the created package is compiled.) | ||
=== Packages === | |||
The concept of packages is used for grouping together several linked interfaces and classes. Packages can play a role of some class library. Packages can be used in your program instead of direct placing all these interfaces and classes into your program. | The concept of packages is used for grouping together several linked interfaces and classes. Packages can play a role of some class library. Packages can be used in your program instead of direct placing all these interfaces and classes into your program. | ||
Line 32: | Line 34: | ||
The package is a collection of several grouped together interfaces and classes. The package provides some common name to all these interfaces and classes. Each declaration or implementation of each interface or class from a package is placed in a separate file. Each filename (of these files) coincides with the name of a class or an interface that is declared or implemented in this file. All package files are stored in the same separate package directory. (If a package contains sub-packages, then they are placed in subdirectories of the package directory.) | The package is a collection of several grouped together interfaces and classes. The package provides some common name to all these interfaces and classes. Each declaration or implementation of each interface or class from a package is placed in a separate file. Each filename (of these files) coincides with the name of a class or an interface that is declared or implemented in this file. All package files are stored in the same separate package directory. (If a package contains sub-packages, then they are placed in subdirectories of the package directory.) | ||
Except for files with declarations and implementations of interfaces and classes, each package contains two special files: the ''package header'' ('''. | Except for files with declarations and implementations of interfaces and classes, each package contains two special files: the ''package header'' ('''.ph''') and the ''package implementation'' ('''.pack''') files. | ||
* The ''package header'' file provides declarations of all names exported from the package. Therefore, the package header file should be inserted by the <vp>#include</vp> directive in each other package that uses some names exported from this package. | * The ''package header'' file provides declarations of all names exported from the package. Therefore, the package header file should be inserted by the <vp>#include</vp> directive in each other package that uses some names exported from this package. | ||
* The ''package implementation'' file provides code implementing the package classes which can be compiled into an object file. The package implementation file should be included only once into a project that uses this package. | * The ''package implementation'' file provides code implementing the package classes which can be compiled into an object file. The package implementation file should be included only once into a project that uses this package. | ||
So using the concept of packages we can create sets of linked interfaces and classes grouped into packages. Once created package can be included (and used) in several programs without copying package sources into each project. The example of such set of packages is our | So using the concept of packages we can create sets of linked interfaces and classes grouped into packages. Once created package can be included (and used) in several programs without copying package sources into each project. The example of such set of packages is our Visual Prolog Foundation Classes (PFC). | ||
=== Package Header Files === | |||
The package header file provides external view of the package. | The package header file provides external view of the package. | ||
Line 53: | Line 55: | ||
A package header file does not produce any compiled code, but it is used while compilation to declare names exported from the package. | A package header file does not produce any compiled code, but it is used while compilation to declare names exported from the package. | ||
Usually a package header file has the | Usually a package header file has the <vp>PackageName.ph</vp> name. | ||
=== Package Implementation Files === | |||
The package implementation file provides code implementing classes declared in the package. Compilation of the package implementation file generates object file that provides real implementations of classes declared in the package. | The package implementation file provides code implementing classes declared in the package. Compilation of the package implementation file generates object file that provides real implementations of classes declared in the package. | ||
Line 65: | Line 67: | ||
* It provides <vp>#include</vp> directives for all files with class implementations ('''.pro''' files) that provides Prolog code implementing all classes declared the package. | * It provides <vp>#include</vp> directives for all files with class implementations ('''.pro''' files) that provides Prolog code implementing all classes declared the package. | ||
Usually a package implementation file has the | Usually a package implementation file has the <vp>PackageName.pack</vp> name. |
Latest revision as of 14:12, 25 September 2018
Creating a Package
The basic units of code organization accepted in Visual Prolog are packages. We use packages in Visual Prolog to organize and structuring things. The use of packages ensures homogeneity in structuring principles among different projects. Packages define the standard for tool structuring, they ease sharing source code among projects.
By default, the IDE organizes projects into packages. When you create a new package in a project, the IDE creates:
- The subdirectory into which the package files will be placed.
- The package header file (i.e. NewPackage.ph) that describes the public view of the package. The package header file should be inserted by #include directives in all other packages that use the package. The package header file contains the list of public interfaces, the list of public classes, and some #requires directives.
Names declared in public interfaces and classes are seen outside the package in all places where the package header file is included. #requires directives are used to guaranty that all packages required to use the package are included into the project. - The package implementation file (i.e. NewPackage.pack) produces a Visual Prolog compilation unit which is added to a set of project modules.
How to Create a New Package?
To create a new package in a project you should select the IDE menu command File | New. In the left pane of the appeared Create Project Item dialog you should select Package. Then the dialog accepts the following shape:
Name:
- In the Name edit control you should type in the name of the package being created (NewPackage in the picture).
Parent Directory
- In the Parent Directory field you should type in or select (using the Browse button) the parent directory for the package. The package will be placed into the subdirectory of this parent directory. By default, when you activate this dialog, Parent Directory displays the directory selected in the project tree. If this directory is one of project subdirectories, then its path is displayed relatively to the project root directory.
- In this Parent Directory the IDE creates a new subdirectory with the name correspondent to the specified package name. The package will be placed into this subdirectory.
After you fill in all required settings for the package, you can press the Create button. Then the IDE creates the package subdirectory, the package header file NewPackage.ph, and the package implementation file NewPackage.pack. (They will appear in the project tree in the Project Window after the created package is compiled.)
Packages
The concept of packages is used for grouping together several linked interfaces and classes. Packages can play a role of some class library. Packages can be used in your program instead of direct placing all these interfaces and classes into your program.
The package is a collection of several grouped together interfaces and classes. The package provides some common name to all these interfaces and classes. Each declaration or implementation of each interface or class from a package is placed in a separate file. Each filename (of these files) coincides with the name of a class or an interface that is declared or implemented in this file. All package files are stored in the same separate package directory. (If a package contains sub-packages, then they are placed in subdirectories of the package directory.)
Except for files with declarations and implementations of interfaces and classes, each package contains two special files: the package header (.ph) and the package implementation (.pack) files.
- The package header file provides declarations of all names exported from the package. Therefore, the package header file should be inserted by the #include directive in each other package that uses some names exported from this package.
- The package implementation file provides code implementing the package classes which can be compiled into an object file. The package implementation file should be included only once into a project that uses this package.
So using the concept of packages we can create sets of linked interfaces and classes grouped into packages. Once created package can be included (and used) in several programs without copying package sources into each project. The example of such set of packages is our Visual Prolog Foundation Classes (PFC).
Package Header Files
The package header file provides external view of the package.
- It provides #include directives for all files containing declarations of all interfaces (.i fles) and all classes (.cl files) exported from the package (public interfaces and classes).
- It contains #include directives for package header (.ph files) files of all packages publicly used by the package. Since these package header files provide declarations of all public names declared in them; therefore, all public names declared in these packages are also publicly visible from the package.
- It contains some #requires directives. #requires directives define packages whose implementations (compiled code) have to A be accessible in order to use the package.
So the package header file provides declarations of all names exported from the package. Not only of exported names declared in the package itself, but also of all names declared in other packages that are included in the package header file.
A package header file should be inserted by #include directives in all places where the public names exported from the package should be visible.
A package header file does not produce any compiled code, but it is used while compilation to declare names exported from the package.
Usually a package header file has the PackageName.ph name.
Package Implementation Files
The package implementation file provides code implementing classes declared in the package. Compilation of the package implementation file generates object file that provides real implementations of classes declared in the package.
- It contains the #include directive for the package header file.
- It provides #include directives for package header files of external packages privately used by the package implementation. These header files provide declarations of all external names used in the package implementation (.pro) files.
- It provides #include directives for files containing interfaces (.i files) privately used by the package implementation. These interfaces are only used inside the package implementation and are not seen externally.
- It provides #include directives for files containing declarations of classes (.cl files) privately used by the package implementation. These classes are only used inside the package implementation and are not seen externally.
- It provides #include directives for all files with class implementations (.pro files) that provides Prolog code implementing all classes declared the package.
Usually a package implementation file has the PackageName.pack name.