123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- // { 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;
- }
|