/***********************************************************************

  Copyright by Telelogic AB 1998

  This Program is owned by Telelogic and is protected by national
  copyright laws and international copyright treaties. Telelogic grants
  you the right to use this Program on one computer or in one local
  computer network at any one time.

  Under this License you may only modify the source code for the purpose
  of adapting it to your environment. You must reproduce and include any
  copyright and trademark notices on all copies of the source code.  You
  may not use, copy, merge, modify or transfer the Program except as
  provided in this License.

  Telelogic does not warrant that the Program will meet your
  requirements or that the operation of the Program will be
  uninterrupted and error free. You are solely responsible that the
  selection of the Program and the modification of the source code will
  achieve your intended results and that the results are actually
  obtained.

************************************************************************/


#ifndef _omaccess_h
#define _omaccess_h

#include "pmtool.h"
#include "stlmini.h"

// include the class-structure
#include "uml.h"


// Compatibilty defines
#define OMINFOVERSION33 1
#define OMINFOVERSION34 2

#define OMINFOVERSION   OMINFOVERSION34  // Version matching API in this file



struct OMModule {
  Class &AddClass (const string &className) 
    {
      list<Class>::iterator i = FindClass (className);
      if (i != classList.end())
        return *i;
      Class tmpClass;
      tmpClass.name=className;
      classList.push_back (tmpClass);
      return classList.back();
    }

  list<Class>::iterator FindClass (const string &className) 
    {
      for (list<Class>::iterator i = classList.begin();
           i != classList.end();
           i++)
        if ((*i).name == className)
          return i;
      return classList.end();
    }

  string name;
  list<Class> classList;
  list<Generalization> generalizationList;
  list<AssociationClass> associationList;
};


////////////////////////////////////////////////////////////
//  Utilities

bool GetFile(const string &filename, OMModule *omModule, string *status=NULL);
bool GetBufID(const string &bufid, OMModule *omModule, string *status=NULL);

void GetSuperClassList (const OMModule &omModule,
                        const string &classstring,
                        list<string> *superClasses);

void GetSubClassList (const OMModule &omModule,
                      const string &classstring,
                      list<string> *subClasses);

string SourceAggregationEnd(const AssociationClass &association);
string TargetAggregationEnd(const AssociationClass &association);

void GetEndPoints(const AssociationClass &association, list<string> *classes);
bool hasEndPoint(const AssociationClass &association, const string &string);

void GetAggregations(const OMModule &omModule,
                     list<AssociationClass> *aggregations);
void GetAggregations(const OMModule &omModule,
                     list<AssociationClass> *aggregations,
                     const string &owner);

void GetAssociations(const OMModule &omModule,
                     list<AssociationClass> *associations);
void GetAssociations(const OMModule &omModule,
                     list<AssociationClass> *associations,
                     const string &firstEnd);
void GetAssociations(const OMModule &omModule,
                     list<AssociationClass> *associations,
                     const string &firstEnd, const string &secondEnd);

void TraceModule (const OMModule &omModule,
                  ostream &os=cout);

////////////////////////////////////////////////////////////
// Misc.

void PackOMModule(const OMModule &omModule,
                  int version,
                  MessagePacker &packer);

////////////////////////////////////////////////////////////
// OM InfoServer Tool

class OMAccessTool : public PMTool {
public:
  OMAccessTool () : PMTool(SET_OMINFOSERVER, "OM Access") {}

  bool RPCGetObjects (const string &module, OMModule *);
  static bool RPCGetObjectsReply (int pid, const OMModule &omModule);
};

#endif // _omaccess_h

