12

ソース ファイル ペインは (プロジェクト内のファイル数の点で) 急速に大きくなり、いつでもアクセスする必要がある特定のソース ファイルをすばやく見つけるのが少し面倒になっています。Embarcadero の C++Builder を使用していますが、他の C++ IDE でもこの問題に遭遇しました。

Java では、特に 1 つのプロジェクトで多数のソース ファイルを扱う場合に、ソース コードを論理的に分割するためにパッケージをよく利用します。もちろん、これが Java パッケージの唯一の目的ではありませんが、この点で非常に便利です。

C ++で同様の機能を実現する方法について誰かアイデアがありますか? ソースを物理フォルダーに分ける必要がありますか? C++Builder は、私が見ていない仮想フォルダ/グループ化機能を提供していますか? どんなアイデアでも大歓迎です。

4

3 に答える 3

13

私は通常、ソース コードを整理するために IDE や言語構文を使用しない(のみ) ことをお勧めします。1 つは、自分自身を環境に縛り付けることです。IDE で適切に整理され、ファイルが整理されていない場合、別の環境を使用したくなる日が来ます...

このため、私は通常、ソースを整理する 3 つの方法をすべて同時に使用します。ソースを機能モジュール、つまり関連するクラスに分割します。各モジュールは、独自の名前空間、物理フォルダー、および IDE フォルダーを取得します。(私の場合、CMakeを使用しsource_group()、必要に応じて IDE プロジェクト ファイルを生成します。個人的には、コマンド ライン、Vim、および「make」を好みます。)

したがって、プロジェクトを IDE 内、コマンド ライン、またはコンパイラ ログのいずれから見ても、foo/some_class.hpp は foo/some_class.cpp は foo::some_class であり、混乱を最小限に抑えます。

実際、私の現在の好みの設定では、クラスが独自のモジュールの外部で使用されているかどうかに応じて、<project>/<module>/<class>.hpp各モジュール ディレクトリをさらに 、 、およびに細分化しています。もちろん、名前空間はです。<project>/<module>/src/<class>.hpp<project>/<module>/src/<class>.cpp<project>/<module>/test/<class>_tu.cpp<project>::<module>::<class>

project
|-- foo
|   |-- some_class.hpp
|   |-- src
|   |   |-- internal_class.hpp
|   |   |-- internal_class.cpp
|   |   `-- some_class.cpp
|   `-- test
|       |-- internal_class_tu.cpp
|       `-- some_class_tu.cpp
|-- bar
|   |-- ...

ここでの考え方は、各モジュールの「外部」インターフェース ( foo) がそのサブフォルダーのヘッダーによって文書化され、実装の詳細とテストがそれぞれのサブフォルダーに「隠されている」ということです。

しかし、最終的には、あなたの好み、共同開発者の好み、およびプロジェクトの範囲に大きく依存します。

于 2013-04-22T16:04:18.380 に答える
12

これが私が転がる方法です:

PROJECT_NAME
|-- build // This is DVCS ignored but has all the built intermediates and final binaries
|   |-- release // These are the different build profiles
|   |-- debug
|   |-- profile
|   `-- coverage
|-- bin // For binary source code
|   `-- hello_world
|       |-- doc
|       |-- inc
|       |-- src
|       |-- tests
|       `-- build_script  // Builds binary into the build folder
|-- include // Public headers for the library
|   `-- these
|       `-- folders
|           `-- represent
|               `-- namespaces
|                   `-- my_awesome_class.hpp
|-- lib // library source code
|   |-- these
|   |   `-- folders
|   |       `-- represent
|   |           `-- namespaces
|   |               |-- inc // Private headers
|   |               |   `-- my_private_class.hpp // internal class
|   |               |-- src // Source code for this namespace
|   |               |   |-- posix
|   |               |   |   `-- my_awesome_class.cpp // posix specific source code
|   |               |   |-- nt
|   |               |   |   `-- my_awesome_class.cpp // nt specific source code
|   |               |   |-- my_private_class.cpp // non-visibile class
|   |               |   `-- my_awesome_class.cpp // cross platform source code
|   |               |-- tests // Unit tests
|   |               |   `-- my_awesome_class.cpp // builds a test executable for the library
|   |               `-- doc // Documentation for this namespace
|   |                   `-- namespace.dox
|   `-- build_script  // Builds binary into the build folder
|-- doc // Documentation files
|   |-- main_page.dox
|   `-- namespace.dox
`-- build_script  // Builds the source code into the build folder

これは、特定のソース コード (および一般的なソース コード)these::folders::represent::namespaces::MyAwesomeClassを持つクラスを表し、ライブラリ内で内部的に使用されるプライベートがあり、ヘッダーはパブリックではなく、クラス シンボルの可視性は隠されています。posixNTthese::folders::represent::namespaces::MyPrivateClass

これは非常にうまくスケーリングされており、ファイルを簡単に見つけることができます。

于 2013-04-22T16:25:47.150 に答える