user1291606
user1291606

Reputation: 37

Counting classes in C++ file

I wanted to know if there is a software or some way I could count the number of classes used in a C++ written program.

I am doing a project, and that project requires me to investigate in a open source program and count the number of classes.

Thanks in advance

Upvotes: 0

Views: 1075

Answers (2)

Vivian De Smedt
Vivian De Smedt

Reputation: 1029

The following Python script will give an indication. Run it in the root of your source tree and it will give you the number of classes defined in the source tree.

import os
import re

def main():
    classes = set()
    
    for root, folders, files in os.walk("."):
        for file in files:
            name, ext = os.path.splitext(file)
         
            if ext.lower() not in [".h", ".hpp", ".hxx"]:
                continue
                
            f = open(os.path.join(root, file))
            for l in f:
                m = re.match(r"class ([a-zA-Z0-9]*)[^;]*$", l)
                if not m:
                    continue
                    
                classes.add(m.groups())
                
            f.close()
                
    print len(classes)
        
if __name__ == "__main__":
    main()

Upvotes: 1

Tomas Andrle
Tomas Andrle

Reputation: 13354

If you use Xcode, you can open the Symbol navigator with Cmd-2 and it will show you the number of classes, functions and other elements in your project.

Upvotes: 1

Related Questions