llvm.org GIT mirror llvm / 6df933e
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 Sean Silva 6 years ago
1 changed file(s) with 19 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
7676 public:
7777 + /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
7878 + enum ShapeKind {
79 + SquareKind,
80 + CircleKind
79 + SK_Square,
80 + SK_Circle
8181 + };
8282 +private:
8383 + const ShapeKind Kind;
120120 public:
121121 /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
122122 enum ShapeKind {
123 SquareKind,
124 CircleKind
123 SK_Square,
124 SK_Circle
125125 };
126126 private:
127127 const ShapeKind Kind;
137137 double SideLength;
138138 public:
139139 - Square(double S) : SideLength(S) {}
140 + Square(double S) : Shape(SquareKind), SideLength(S) {}
140 + Square(double S) : Shape(SK_Square), SideLength(S) {}
141141 double computeArea() /* override */;
142142 };
143143
145145 double Radius;
146146 public:
147147 - Circle(double R) : Radius(R) {}
148 + Circle(double R) : Shape(CircleKind), Radius(R) {}
148 + Circle(double R) : Shape(SK_Circle), Radius(R) {}
149149 double computeArea() /* override */;
150150 };
151151
162162 public:
163163 /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
164164 enum ShapeKind {
165 SquareKind,
166 CircleKind
165 SK_Square,
166 SK_Circle
167167 };
168168 private:
169169 const ShapeKind Kind;
177177 class Square : public Shape {
178178 double SideLength;
179179 public:
180 Square(double S) : Shape(SquareKind), SideLength(S) {}
180 Square(double S) : Shape(SK_Square), SideLength(S) {}
181181 double computeArea() /* override */;
182182 +
183183 + static bool classof(const Shape *S) {
184 + return S->getKind() == SquareKind;
184 + return S->getKind() == SK_Square;
185185 + }
186186 };
187187
188188 class Circle : public Shape {
189189 double Radius;
190190 public:
191 Circle(double R) : Shape(CircleKind), Radius(R) {}
191 Circle(double R) : Shape(SK_Circle), Radius(R) {}
192192 double computeArea() /* override */;
193193 +
194194 + static bool classof(const Shape *S) {
195 + return S->getKind() == CircleKind;
195 + return S->getKind() == SK_Circle;
196196 + }
197197 };
198198
263263 .. code-block:: c++
264264
265265 enum ShapeKind {
266 SquareKind,
267 + SpecialSquareKind,
268 + OtherSpecialSquareKind,
269 CircleKind
266 SK_Square,
267 + SK_SpecialSquare,
268 + SK_OtherSpecialSquare,
269 SK_Circle
270270 }
271271
272272 Then in ``Square``, we would need to modify the ``classof`` like so:
274274 .. code-block:: c++
275275
276276 - static bool classof(const Shape *S) {
277 - return S->getKind() == SquareKind;
277 - return S->getKind() == SK_Square;
278278 - }
279279 + static bool classof(const Shape *S) {
280 + return S->getKind() >= SquareKind &&
281 + S->getKind() <= OtherSpecialSquareKind;
280 + return S->getKind() >= SK_Square &&
281 + S->getKind() <= SK_OtherSpecialSquare;
282282 + }
283283
284284 The reason that we need to test a range like this instead of just equality