Ejemplo n.º 1
0
//-------------------------------------------------------------------
double *cpp_xloper::ConvertMultiToDouble(void)
{
   if(m_Op.xltype != xltypeMulti)
      return NULL;

// Allocate the space for the array of doubles
   int size = m_Op.val.array.rows * m_Op.val.array.columns;
   double *ret_array = (double *)malloc(size * sizeof(double));

   if(!ret_array)
      return NULL;

// Get the cell values one-by-one as doubles and place in the array.
// Store the array row-by-row in memory.
   xloper *p_op = m_Op.val.array.lparray;

   if(!p_op)
   {
      free(ret_array);
      return NULL;
   }

   double *p = ret_array;

   for(; size--; p++)
      if(!coerce_to_double(p_op++, *p))
         *p = 0.0;

   return ret_array; // caller must free the memory!
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------
cpp_xloper::operator double(void)
{
   double d;

   if(coerce_to_double(&m_Op, d))
      return d;

   return 0.0;
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------
bool cpp_xloper::operator==(double d)
{
   double dd;

   if(!coerce_to_double(&m_Op, dd) || dd != d)
      return false;

   return true;
}
Ejemplo n.º 4
0
//-------------------------------------------------------------------
xl_array *cpp_xloper::AsDblArray(void)
{
   xl_array *p_ret_array;
   double *p;
   int size;
   xloper *p_op;

   switch(m_Op.xltype)
   {
   case xltypeMulti:
      size = m_Op.val.array.rows * m_Op.val.array.columns;
      p_ret_array = (xl_array *)malloc(sizeof(xl_array) + sizeof(double) * (size - 1));
      p_ret_array->columns = m_Op.val.array.columns;
      p_ret_array->rows = m_Op.val.array.rows;

      if(!p_ret_array)
         return NULL;

// Get the cell values one-by-one as doubles and place in the array.
// Store the array row-by-row in memory.
      if(!(p_op = m_Op.val.array.lparray))
      {
         free(p_ret_array);
         return NULL;
      }

      for(p = p_ret_array->array; size--; p++)
         if(!coerce_to_double(p_op++, *p))
            *p = 0.0;

      return p_ret_array;

   case xltypeNum:
   case xltypeStr:
   case xltypeBool:
      p_ret_array = (xl_array *)malloc(sizeof(xl_array));
      p_ret_array->columns = p_ret_array->rows = 1;
      if(!coerce_to_double(&m_Op, p_ret_array->array[0]))
         p_ret_array->array[0] = 0.0;

      return p_ret_array;
   }
   return NULL;
}
Ejemplo n.º 5
0
//-------------------------------------------------------------------
// Allocate and populate an array of doubles based on input xloper
//-------------------------------------------------------------------
double *coerce_to_double_array(const xloper *p_op, double invalid_value, RW &cols, COL &rows)
{
	if(!p_op || (p_op->xltype & (xltypeMissing | xltypeNil)))
		return NULL;

// xloper is not an xloper array type, so try to convert it.
	xloper ret_val;

	if(!coerce_xloper(p_op, ret_val, xltypeMulti))
		return NULL;

// Allocate the space for the array of doubles
	cols = ret_val.val.array.columns;
	rows = ret_val.val.array.rows;
	int size = rows * cols;
	double *d_array = (double *)malloc(size * sizeof(double));

	if(!d_array)
	{
	// Must free array memory allocated by xlCoerce
		Excel4(xlFree, 0, 1, &ret_val);
		return NULL;
	}

// Get the cell values one-by-one as doubles and place in the array.
// Store the array row-by-row in memory.
	xloper *p_elt = ret_val.val.array.lparray;

	if(!p_elt) // array could not be created
	{
	// Must free array memory allocated by xlCoerce
		Excel4(xlFree, 0, 1, &ret_val);
		free(d_array);
		return NULL;
	}

	double *p = d_array;

	for(; size--; p++)
		if(!coerce_to_double(p_elt++, *p))
			*p = invalid_value;

	Excel4(xlFree, 0, 1, &ret_val);
	return d_array; // caller must free this
}
Ejemplo n.º 6
0
//-------------------------------------------------------------------
bool cpp_xloper::GetArrayElement(DWORD offset, double &d)
{
   return coerce_to_double(GetArrayElement(offset), d);
}
Ejemplo n.º 7
0
//-------------------------------------------------------------------
bool cpp_xloper::GetArrayElement(WORD row, WORD column, double &d)
{
   return coerce_to_double(GetArrayElement(row, column), d);
}