// This may look like C code, but it is really -*- C++ -*-

/***********************************************************
Copyright 1991 by the Massachusetts Institute of Technology

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of M.I.T. not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission.  M.I.T. makes no representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.


Author: Roman J. Budzianowski - Project Athena MIT

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

#include "ObjectView.h"
#include "EurekaTypes.h"

#ifndef EurekaObject_h
#define EurekaObject_h

class ObjectEditor;

class SetupWorkspace {
 protected:
   static ObjectEditor* workspace;
   SetupWorkspace() { if(!workspace) XtError("Workspace not initialized"); }
 public:
   SetupWorkspace(ObjectEditor* w) {
      if(!workspace) workspace = w;
      else
	XtWarning("Workspace already initialized");
   }
};

class BaseObject;

class IO : public Data {
 protected:
   String name;
   String documentation;
   IO*      peer;		// XXX only in output ???
   BaseObject*  object;
   IO(String n, BaseObject* obj, DataType type, String d = "Undocumented") 
     : Data(type), name(n), documentation(d), peer(NULL), object(obj) {}
   
 public:
   virtual Boolean AcceptConnection(IO*) { XtWarning("Attempt to connect to input"); return False;}
   virtual Boolean Receive(Data*) { XtWarning("Attempt to Receive on Ouput"); return False;}
   virtual Boolean Send(Data*) { XtWarning("Attempt to Send on Input"); return False; }

   void Connect(IO* p) { peer = p; }
   String Name() { return name; }
   String Documentation() { return documentation; }
};

class ObjectInput : public IO {
 public:
   ObjectInput(String name, BaseObject* obj, DataType type, String doc = "Undocumented") 
     : IO(name,obj,type,doc) {}

   Boolean AcceptConnection(IO*);

   Boolean Receive(Data*);
};

class ObjectOutput : public IO {
 public:
   ObjectOutput(String name, BaseObject* obj, DataType type, String doc = "Undocumented") 
     : IO(name,obj,type,doc)  {}

   Boolean Send(Data*);
};


class BaseObject : public SetupWorkspace {
 private:
   ObjectView* view;
   String      name;
   String      class_name;
   String      documentation;
 public:
   virtual void SetupIO(ObjectView*) = 0;
   virtual void CreateWidget();
   virtual Boolean AcceptInput(IO*,Data*) 
     { XtWarning("Object has no input"); return False; }
 protected:
   BaseObject() {}
   BaseObject(String class_name, String name, String doc= "Undocumented")
     : class_name(class_name), name(name), documentation(doc) {}

 public:
   String ClassName() { return class_name; }
   String Name() { return name; }
   void   Name(String obj_name) { name = obj_name; } // ??? do we need it ?
   void print_object(ostream& o) { o << " " << class_name << ":" << name << " ";}
   virtual void print_all(ostream& o) { o << "Full print not implemented: "; print_object(o); }
};

#endif
