Exemplo n.º 1
0
DECLARE_EXPORT SetupMatrix::Rule* SetupMatrix::createRule(const AttributeList& atts)
{
  // Pick up the start, end and name attributes
  int priority = atts.get(Tags::tag_priority)->getInt();

  // Check for existence of a rule with the same priority
  Rule* result = firstRule;
  while (result && priority > result->priority)
    result = result->nextRule;
  if (result && result->priority != priority) result = NULL;

  // Pick up the action attribute and update the rule accordingly
  switch (MetaClass::decodeAction(atts))
  {
    case ADD:
      // Only additions are allowed
      if (result)
      {
        ostringstream o;
        o << "Rule with priority "  << priority
          << " already exists in setup matrix '" << getName() << "'";
        throw DataException(o.str());
      }
      result = new Rule(this, priority);
      return result;
    case CHANGE:
      // Only changes are allowed
      if (!result)
      {
        ostringstream o;
        o << "No rule with priority " << priority
          << " exists in setup matrix '" << getName() << "'";
        throw DataException(o.str());
      }
      return result;
    case REMOVE:
      // Delete the entity
      if (!result)
      {
        ostringstream o;
        o << "No rule with priority " << priority
          << " exists in setup matrix '" << getName() << "'";
        throw DataException(o.str());
      }
      else
      {
        // Delete it
        delete result;
        return NULL;
      }
    case ADD_CHANGE:
      if (!result)
        // Adding a new rule
        result = new Rule(this, priority);
      return result;
  }

  // This part of the code isn't expected not be reached
  throw LogicException("Unreachable code reached");
}
Exemplo n.º 2
0
DECLARE_EXPORT SetupMatrix::Rule::Rule(SetupMatrix *s, int p)
  : cost(0), priority(p), matrix(s), nextRule(NULL), prevRule(NULL)
{
  // Validate the arguments
  if (!matrix) throw DataException("Can't add a rule to NULL setup matrix");

  // Find the right place in the list
  Rule *next = matrix->firstRule, *prev = NULL;
  while (next && p > next->priority)
  {
    prev = next;
    next = next->nextRule;
  }

  // Duplicate priority
  if (next && next->priority == p)
    throw DataException("Multiple rules with identical priority in setup matrix");

  // Maintain linked list
  nextRule = next;
  prevRule = prev;
  if (prev) prev->nextRule = this;
  else matrix->firstRule = this;
  if (next) next->prevRule = this;

  // Initialize the Python type
  initType(metadata);
}
Exemplo n.º 3
0
void SetupMatrixRule::setSetupMatrix(SetupMatrix *s)
{
  // Validate the arguments
  if (matrix)
    throw DataException("Can't reassign setup matrix matrix once assigned");
  if (!s)
    throw DataException("Can't update setup matrix to nullptr");

  // Assign the pointer
  matrix = s;

  // Find the right place in the list
  SetupMatrixRule *next = matrix->firstRule, *prev = nullptr;
  while (next && priority > next->priority)
  {
    prev = next;
    next = next->nextRule;
  }

  // Duplicate priority
  if (next && next->priority == priority)
    throw DataException("Multiple rules with identical priority in setup matrix");

  // Maintain linked list
  nextRule = next;
  prevRule = prev;
  if (prev)
    prev->nextRule = this;
  else
    matrix->firstRule = this;
  if (next)
    next->prevRule = this;
}
Exemplo n.º 4
0
int
FunctionSpace::getTagFromDataPointNo(DataTypes::dim_t dataPointNo) const
{
  //
  // Get the number of samples and data-points per sample
  int numSamples = getNumSamples();
  int numDataPointsPerSample = getNumDPPSample();
  int numDataPoints = numSamples * numDataPointsPerSample;

  if (numDataPointsPerSample==0) {
    throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
  }

  if (dataPointNo<0 || dataPointNo>=numDataPoints) {
    throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
  }

  //
  // Determine the sample number which corresponds to this data-point number
  int sampleNo = dataPointNo / numDataPointsPerSample;

  //
  // Determine the tag number which corresponds to this sample number
  int tagNo = getTagFromSampleNo(sampleNo);

  //
  // return the tag number
  return(tagNo);
}
Exemplo n.º 5
0
PyObject* SubOperation::create(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
{
  try
  {
    // Pick up the operation
    PyObject* oper = PyDict_GetItemString(kwds, "operation");
    if (!oper)
      throw DataException("Missing operation on SubOperation");
    if (!PyObject_TypeCheck(oper, Operation::metadata->pythonClass))
      throw DataException("field 'operation' of suboperation must be of type operation");

    // Pick up the owner
    PyObject* owner = PyDict_GetItemString(kwds, "owner");
    if (!owner)
      throw DataException("Missing owner on SubOperation");
    if (!PyObject_TypeCheck(owner, Operation::metadata->pythonClass))
      throw DataException("field 'operation' of suboperation must be of type operation");

    // Pick up the type and create the suboperation
    SubOperation *l = new SubOperation();
    if (oper) l->setOperation(static_cast<Operation*>(oper));
    if (owner) l->setOwner(static_cast<Operation*>(owner));

    // Iterate over extra keywords, and set attributes.   @todo move this responsibility to the readers...
    if (l)
    {
      PyObject *key, *value;
      Py_ssize_t pos = 0;
      while (PyDict_Next(kwds, &pos, &key, &value))
      {
        PythonData field(value);
        PyObject* key_utf8 = PyUnicode_AsUTF8String(key);
        DataKeyword attr(PyBytes_AsString(key_utf8));
        Py_DECREF(key_utf8);
        if (!attr.isA(Tags::operation) && !attr.isA(Tags::owner)
           && !attr.isA(Tags::type) && !attr.isA(Tags::action))
        {
          const MetaFieldBase* fmeta = SubOperation::metacategory->findField(attr.getHash());
          if (fmeta)
            // Update the attribute
            fmeta->setField(l, field);
          else
            l->setProperty(attr.getName(), value);
        }
      };
    }

    // Return the object
    Py_INCREF(l);
    return static_cast<PyObject*>(l);
  }
  catch (...)
  {
    PythonType::evalException();
    return nullptr;
  }
}
Exemplo n.º 6
0
Object* MetaCategory::ControllerDefault (
  const MetaClass* cat, const DataValueDict& in, CommandManager* mgr
  )
{
  Action act = MetaClass::decodeAction(in);
  switch (act)
  {
    case REMOVE:
      throw DataException
      ("Entity " + cat->type + " doesn't support REMOVE action");
    case CHANGE:
      throw DataException
      ("Entity " + cat->type + " doesn't support CHANGE action");
    default:
      /* Lookup the class in the map of registered classes. */
      const MetaClass* j;
      if (cat->category)
        // Class metadata passed: we already know what type to create
        j = cat;
      else
      {
        // Category metadata passed: we need to look up the type
        const DataValue* type = in.get(Tags::type);
        j = static_cast<const MetaCategory&>(*cat).findClass(
          type ? Keyword::hash(type->getString()) : MetaCategory::defaultHash
          );
        if (!j)
        {
          string t(type ? type->getString() : "default");
          throw LogicException("No type " + t + " registered for category " + cat->type);
        }
      }

      // Call the factory method
      assert(j->factoryMethod);
      Object* result = j->factoryMethod();

      // Run the callback methods
      if (!result->getType().raiseEvent(result, SIG_ADD))
      {
        // Creation denied
        delete result;
        throw DataException("Can't create object");
      }

      // Report the creation to the manager
      if (mgr)
        mgr->add(new CommandCreateObject(result));

      // Creation accepted
      return result;
  }
  throw LogicException("Unreachable code reached");
  return nullptr;
}
Exemplo n.º 7
0
/** @todo this method implementation is not generic enough and not extendible by subclasses. */
PyObject* ResourceSkill::create(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
{
  try
  {
    // Pick up the skill
    PyObject* skill = PyDict_GetItemString(kwds,"skill");
    if (!PyObject_TypeCheck(skill, Skill::metadata->pythonClass))
      throw DataException("resourceskill skill must be of type skill");

    // Pick up the resource
    PyObject* res = PyDict_GetItemString(kwds,"resource");
    if (!PyObject_TypeCheck(res, Resource::metadata->pythonClass))
      throw DataException("resourceskill resource must be of type resource");

    // Pick up the priority
    PyObject* q1 = PyDict_GetItemString(kwds,"priority");
    int q2 = q1 ? PythonObject(q1).getInt() : 1;

    // Pick up the effective dates
    DateRange eff;
    PyObject* eff_start = PyDict_GetItemString(kwds,"effective_start");
    if (eff_start)
    {
      PythonObject d(eff_start);
      eff.setStart(d.getDate());
    }
    PyObject* eff_end = PyDict_GetItemString(kwds,"effective_end");
    if (eff_end)
    {
      PythonObject d(eff_end);
      eff.setEnd(d.getDate());
    }

    // Create the load
    ResourceSkill *l = new ResourceSkill(
      static_cast<Skill*>(skill),
      static_cast<Resource*>(res),
      q2, eff
    );

    // Return the object
    Py_INCREF(l);
    return static_cast<PyObject*>(l);
  }
  catch (...)
  {
    PythonType::evalException();
    return NULL;
  }
}
Exemplo n.º 8
0
void  BindIntVariables(DBHandles *d, DataFeedData *df)
{
    SQLRETURN r;

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_TIMESTAMP, 19, 0, df->timestamp, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->highPrice, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->lowPrice, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->openPrice, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->closePrice, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, -5, 8, 0, df->totalVol, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_INTEGER, 4, 0, df->vol, SIZE, &df->stringLength)))
        throw DataException(__FILE__, __LINE__);

    if (o.isOption == true || o.isFutures == true || o.useContract == true) {
        if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 10, 0, (SQLPOINTER) df->symbol, (SQLINTEGER) strlen(df->symbol), &df->stringLength)))
            throw DataException(__FILE__, __LINE__);
    }
}
Exemplo n.º 9
0
DECLARE_EXPORT PyObject* readXMLdata(PyObject *self, PyObject *args)
{
  // Pick up arguments
  char *data;
  int validate(1), validate_only(0);
  PyObject *userexit = NULL;
  int ok = PyArg_ParseTuple(args, "s|iiO:readXMLdata",
    &data, &validate, &validate_only, &userexit);
  if (!ok) return NULL;

  // Free Python interpreter for other threads
  Py_BEGIN_ALLOW_THREADS

  // Execute and catch exceptions
  try
  {
    if (!data) throw DataException("No input data");
    XMLInputString p(data);
    if (userexit) p.setUserExit(userexit);
    if (validate_only!=0)
      p.parse(NULL, true);
    else
      p.parse(&Plan::instance(), validate!=0);
  }
  catch (...)
  {
    Py_BLOCK_THREADS;
    PythonType::evalException();
    return NULL;
  }
  Py_END_ALLOW_THREADS   // Reclaim Python interpreter
  return Py_BuildValue("");  // Safer than using Py_None, which is not portable across compilers
}
Exemplo n.º 10
0
DECLARE_EXPORT void Resource::setMaximum(double m)
{
  if (m < 0)
    throw DataException("Maximum capacity for resource '" + getName() + "' must be postive");

  // There is already a maximum calendar.
  if (size_max_cal)
  {
    // We update the field, but don't use it yet.
    size_max = m;
    return;
  }

  // Mark as changed
  setChanged();

  // Set field
  size_max = m;

  // Create or update a single timeline max event
  for (loadplanlist::iterator oo=loadplans.begin(); oo!=loadplans.end(); oo++)
    if (oo->getType() == 4)
    {
      // Update existing event
      static_cast<loadplanlist::EventMaxQuantity *>(&*oo)->setMax(size_max);
      return;
    }
  // Create new event
  loadplanlist::EventMaxQuantity *newEvent =
    new loadplanlist::EventMaxQuantity(Date::infinitePast, &loadplans, size_max);
  loadplans.insert(newEvent);
}
Exemplo n.º 11
0
int WriteDataToDB(DBHandles *d, DataFeedData *df)
{
    SQLINTEGER stringLength = SQL_NTS;
    SQLRETURN r;

    //only daily data need this, because the times are jacked up so
    //I just manually set it to midnight
    if (o.useDaily == true)
    {
        char newTransactionTime[50];
        char dummy[50];
        sscanf(df->timestamp, "%s %s", newTransactionTime, dummy);
        sprintf(df->timestamp, "%s 00:00:00", newTransactionTime);
    }

    r = SQLExecute(d->hstmt);

    if (!SQL_SUCCEEDED(r))
    {
        std::string errorString;
        int errorNum = ODBCError(d, errorString);
        //error code denoting that the row already exists
        if (errorNum == 2601 || errorNum == 2627)
            return 0;
        else
            throw DataException(__FILE__, __LINE__);
    }

    return 1;
}
Exemplo n.º 12
0
void SubOperation::setOwner(Operation* o)
{
  if (o == owner)
    // No change
    return;

  if (o && !o->hasSubOperations())
    // Some operation types don't have suboperations
    throw DataException("Operation '" + o->getName() + "' can't have suboperations");

  // Remove from previous owner
  if (oper && owner)
    oper->removeSuperOperation(owner);
  if (owner)
    owner->getSubOperations().remove(this);

  // Update
  owner = o;

  // Insert at new owner
  if (oper && owner)
    oper->addSuperOperation(owner);
  if (owner)
  {
    Operation::Operationlist::iterator iter = owner->getSubOperations().begin();
    while (iter != owner->getSubOperations().end() && prio >= (*iter)->getPriority())
      ++iter;
    owner->getSubOperations().insert(iter, this);
  }
}
Exemplo n.º 13
0
PyObject* saveXMLfile(PyObject* self, PyObject* args)
{
  // Pick up arguments
  char *filename;
  char *content = NULL;
  int ok = PyArg_ParseTuple(args, "s|s:save", &filename, &content);
  if (!ok) return NULL;

  // Execute and catch exceptions
  Py_BEGIN_ALLOW_THREADS   // Free Python interpreter for other threads
  try
  {
    XMLOutputFile o(filename);
    if (content)
    {
      if (!strcmp(content,"STANDARD"))
        o.setContentType(XMLOutput::STANDARD);
      else if (!strcmp(content,"PLAN"))
        o.setContentType(XMLOutput::PLAN);
      else if (!strcmp(content,"PLANDETAIL"))
        o.setContentType(XMLOutput::PLANDETAIL);
      else
        throw DataException("Invalid content type '" + string(content) + "'");
    }
    o.writeElementWithHeader(Tags::tag_plan, &Plan::instance());
  }
  catch (...)
  {
    Py_BLOCK_THREADS;
    PythonType::evalException();
    return NULL;
  }
  Py_END_ALLOW_THREADS   // Reclaim Python interpreter
  return Py_BuildValue("");
}
Exemplo n.º 14
0
DECLARE_EXPORT void Calendar::removeBucket(CalendarBucket* bkt)
{
  // Verify the bucket is on this calendar indeed
  CalendarBucket *b = firstBucket;
  while (b && b != bkt) b = b->nextBucket;

  // Error
  if (!b)
    throw DataException("Trying to remove unavailable bucket from calendar '"
        + getName() + "'");

  // Update the list
  if (bkt->prevBucket)
    // Previous bucket links to a new next bucket
    bkt->prevBucket->nextBucket = bkt->nextBucket;
  else
    // New head for the bucket list
    firstBucket = bkt->nextBucket;
  if (bkt->nextBucket)
    // Update the reference prevBucket of the next bucket
    bkt->nextBucket->prevBucket = bkt->prevBucket;

  // Delete the bucket
  delete bkt;
}
Exemplo n.º 15
0
QString Customizations::DataBasePath()
{
	static bool cached = false;
	if ( cached )
		return dataBasePath_;

	QList<QString> checked_paths;
	QString sub_path( "lobby/SpringLobby/customizations/" );
	sub_path.append( m_shortname );
	for ( int i = 0; i < susynclib().GetSpringDataDirCount(); ++i ) {
		QDir data ( ToQString( susynclib().GetSpringDataDirByIndex(i) ) );
		checked_paths.append( data.absolutePath().append("/").append( sub_path ) );
		if ( data.cd( sub_path ) ) {
			dataBasePath_ = data.absolutePath();
			break;
		}
	}
	if( dataBasePath_ != QString() )
		return dataBasePath_ ;

	checked_paths.prepend( QString("Couldn't find customization data in any of these directories:\n ") );
	throw DataException( checked_paths );

	return QString();
}
Exemplo n.º 16
0
int WriteOneLine(DBHandles *d, char *oneLine, boost::unordered_set<dataPoint> *hash, DataFeedData *df)
{
    if (o.useTicks == true)
    {
        ExtractTickData(oneLine, df);

        //first check the hashTable to see if it already has the data
        if (o.useHashTable == true && hash != NULL)
        {
            dataPoint dp;
            dp.date = GetUDate(df->timestamp, dateGC);
            dp.tickId = atoi(df->tickId);

            if (hash->find(dp) != hash->end())
                return 0;
        }
    }
    else if (o.useInterval == true || o.useDaily == true)
    {
        ExtractIntData(oneLine, df);
    }
    else
    {
        WriteLog("Missing useInterval or useTicks\n");
        throw DataException(__FILE__, __LINE__);
    }

    return WriteDataToDB(d, df);
}
Exemplo n.º 17
0
DECLARE_EXPORT void Load::setAlternate(Load *f)
{
  // Can't be an alternate to oneself.
  // No need to flag as an exception.
  if (f == this) return;

  // Validate the argument
  if (!f)
    throw DataException("Setting NULL alternate load");
  if (hasAlts || f->altLoad)
    throw DataException("Nested alternate loads are not allowed");

  // Update both flows
  f->hasAlts = true;
  altLoad = f;
}
Exemplo n.º 18
0
DECLARE_EXPORT void LoadPlan::setLoad(Load* newld)
{
  // No change
  if (newld == ld) return;

  // Verify the data
  if (!newld) throw DataException("Can't switch to NULL load");
  if (ld && ld->getOperation() != newld->getOperation())
    throw DataException("Only switching to a load on the same operation is allowed");

  // Update the load and resource fields
  LoadPlan* o = getOtherLoadPlan();
  if (o) o->ld = newld;
  ld = newld;
  setResource(newld->getResource());
}
Exemplo n.º 19
0
void SetupMatrixRule::setPriority(const int n)
{
  if (n == priority)
    return;
  if (!matrix)
  {
    // As long as there is no matrix assigned, anything goes
    priority = n;
    return;
  }

  // Check for duplicate priorities, before making any changes
  for (SetupMatrixRule *i = matrix->firstRule; i; i = i->nextRule)
    if (i->priority == n)
    {
      ostringstream o;
      o << "Rule with priority " << priority << " in setup matrix '"
        << matrix->getName() << "' already exists";
      throw DataException(o.str());
    }
    else if (i->priority > n)
      break;

  // Update the field
  priority = n;

  // Check ordering on the left
  while (prevRule && priority < prevRule->priority)
  {
    SetupMatrixRule* next = nextRule;
    SetupMatrixRule* prev = prevRule;
    if (prev->prevRule)
      prev->prevRule->nextRule = this;
    else
      matrix->firstRule = this;
    prev->nextRule = nextRule;
    nextRule = prev;
    prevRule = prev->prevRule;
    if (next)
      next->prevRule = prev;
    prev->prevRule = this;
  }

  // Check ordering on the right
  while (nextRule && priority > nextRule->priority)
  {
    SetupMatrixRule* next = nextRule;
    SetupMatrixRule* prev = prevRule;
    nextRule = next->nextRule;
    if (next->nextRule)
      next->nextRule->prevRule = this;
    if (prev)
      prev->nextRule = next;
    else
      matrix->firstRule = next;
    next->nextRule = this;
    next->prevRule = prev;
    prevRule = next;
  }
}
Exemplo n.º 20
0
DECLARE_EXPORT void Load::setAlternateName(string n)
{
  if (!getOperation())
    throw LogicException("Can't set an alternate load before setting the operation");
  Load *x = getOperation()->loaddata.find(n);
  if (!x) throw DataException("Can't find load with name '" + n + "'");
  setAlternate(x);
}
Exemplo n.º 21
0
Object* MetaCategory::ControllerDefault (const MetaClass* cat, const AttributeList& in)
{
  Action act = ADD;
  switch (act)
  {
    case REMOVE:
      throw DataException
      ("Entity " + cat->type + " doesn't support REMOVE action");
    case CHANGE:
      throw DataException
      ("Entity " + cat->type + " doesn't support CHANGE action");
    default:
      /* Lookup for the class in the map of registered classes. */
      const MetaClass* j;
      if (cat->category)
        // Class metadata passed: we already know what type to create
        j = cat;
      else
      {
        // Category metadata passed: we need to look up the type
        const DataElement* type = in.get(Tags::tag_type);
        j = static_cast<const MetaCategory&>(*cat).findClass(*type ? Keyword::hash(type->getString()) : MetaCategory::defaultHash);
        if (!j)
        {
          string t(*type ? type->getString() : "default");
          throw LogicException("No type " + t + " registered for category " + cat->type);
        }
      }

      // Call the factory method
      Object* result = j->factoryMethodDefault();

      // Run the callback methods
      if (!result->getType().raiseEvent(result, SIG_ADD))
      {
        // Creation denied
        delete result;
        throw DataException("Can't create object");
      }

      // Creation accepted
      return result;
  }
  throw LogicException("Unreachable code reached");
  return NULL;
}
Exemplo n.º 22
0
DECLARE_EXPORT void Flow::setAlternate(Flow *f)
{
  // Can't be an alternate to oneself.
  // No need to flag as an exception.
  if (f == this) return;

  // Validate the argument
  if (!f)
    throw DataException("Setting NULL alternate flow");
  if (hasAlts || f->altFlow)
    throw DataException("Nested alternate flows are not allowed");
  if (f->getQuantity() > 0.0 || getQuantity() > 0.0)
    throw DataException("Only consuming alternate flows are supported");

  // Update both flows
  f->hasAlts = true;
  altFlow = f;
}
Exemplo n.º 23
0
DECLARE_EXPORT void CalendarBucket::setEnd(const Date d)
{
  // Check
  if (d < startdate)
    throw DataException("Calendar bucket end must be later than its start");

  // Update
  enddate = d;
}
Exemplo n.º 24
0
DataTypes::dim_t FunctionSpace::getReferenceIDFromDataPointNo(DataTypes::dim_t dataPointNo) const
{
     //
     // Get the number of samples and data-points per sample
    DataTypes::dim_t numSamples = getNumSamples();
    int numDataPointsPerSample = getNumDPPSample();
    const DataTypes::dim_t* referenceIDs= borrowSampleReferenceIDs();
    DataTypes::dim_t numDataPoints = numSamples * numDataPointsPerSample;

    if (numDataPointsPerSample==0) {
        throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
    }
    if (dataPointNo<0 || dataPointNo>numDataPoints) {
        throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
    }
    DataTypes::dim_t sampleNo = dataPointNo / numDataPointsPerSample;
    return referenceIDs[sampleNo];
}
Exemplo n.º 25
0
DECLARE_EXPORT void Flow::setAlternateName(const string& n)
{
  if (!getOperation())
    throw LogicException("Can't set an alternate flow before setting the operation");
  Flow *x = getOperation()->flowdata.find(n);
  if (!x)
    throw DataException("Can't find flow with name '" + n + "'");
  setAlternate(x);
}
Exemplo n.º 26
0
// FunctionSpace instances should not be overwritten to point to different domains/types
// The only time this was actually used was in constructors and the copy constructor can deal with that
FunctionSpace&
FunctionSpace::operator=(const FunctionSpace& other)
{
  throw DataException("FunctionSpace::= should not be called. Programming Error.");
  // explicitly defined assignment operator to emphasise pointer copy
/*  m_functionSpaceType=other.m_functionSpaceType;
  m_domain=other.m_domain;
  return *this;*/
}
Exemplo n.º 27
0
DECLARE_EXPORT void Flow::validate(Action action)
{
  // Catch null operation and buffer pointers
  Operation* oper = getOperation();
  Buffer* buf = getBuffer();
  if (!oper || !buf)
  {
    // This flow is not a valid one since it misses essential information
    if (!oper && !buf)
      throw DataException("Missing operation and buffer on a flow");
    else if (!oper)
      throw DataException("Missing operation on a flow with buffer '"
          + buf->getName() + "'");
    else
      throw DataException("Missing buffer on a flow with operation '"
          + oper->getName() + "'");
  }

  // Check if a flow with 1) identical buffer, 2) identical operation and
  // 3) overlapping effectivity dates already exists, and 4) same
  // flow type.
  Operation::flowlist::const_iterator i = oper->getFlows().begin();
  for (; i != oper->getFlows().end(); ++i)
    if (i->getBuffer() == buf
        && i->getEffective().overlap(getEffective())
        && i->getType() == getType()
        && &*i != this)
      break;

  // Apply the appropriate action
  switch (action)
  {
    case ADD:
      if (i != oper->getFlows().end())
        throw DataException("Flow of '" + oper->getName() + "' and '" +
            buf->getName() + "' already exists");
      break;
    case CHANGE:
      throw DataException("Can't update a flow");
    case ADD_CHANGE:
      // ADD is handled in the code after the switch statement
      if (i == oper->getFlows().end()) break;
      throw DataException("Can't update a flow between '" +
        oper->getName() + "' and '" + buf->getName() + "')");
    case REMOVE:
      // Delete the temporary flow object
      delete this;
      // Nothing to delete
      if (i == oper->getFlows().end())
        throw DataException("Can't remove nonexistent flow of '"
            + oper->getName() + "' and '" + buf->getName() + "'");
      // Delete
      delete &*i;
  }

  // Set a flag to make sure the level computation is triggered again
  HasLevel::triggerLazyRecomputation();
}
Exemplo n.º 28
0
void OperationTransport::setFromBuffer(Buffer *b)
{
  // Don't update the operation if operationplans already exist
  if (OperationPlan::iterator(this) != OperationPlan::end())
    throw DataException("Can't update an initialized transport operation");

  // Create a flow
  fromBuf = b;
  new Flow(this, b, -1);
}
Exemplo n.º 29
0
DECLARE_EXPORT void Solver::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
{
  if (pAttr.isA(Tags::tag_loglevel))
  {
    int i = pElement.getInt();
    if (i<0 || i>USHRT_MAX)
      throw DataException("Invalid log level" + pElement.getString());
    setLogLevel(i);
  }
}
Exemplo n.º 30
0
	void Data::isReady(){
		if(eof()){
			throw DataException("Stream is closed!");
			return;
		}
		if(!ready){
			makeReady();
		}
		return;
	}