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