Logo Search packages:      
Sourcecode: afnix version File versions

Object * afnix::Sheet::apply ( Runnable robj,
Nameset nset,
const long  quark,
Vector argv 
) [virtual]

apply this object with a set of arguments and a quark

Parameters:
robj the current runnable
nset the current nameset
quark the quark to apply these arguments
argv the arguments to apply

Reimplemented from afnix::Persist.

Definition at line 1156 of file Sheet.cpp.

References adddata(), addfoot(), addhead(), addmark(), addsign(), addtag(), afnix::Persist::apply(), convert(), findmark(), findsign(), findtag(), afnix::Vector::get(), afnix::Vector::getbool(), getcols(), getfoot(), gethead(), getinfo(), afnix::Vector::getint(), getmark(), getname(), getsign(), afnix::Vector::getstring(), gettag(), ismark(), issign(), istag(), length(), afnix::Vector::length(), lkcol(), map(), mapfoot(), maphead(), marklen(), afnix::Runnable::post(), afnix::Object::rdlock(), afnix::Object::repr(), reset(), setfoot(), sethead(), setinfo(), setmark(), setname(), setsign(), settag(), signlen(), sort(), tagslen(), afnix::Boolean::toboolean(), afnix::Integer::tointeger(), afnix::Literal::tostring(), and afnix::Object::unlock().

                                {
    // check for generic quark
    if (quark == QUARK_ADDDATA) {
      adddata (argv);
      return nilp;
    }
    if (quark == QUARK_ADDTAG) {
      addtag (argv);
      return nilp;
    }
    if (quark == QUARK_ADDMARK) {
      addmark (argv);
      return nilp;
    }
    if (quark == QUARK_ADDSIGN) {
      addsign (argv);
      return nilp;
    }
    if (quark == QUARK_ADDHEAD) {
      addhead (argv);
      return nilp;
    }
    if (quark == QUARK_ADDFOOT) {
      addfoot (argv);
      return nilp;
    }

    // get the number of arguments
    long argc = (argv == nilp) ? 0 : argv->length ();

    // dispatch 0 argument
    if (argc == 0) {
      if (quark == QUARK_LENGTH ) return new Integer (length  ());
      if (quark == QUARK_COLLEN ) return new Integer (getcols ());
      if (quark == QUARK_TAGLEN ) return new Integer (tagslen ());
      if (quark == QUARK_MARKLEN) return new Integer (marklen ());
      if (quark == QUARK_SIGNLEN) return new Integer (signlen ());
      if (quark == QUARK_GETNAME) return new String  (getname ());
      if (quark == QUARK_GETINFO) return new String  (getinfo ());
      if (quark == QUARK_CONVERT) return convert (0, 0, true);
      if (quark == QUARK_RESET) {
      reset ();
      return nilp;
      }
      if (quark == QUARK_SORT) {
      sort (0, true);
      return nilp;
      }
    }

    // dispatch 1 argument
    if (argc == 1) {
      if (quark == QUARK_SETNAME) {
      String name = argv->getstring (0);
      setname (name);
      return nilp;
      }
      if (quark == QUARK_SETINFO) {
      String info = argv->getstring (0);
      setinfo (info);
      return nilp;
      }
      if (quark == QUARK_ISTAGP) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with tag-p",
                     Object::repr (obj));
      }       
      String tag = lobj->tostring ();
      return new Boolean (istag (tag));
      }
      if (quark == QUARK_GETTAG) {
      long index = argv->getint (0);
      return new String (gettag (index));
      }
      if (quark == QUARK_ISMARKP) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with marker-p",
                     Object::repr (obj));
      }       
      String mark = lobj->tostring ();
      return new Boolean (ismark (mark));
      }
      if (quark == QUARK_ISSIGNP) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with sign-p",
                     Object::repr (obj));
      }       
      String sign = lobj->tostring ();
      return new Boolean (issign (sign));
      }
      if (quark == QUARK_GETMARK) {
      long index = argv->getint (0);
      return new String (getmark (index));
      }
      if (quark == QUARK_GETSIGN) {
      long index = argv->getint (0);
      return new String (getsign (index));
      }
      if (quark == QUARK_FINDTAG) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with find-tag",
                     Object::repr (obj));
      }       
      String tag = lobj->tostring ();
      return new Integer (findtag (tag));
      }
      if (quark == QUARK_FINDMRK) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with find-marker",
                     Object::repr (obj));
      }       
      String mark = lobj->tostring ();
      return new Integer (findmark (mark));
      }
      if (quark == QUARK_FINDSGN) {
      Object*   obj = argv->get (0);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if (lobj == nilp) {
        throw Exception ("type-error", "non literal object with find-sign",
                     Object::repr (obj));
      }       
      String sign = lobj->tostring ();
      return new Integer (findsign (sign));
      }
      if (quark == QUARK_GET) {
      long idx = argv->getint (0);
      rdlock ();
      try {
        Object* result = get (idx);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_ADD) {
      Object* obj = argv->get (0);
      Record* rcd = dynamic_cast <Record*> (obj);
      if (rcd != nilp) {
        add (rcd);
        return nilp;
      }
      throw Exception ("type-error", "invalid object to add in sheet",
                   Object::repr (obj));
      }
      if (quark == QUARK_GETHEAD) {
      long index = argv->getint (0);
      rdlock ();
      try {
        Object* result = gethead (index);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_MAPHEAD) {
      long index = argv->getint (0);
      rdlock ();
      try {
        Object* result = maphead (index);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_GETFOOT) {
      long index = argv->getint (0);
      rdlock ();
      try {
        Object* result = getfoot (index);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_MAPFOOT) {
      long index = argv->getint (0);
      rdlock ();
      try {
        Object* result = mapfoot (index);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_IMPORT) {
      Object* obj = argv->get (0);
      Input*   is = dynamic_cast <Input*> (obj);
      if (is != nilp) {
        import (is);
        return nilp;
      }
      throw Exception ("type-error", "invalid object for sheet importation",
                   Object::repr (obj));
      }
      if (quark == QUARK_CONVERT) {
      long max = argv->getint (0);
      return convert (max, 0, true);
      }
      if (quark == QUARK_SORT) {
      Object* obj = argv->get (0);
      // check for integer
      Integer* col = dynamic_cast <Integer*> (obj);
      if (col != nilp) {
        sort (col->tointeger (), true);
        return nilp;
      }
      // check for boolean
      Boolean* mode = dynamic_cast <Boolean*> (obj);
      if (mode != nilp) {
        sort (0, mode->toboolean ());
        return nilp;
      }
      // invalid arguments
      throw Exception ("type-error", "invalid object for sorting ",
                   Object::repr (obj));
      }
    }

    // dispatch 2 argument
    if (argc == 2) {
      if (quark == QUARK_SETTAG) {
      long     idx  = argv->getint (0);
      Object*  obj  = argv->get (1);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if ((obj != nilp) && (lobj == nilp)) 
        throw Exception ("type-error", "invalid object to set in tags",
                     Object::repr (obj));
      settag (idx, lobj);
      return nilp;
      }
      if (quark == QUARK_SETMARK) {
      long     idx  = argv->getint (0);
      Object*  obj  = argv->get (1);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if ((obj != nilp) && (lobj == nilp)) 
        throw Exception ("type-error", "invalid object to set in marker",
                     Object::repr (obj));
      setmark (idx, lobj);
      return nilp;
      }
      if (quark == QUARK_SETSIGN) {
      long     idx  = argv->getint (0);
      Object*  obj  = argv->get (1);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if ((obj != nilp) && (lobj == nilp)) 
        throw Exception ("type-error", "invalid object to set in signature",
                     Object::repr (obj));
      setsign (idx, lobj);
      return nilp;
      }
      if (quark == QUARK_SETHEAD) {
      long    idx = argv->getint (0);
      Object*  obj  = argv->get (1);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if ((obj != nilp) && (lobj == nilp)) 
        throw Exception ("type-error", "invalid object to set in header",
                     Object::repr (obj));
      sethead (idx, lobj);
      return nilp;
      }
      if (quark == QUARK_SETFOOT) {
      long    idx = argv->getint (0);
      Object*  obj  = argv->get (1);
      Literal* lobj = dynamic_cast <Literal*> (obj);
      if ((obj != nilp) && (lobj == nilp)) 
        throw Exception ("type-error", "invalid object to set in footer",
                     Object::repr (obj));
      setfoot (idx, lobj);
      return nilp;
      }
      if (quark == QUARK_GET) {
      long row = argv->getint (0);
      long col = argv->getint (1);
      rdlock ();
      try {
        Object* result = get (row, col);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_MAP) {
      long row = argv->getint (0);
      long col = argv->getint (1);
      rdlock ();
      try {
        Object* result = map (row, col);
        robj->post (result);
        unlock ();
        return result;
      } catch (...) {
        unlock ();
        throw;
      }
      }
      if (quark == QUARK_SET) {
      long    idx = argv->getint (0);
      Object* obj = argv->get (1);
      Record* rcd = dynamic_cast <Record*> (obj);
      if ((obj != nilp) && (rcd == nilp)) 
        throw Exception ("type-error", "invalid object to set in sheet",
                     Object::repr (obj));
      set (idx, rcd);
      return nilp;
      }
      if (quark == QUARK_CONVERT) {
      long max   = argv->getint (0);
      long start = argv->getint (1);
      return convert (max, start, true);
      }
      if (quark == QUARK_SORT) {
      long col  = argv->getint  (0);
      bool mode = argv->getbool (1);
      sort (col, mode);
      return nilp;
      }
      if (quark == QUARK_LINKCOL) {
      Object* obj = argv->get (0);
      Sheet*  sht = dynamic_cast <Sheet*> (obj);
      if (sht == nilp) {
        throw Exception ("type-error", "invalid object with link-column",
                     Object::repr (obj));
      }
      long col = argv->getint (1);
      lkcol (sht, col);
      return nilp;
      }
    }
    // dispatch 3 arguments
    if (argc == 3) {
      if (quark == QUARK_CONVERT) {
      long max   = argv->getint  (0);
      long start = argv->getint  (1);
      bool flag  = argv->getbool (2);
      return convert (max, start, flag);
      }
      if (quark == QUARK_SET) {
      long    row = argv->getint (0);
      long    col = argv->getint (1);
      Object* obj = argv->get    (2);
      set (row, col, obj);
      return nilp;
      }
    }
    // call the persist method
    return Persist::apply (robj, nset, quark, argv);
  }


Generated by  Doxygen 1.6.0   Back to index