scitools.com

← Metric catalog

Classes is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Classes

API ID: CountDeclClass
Languages: Basic, C#, C++, Java, Pascal, Python, Web
Targets: Architectures, Files, Project

Number of classes.

Exactly what qualifies as a class for this count depends on the language and, for C++, the parse mode.

For example:

// class_macro.h
#define DECLARE_TAG_CLASS(ClassName) \
  class ClassName { \
  public: \
    int tag = 0; \
  };

// classes.cpp
#include "class_macro.h"

struct Point {
  int x;
  int y;
};

union Value {
  int asInt;
  float asFloat;
};

class Shape {
public:
  virtual double area() const = 0;
};

enum class Color { Red, Green, Blue };

DECLARE_TAG_CLASS(MacroClass)

In C/C++, classes, structs, and unions all contribute to the count, but enums do not. So classes.cpp above has CountDeclClass = 4: the struct Point, the union Value, the class Shape, and the class MacroClass generated by the DECLARE_TAG_CLASS macro (the preprocessor expands it into a real class declaration before the parser ever sees it). The scoped enum Color doesn't count.

Note that C++'s fuzzy parsing mode doesn't support enum class syntax, so it mistakes Color for a class and reports CountDeclClass = 5 for the same file — one too many.

See Functions for the equivalent count of function declarations.

Targets By Language: Configuration: