1// { dg-do run } 2 3#include <stdio.h> 4#include <stdlib.h> 5 6class XMemory 7{ 8public: 9 void * operator new (size_t size); 10 void operator delete (void *p); 11 12protected: 13 XMemory () {} 14 15 virtual ~XMemory() {} 16}; 17 18class XSerializable 19{ 20public: 21 virtual ~XSerializable () {}; 22 23 virtual bool isSerializable() const = 0; 24 virtual void serialize () = 0; 25 26protected: 27 XSerializable() {}; 28 29}; 30 31class Grammar: public XSerializable, public XMemory 32{ 33public: 34 enum GrammarType { 35 DTDGrammarType, 36 SchemaGrammarType, 37 OtherGrammarType, 38 Unknown 39 }; 40 41 virtual ~Grammar() {} 42 43 virtual GrammarType getGrammarType() const = 0; 44 virtual bool getValidated() const = 0; 45 46 virtual bool isSerializable() const; 47 virtual void serialize (); 48 49protected: 50 Grammar() {}; 51 52}; 53 54class SchemaGrammar : public Grammar 55{ 56public: 57 58 SchemaGrammar () : Grammar(), elemID(10) { fValidated = true; } 59 60 virtual ~SchemaGrammar() {} 61 62 virtual Grammar::GrammarType getGrammarType() const; 63 virtual bool getValidated() const; 64 65 virtual bool isSerializable () const; 66 virtual void serialize (); 67 68private: 69 const unsigned int elemID; 70 bool fValidated; 71 72}; 73 74class OtherGrammar : public Grammar 75{ 76public: 77 78 OtherGrammar () : Grammar(), elemID(10) { fValidated = true; } 79 80 virtual ~OtherGrammar() {} 81 82 virtual Grammar::GrammarType getGrammarType() const; 83 virtual bool getValidated() const; 84 85 virtual bool isSerializable () const; 86 virtual void serialize (); 87 88private: 89 const unsigned int elemID; 90 bool fValidated; 91 92}; 93 94void 95Grammar::serialize () 96{ 97 printf ("in Grammar::serialize\n"); 98} 99 100bool 101Grammar::isSerializable () const 102{ 103 return true; 104} 105 106bool 107SchemaGrammar::isSerializable () const 108{ 109 return true; 110} 111 112void 113SchemaGrammar::serialize () 114{ 115 printf ("in SchemaGrammar::serialize\n"); 116} 117 118Grammar::GrammarType 119SchemaGrammar::getGrammarType() const { 120 return Grammar::SchemaGrammarType; 121} 122 123bool 124SchemaGrammar::getValidated () const 125{ 126 return fValidated; 127} 128 129void * 130XMemory::operator new (size_t size) 131{ 132 return malloc (size); 133} 134 135void 136XMemory::operator delete (void *p) 137{ 138} 139 140bool 141OtherGrammar::isSerializable () const 142{ 143 return false; 144} 145 146void 147OtherGrammar::serialize () 148{ 149 printf ("in OtherGrammar::serialize\n"); 150} 151 152Grammar::GrammarType 153OtherGrammar::getGrammarType() const { 154 return Grammar::OtherGrammarType; 155} 156 157bool 158OtherGrammar::getValidated () const 159{ 160 return fValidated; 161} 162 163int 164main (int argc, char **argv) 165{ 166 SchemaGrammar sPtr; 167 OtherGrammar oPtr; 168 Grammar &sGrammar = sPtr; 169 170 for (int i = 0; i < 2; ++i) 171 { 172 if (i == 0) 173 sGrammar = oPtr; 174 else 175 sGrammar = sPtr; 176 177 if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType || 178 sGrammar.getValidated ()) 179 printf ("if condition was true.\n"); 180 else 181 printf ("if condition was false.\n"); 182 } 183 184 return 0; 185} 186