The easiest way to observe the source code is through an IDE such as Qt Creator. However, this appendix is provided as a navigational guide to the source code tree. In addition to the source code files listed in the tables below, the source tree also contains qmake project files, a few assorted configuration files, and a few baseline files for regression tests.
观察源代码的最简单方法是通过一个IDE,如Qt Creator。然而,本附录是作为源代码树的导航指南提供的。除了下面表格中列出的源代码文件外,源代码树还包含qmake项目文件,一些各种各样的配置文件,以及一些用于回归测试的基线文件。
The root level in the source code tree contains two directories, src and test, which contain the source code for pdCalc and the unit tests, respectively. Let’s look at these directories separately.
源代码树的根层包含两个目录,src和test,它们分别包含pdCalc的源代码和单元测试。让我们分别看一下这些目录。
B.1 The src Directory
The src directory subdivides into five directories: app, utilities, backend, ui, and plugins. The app directory is a folder for containing the pdCalc, pdCalc-simple-cli, and pdCalc-simple-gui directories. The ui directory is a folder for containing a cli directory and a gui directory. Each directory contains the files necessary for building the respective module defined by the directory’s name. Each module compiles into a distinct shared library encapsulating the module’s functionality. The exceptions are the three subdirectories of the app directory, which contain source code for compiling executables. Let’s now look at the files contained in each directory.
src目录又分为五个目录:app、utilities、backend、ui和plugins。app目录是一个包含pdCalc、pdCalc-simple-cli和pdCalc-simple-gui目录的文件夹。ui目录是一个包含cli目录和gui目录的文件夹。每个目录都包含了构建各自模块所需的文件,这些模块由目录的名称定义。每个模块都编译成一个独特的共享库,封装了该模块的功能。例外的情况是app目录下的三个子目录,它们包含用于编译可执行文件的源代码。现在让我们来看看每个目录中包含的文件。
B.1.1 The pdCalc Directory
The pdCalc directory contains the source code that compiles into the pdCalc executable. Notably, this directory contains the main() function located in main.cpp, which is the entry point into the application.
pdCalc目录包含编译成pdCalc可执行文件的源代码。值得注意的是,这个目录包含了位于main.cpp中的main()函数,它是 是应用程序的入口。
B.1.2 The pdCalc-simple-cli Directory
The pdCalc-simple-cli directory contains the source code that compiles into the simple CLI-only executable defined at the end of Chapter 5. This directory contains a single file, main.cpp.
pdCalc-simple-cli目录包含了源代码,它可以编译成第5章末尾定义的仅用于CLI的简单可执行文件。这个目录包含一个文件,main.cpp。
B.1.3 The pdCalc-simple-gui Directory
The pdCalc-simple-gui directory contains the source code that compiles into the simple GUI-only executable defined at the end of Chapter 6. This directory contains a single file, main.cpp.
pdCalc-simple-gui目录包含源代码,它可以编译成第6章末尾定义的仅有GUI的简单可执行文件。这个目录包含一个文件,main.cpp。
B.1.4 The utilities Directory
The utilities directory contains generic, reusable components, none of which are specifically associated with the calculator’s logic. Table B-1 lists the files contained in the utilities directory.
实用程序目录包含通用的、可重复使用的组件,其中没有一个是专门与计算器的逻辑相关的。这些组件与计算器的逻辑没有特别的联系。表B-1列出了包含在 实用程序目录中的文件。
Table B-1. Source Files in the utilities Directory
Header Files | Source Files |
---|---|
Exception.h | |
Observer.h | |
Observer.cpp | |
Publisher.h | |
Publisher.cpp | |
Tokenizer.h | |
Tokenizer.cpp | |
UserInterface.h | UserInterface.cpp |
B.1.5 The backend Directory
The backend directory contains all of the “business logic” for the calculator. From the model-view-controller perspective, this director contains the model and the controller. The backend directory also contains all of the logic for loading and managing plugins as well as the observer intermediary classes. Table B-2 lists the files contained in the backend directory.
后台目录包含计算器的所有“业务逻辑”。从模型-视图-控制器的角度来看,这个主管包含模型和控制器。后台目录还包含所有用于加载和管理插件的逻辑,以及观察者中间类。表B-2列出了后端目录中包含的文件。
Table B-2. Source Files in the backend Directory
Header Files | Source Files |
---|---|
AppObservers.h | |
AppObservers.cpp | |
Command.h | |
Command.cpp | |
CommandDispatcher.h | |
CommandDispatcher.cpp | |
CommandManager.h | |
CommandManager.cpp | |
CommandRepository.h | |
CommandRepository.cpp | |
CoreCommands.h | |
CoreCommands.cpp | |
DynamicLoader.h | |
DynamicLoader.cpp | |
PlatformFactory.h | |
PlatformFactory.cpp | |
Plugin.h | |
PluginLoader.h | |
PluginLoader.cpp | |
PosixDynamicLoader.h | |
PosixDynamicLoader.cpp | |
PosixFactory.h | |
PosixFactory.cpp | |
Stack.h | |
Stack.cpp | |
StackPluginInterface.h | |
StackPluginInterface.cpp | |
StoredProcedure.h | |
StoredProcedure.cpp | |
WindowsDynamicLoader.h | |
WindowsDynamicLoader.cpp | |
WindowsFactory.h | WindowsFactory.cpp |
B.1.6 The cli Directory
The cli directory contains the source code for the command line interface module. This module is one of the simplest modules in pdCalc and only contains two files, Cli.h and Cli.cpp.
cli目录包含命令行界面模块的源代码。这个模块是pdCalc中最简单的模块之一,只包含两个文件,Cli.h和Cli.cpp。
B.1.7 The gui Directory
The gui directory contains the source code for the graphical user interface. The files in this directory encompass the main GUI window, the GUI’s input and output classes, and the class governing the look-and-feel of the GUI. Table B-3 lists the source files found in the gui directory.
gui目录包含图形用户界面的源代码。这个目录中的文件包括主GUI窗口、GUI的输入和输出类以及管理GUI外观和感觉的类。表B-3列出了在gui目录中发现的源文件。
Table B-3. Source Files in the gui Directory
| Header Files | Source Files | | —- | —- | | CommandButton.h | CommandButton.cpp | | Display.h | Display.cpp | | GuiModel.h | GuiModel.cpp | | InputWidget.h | InputWidget.cpp | | LookAndFeel.h | LookAndFeel.cpp | | MainWindow.h | MainWindow.cpp | | StoredProcedureDialog.h | StoredProcedureDialog.cpp |
B.1.8 The plugins Directory
The plugins directory is a placeholder directory for the source code for plugins to pdCalc. It only includes one subdirectory, hyperbolicLnPlugin, which contains the source code for the hyperbolic functions and natural logarithm plugin developed in this book. The two source files in the hyperbolicPlugin directory are HyperbolicLnPlugin.h and HyperbolicLnPlugin.cpp. The source code implementing plugin loading and plugin management is all contained in the backend directory.
plugins目录是一个占位符目录,用于存放pdCalc的插件的源代码。它只包括一个子目录,即hyperbolicLnPlugin,它包含了本书所开发的双曲函数和自然对数插件的源代码。hyperbolicPlugin目录中的两个源文件是HyperbolicLnPlugin.h和HyperbolicLnPlugin.cpp。实现插件加载和插件管理的源代码全部包含在backend目录下。
B.2 The test Directory
The test directory is the home directory for all of the unit tests for pdCalc. This directory is simply a container for the following subdirectories, each of which tests the module corresponding to its name: testDriver, utilitiesTest, backendTest, cliTest, guiTest, pluginsTest. While I like to believe that I have been diligent in testing pdCalc thoroughly, I am certain of two things: I could have tested the code more, and bugs will be found after publication. I now detail the contents of each of the directories under test.
test目录是pdCalc所有单元测试的主目录。这个目录只是以下子目录的容器,每个子目录都测试与其名称相对应的模块:testDriver, utilitiesTest, backendTest, cliTest, guiTest, pluginsTest。虽然我愿意相信我在测试pdCalc方面已经很勤奋了,但我可以肯定两件事。我可以对代码进行更多的测试,而错误会在发布后被发现。我现在详细介绍一下每个被测试的目录的内容。
B.2.1 The testDriver Directory
The testDriver directory contains a single source file, main.cpp. This file sets up the Qt Test environment and registers all of the individual test modules. main.cpp compiles into the testPdCalc executable (testPdCale.exe in Windows), which is responsible for running all of the unit tests.
testDriver目录包含一个源文件main.cpp。这个文件设置了Qt测试环境,并注册了所有单独的测试模块。main.cpp编译成testPdCalc可执行文件(在Windows中为testPdCale.exe),它负责运行所有的单元测试。
B.2.2 The utilitiesTest Directory
The utilitiesTest directory contains the files necessary for testing the utilities module. The files contained in this directory are listed in Table B-4.
utilitiesTest目录包含测试实用程序模块所需的文件。表B-4中列出了该目录中包含的文件。
Table B-4. Source Files in the utilitiesTest Directory
| Header Files | Source Files | | —- | —- | | PublisherObserverTest.h | PublisherObserverTest.cpp | | TokenizerTest.h | TokenizerTest.cpp |
B.2.3 The backendTest Directory
The backendTest directory contains the source code for testing the backend module of pdCalc. The files contained in this directory can be found in Table B-5. In addition to the source code files, the directory also contains a hypotenuse file containing a test stored procedure and the files plugins.unix.pdp and plugins.unix.win, which are plugin loader files for the two respective operating systems.
backendTest目录包含测试pdCalc后台模块的源代码。这个目录中包含的文件可以在表B-5中找到。除了源代码文件,该目录还包含一个包含测试存储过程的hypotenuse文件,以及文件plugins.unix.pdp和plugins.unix.win,这两个文件是各自操作系统的插件加载器文件。
Table B-5. Source Files in the backendTest Directory
| Header Files | Source Files | | —- | —- | | CommandDispatcherTest.h | CommandDispatcherTest.cpp | | CommandManagerTest.h | CommandManagerTest.cpp | | CommandRepositoryTest.h | CommandRepositoryTest.cpp | | CoreCommandsTest.h | CoreCommandsTest.cpp | | PluginLoaderTest.h | PluginLoaderTest.cpp | | StackTest.h | StackTest.cpp | | StoredProcedureTest.h | StoredProcedureTest.cpp |
B.2.4 The cliTest Directory
The cliTest directory contains the source code files necessary for testing the command line interface. The two source files in this directory are CliTest.h and CliTest.cpp. In addition to the source files, the cliTest directory contains a subdirectory, testCases. The testCases directory contains input files and output baselines used in testing the command line interface.
cliTest目录包含测试命令行界面所需的源代码文件。这个目录中的两个源文件是CliTest.h和CliTest.cpp。除了源文件之外,cliTest目录还包含一个子目录testCases。testCases目录包含用于测试命令行界面的输入文件和输出基线。
B.2.5 The guiTest Directory
It is difficult, in general, to test graphical user interfaces automatically. Only the Display class within the GUI is automatically tested in pdCalc’s unit tests. The two source files for testing the Display class, DisplayTest.h and DisplayTest.cpp, are found in the guiTest directory.
一般来说,要自动测试图形用户界面是很困难的。在pdCalc的单元测试中,只有图形用户界面中的Display类被自动测试。测试Display类的两个源文件,DisplayTest.h和DisplayTest.cpp,可以在guiTest目录中找到。
B.2.6 The pluginsTest Directory
The pluginsTest directory contains the source files for testing the single plugin included with pdCalc, the hyperbolic functions and natural logarithm plugin. These tests are contained in the following two source files: HyperbolicLnPluginTest.h and HyperbolicLnPluginTest.cpp.
pluginsTest目录包含测试pdCalc所包含的单一插件的源文件,即双曲函数和自然对数插件。这些测试包含在以下两个源文件中。HyperbolicLnPluginTest.h 和 HyperbolicLnPluginTest.cpp。