Dev Notes

Software Development Resources by David Egan.

Find Custom Data Types in a C++ Project


C++
David Egan

If your looking through an existing C++ project, it is likely that you will come across custom data types.

For example, if you see the following:

...
std::pair<Blob, bool> strUnHex (std::string const& strSrc){...}

…you just know that Blob is an object of some sort. The first_type in the std::pair could be:

  • A class-defined object
  • A struct defined object
  • A type alias

Searching a Project

Use grep:

cd myProject

grep -nr "search term" .

Search Project for Custom Type

If you want to determine information about a custom data type, finding where it is defined/aliased is a good idea:

grep for the specified options in the current directory:
grep -nr "using Blob\|class Blob\|struct Blob" .

# Output:
./src/path/Blob.h:30:using Blob = std::vector <unsigned char>;

At this point, you don’t even need to open Blob.h to know that Blob is an alias for std::vector<unsigned char>.

You could also try grepping for typedef statements:

# grep for the term "typedef<any number of any characters>Blob" recursively starting in the current directory: 
grep -nr "typedef.*Blob" .

References


comments powered by Disqus