Пример #1
0
void*
omlf_sum_new(OmlValueT type, OmlValue* result)
{
  if (! omlc_is_numeric_type (type)) {
    logerror ("%s filter: Can only handle numeric parameters\n", FILTER_NAME);
    return NULL;
  }

  InstanceData* self = (InstanceData *)xmalloc(sizeof(InstanceData));

  if (self) {
    memset(self, 0, sizeof(InstanceData));

    self->sample_sum = 0.;
    self->sample_count = 0;
    self->result = result;
  } else {
    logerror ("%s filter: Could not allocate %d bytes for instance data\n",
        FILTER_NAME,
        sizeof(InstanceData));
    return NULL;
  }

  return self;
}
Пример #2
0
/** Assign the content of an OmlValueU of the given OmlValueT to an OmlValue.
 *
 * This function copies value, which is assumed to be of the given type (no
 * check can be made), into the OmlValue pointed to by to.  The to object is
 * set to have the given type. If type is a simple numeric type, the copy
 * simply copies the value.
 *
 * If type is OML_STRING_VALUE, then the string contents are copied into new
 * storage in to.  If to was previously set to be a const string, then the
 * is_const flag is cleared and a new block of memory is allocated to store the
 * copy and its terminating null character. If to did not previously have the
 * is_const flag set, and its string pointer was NULL, then a new block of
 * memory is also allocated as well.  If the string pointer was not NULL, then
 * the string is copied into the previously allocated memory block if it is
 * large enough to fit; otherwise the block is freed and a new one allocated
 * large enough to hold the string (and its terminator).
 *
 * Blobs are handled in a similar fashion.
 *
 * If the source pointer is NULL then an error is returned and a warning
 * message is sent to the log.
 *
 * \param to pointer to OmlValue into which the value should be copied
 * \param value pointer to original OmlValueU to copy into to
 * \param type OmlValueT of value
 * \return 0 if successful, -1 otherwise
 * \see oml_value_init, omlc_copy_string, omlc_copy_blob
 */
int
oml_value_set(OmlValue *to, const OmlValueU *value, OmlValueT type)
{
    oml_value_set_type(to, type);
    if (omlc_is_numeric_type (type) ||
            omlc_is_guid_type (type) ||
            omlc_is_bool_type (type)) {
        to->value = *value;
    } else {
        switch (type) {
        case OML_STRING_VALUE:
            if (!omlc_get_string_ptr(*value)) {
                logwarn("Trying to copy OML_STRING_VALUE from a NULL source\n");
                return -1;
            }
            omlc_copy_string(*oml_value_get_value(to), *value);
            break;

        case OML_DATETIME_VALUE:
            if (!omlc_get_string_ptr(*value)) {
                logwarn("Trying to copy OML_DATETIME_VALUE from a NULL source\n");
                return -1;
            }
            omlc_copy_string(*oml_value_get_value(to), *value);
            break;

        case OML_BLOB_VALUE:
            if (!omlc_get_blob_ptr(*value)) {
                logwarn("Trying to copy OML_BLOB_VALUE from a NULL source\n");
                return -1;
            }
            omlc_copy_blob(*oml_value_get_value(to), *value);
            break;

        case OML_VECTOR_DOUBLE_VALUE:
        case OML_VECTOR_INT32_VALUE:
        case OML_VECTOR_UINT32_VALUE:
        case OML_VECTOR_INT64_VALUE:
        case OML_VECTOR_UINT64_VALUE:
        case OML_VECTOR_BOOL_VALUE:
            if (!omlc_get_vector_ptr(*value)) {
                logwarn("Trying to copy OML_VECTOR_*_VALUE from a NULL source\n");
                return -1;
            }
            omlc_copy_vector(*oml_value_get_value(to), *value);
            break;

        default:
            logerror("%s() for type '%d' not implemented'\n", __FUNCTION__, type);
            return -1;
        }
    }
    return 0;
}