docs: Update example to conform to coding standards.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sean Silva 2012-10-12 01:55:51 +00:00
parent af21d6f23c
commit 6df933e371

View File

@ -77,8 +77,8 @@ steps:
public: public:
+ /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) + /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
+ enum ShapeKind { + enum ShapeKind {
+ SquareKind, + SK_Square,
+ CircleKind + SK_Circle
+ }; + };
+private: +private:
+ const ShapeKind Kind; + const ShapeKind Kind;
@ -121,8 +121,8 @@ steps:
public: public:
/// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
enum ShapeKind { enum ShapeKind {
SquareKind, SK_Square,
CircleKind SK_Circle
}; };
private: private:
const ShapeKind Kind; const ShapeKind Kind;
@ -138,7 +138,7 @@ steps:
double SideLength; double SideLength;
public: public:
- Square(double S) : SideLength(S) {} - Square(double S) : SideLength(S) {}
+ Square(double S) : Shape(SquareKind), SideLength(S) {} + Square(double S) : Shape(SK_Square), SideLength(S) {}
double computeArea() /* override */; double computeArea() /* override */;
}; };
@ -146,7 +146,7 @@ steps:
double Radius; double Radius;
public: public:
- Circle(double R) : Radius(R) {} - Circle(double R) : Radius(R) {}
+ Circle(double R) : Shape(CircleKind), Radius(R) {} + Circle(double R) : Shape(SK_Circle), Radius(R) {}
double computeArea() /* override */; double computeArea() /* override */;
}; };
@ -163,8 +163,8 @@ steps:
public: public:
/// Discriminator for LLVM-style RTTI (dyn_cast<> et al.) /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
enum ShapeKind { enum ShapeKind {
SquareKind, SK_Square,
CircleKind SK_Circle
}; };
private: private:
const ShapeKind Kind; const ShapeKind Kind;
@ -178,22 +178,22 @@ steps:
class Square : public Shape { class Square : public Shape {
double SideLength; double SideLength;
public: public:
Square(double S) : Shape(SquareKind), SideLength(S) {} Square(double S) : Shape(SK_Square), SideLength(S) {}
double computeArea() /* override */; double computeArea() /* override */;
+ +
+ static bool classof(const Shape *S) { + static bool classof(const Shape *S) {
+ return S->getKind() == SquareKind; + return S->getKind() == SK_Square;
+ } + }
}; };
class Circle : public Shape { class Circle : public Shape {
double Radius; double Radius;
public: public:
Circle(double R) : Shape(CircleKind), Radius(R) {} Circle(double R) : Shape(SK_Circle), Radius(R) {}
double computeArea() /* override */; double computeArea() /* override */;
+ +
+ static bool classof(const Shape *S) { + static bool classof(const Shape *S) {
+ return S->getKind() == CircleKind; + return S->getKind() == SK_Circle;
+ } + }
}; };
@ -264,10 +264,10 @@ from ``Square``, and so ``ShapeKind`` becomes:
.. code-block:: c++ .. code-block:: c++
enum ShapeKind { enum ShapeKind {
SquareKind, SK_Square,
+ SpecialSquareKind, + SK_SpecialSquare,
+ OtherSpecialSquareKind, + SK_OtherSpecialSquare,
CircleKind SK_Circle
} }
Then in ``Square``, we would need to modify the ``classof`` like so: Then in ``Square``, we would need to modify the ``classof`` like so:
@ -275,11 +275,11 @@ Then in ``Square``, we would need to modify the ``classof`` like so:
.. code-block:: c++ .. code-block:: c++
- static bool classof(const Shape *S) { - static bool classof(const Shape *S) {
- return S->getKind() == SquareKind; - return S->getKind() == SK_Square;
- } - }
+ static bool classof(const Shape *S) { + static bool classof(const Shape *S) {
+ return S->getKind() >= SquareKind && + return S->getKind() >= SK_Square &&
+ S->getKind() <= OtherSpecialSquareKind; + S->getKind() <= SK_OtherSpecialSquare;
+ } + }
The reason that we need to test a range like this instead of just equality The reason that we need to test a range like this instead of just equality