home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yeah09.zip / samples / unknown / unknown.cpp < prev   
Text File  |  1996-05-25  |  2KB  |  87 lines

  1. //------------------------------------------------------------
  2. //
  3. // Name:     unknown.cpp
  4. // Version:  0.9
  5. // Author:   Björn Fahller.
  6. //
  7. // Copyright (C) Björn Fahller, 1996.
  8. //
  9. // Purpose:  Show how to read an extended attribute of unknown
  10. //           type and name. If an extended attribute of a type
  11. //           that is not defined in YEAH, or not allowed dynamic,
  12. //           an exception EATypeMismatchError is thrown with the
  13. //           type identifier of the found EA as the error code.
  14. //
  15. // History:
  16. //          Ver.  Date         What
  17. //          0.9   1996-05-26   First official release.
  18. //
  19. //------------------------------------------------------------
  20.  
  21. #include <YEA.H>
  22. #include <iostream.h>
  23.  
  24.  
  25.  
  26. void print(EA* pea)
  27. {
  28.   StringEA* psea = StringEA::cast(pea);
  29.   if (psea)
  30.   {
  31.     cout << "String = \"" << *psea << "\"" << endl;
  32.   }
  33.   MTSequenceEA* pmtsea = MTSequenceEA::cast(pea);
  34.   if (pmtsea)
  35.   {
  36.     cout << "MTSequenceEA" << endl;
  37.     MTSequenceEA::Cursor c(*pmtsea);
  38.     forCursor(c)
  39.     {
  40.       EA* pea = pmtsea->elementAt(c);
  41.       print(pea);
  42.     }
  43.   }
  44.   TSequenceEA<StringEA>* ptssea = TSequenceEA<StringEA>::cast(pea);
  45.   if (ptssea)
  46.   {
  47.     cout << "TSequenceEA<StringEA>" << endl;
  48.     TSequenceEA<StringEA>::Cursor c(*ptssea);
  49.     forCursor(c)
  50.     {
  51.       cout << *(ptssea->elementAt(c)) << endl;
  52.     }
  53.   }
  54. }
  55.  
  56. int main(int argc, char* argv[])
  57. {
  58.   try {
  59.     if (argc != 3)
  60.     {
  61.       cerr << "Usage: " << argv[0] << ": filename eaname" << endl;
  62.       return -1;
  63.     }
  64.  
  65.     StringEA::allowDynamic();
  66.     MTSequenceEA::allowDynamic();
  67.     TSequenceEA<StringEA>::allowDynamic();
  68.  
  69.     EA* pea = EA::newFrom(argv[1],argv[2]);
  70.     print(pea);
  71.     delete pea;
  72.   }
  73.   catch (EAError& e)
  74.   {
  75.     cerr << "Oops, something was wrong here..." << endl;
  76.     cerr << e.name() << endl;
  77.     for (unsigned i=0; i < e.textCount(); ++i)
  78.     {
  79.       cerr << e.text(i) << endl;
  80.     }
  81.  
  82.     cerr << endl << "Error code = " << e.errorId()
  83.          << " (" << hex << e.errorId() << ')' << endl;
  84.   }
  85. }
  86.  
  87.