int32_t compareUnRepeatedFieldValue(const Message * msg1, const Message * msg2, const FieldDescriptor * field1, const FieldDescriptor * field2) {
  if (field1->cpp_type() != field2->cpp_type()) {
    if (field1->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || field2->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
      return 1;
    }

    PbVariant lvar = getFieldValue(msg1, field1);
    PbVariant rvar = getFieldValue(msg2, field2);

    if (lvar == rvar) {
      return 0;
    } else if (lvar < rvar) {
      return -1;
    } else {
      return 1;
    }
  }

  const Reflection* ref1 = msg1->GetReflection();
  const Reflection* ref2 = msg2->GetReflection();
  switch (field1->cpp_type()) {
    case FieldDescriptor::CPPTYPE_UINT64:
      return ref1->GetUInt64(*msg1, field1) - ref2->GetUInt64(*msg2, field2);
    case FieldDescriptor::CPPTYPE_INT64:
      return ref1->GetInt64(*msg1, field1) - ref2->GetInt64(*msg2, field2);
    case FieldDescriptor::CPPTYPE_UINT32:
      return ref1->GetUInt32(*msg1, field1) - ref2->GetUInt32(*msg2, field2);
    case FieldDescriptor::CPPTYPE_INT32:
      return ref1->GetInt32(*msg1, field1) - ref2->GetInt32(*msg2, field2);
    case FieldDescriptor::CPPTYPE_STRING:
      return ref1->GetString(*msg1, field1).compare(ref2->GetString(*msg2, field2));
    case FieldDescriptor::CPPTYPE_DOUBLE: {
      double lhs = ref1->GetDouble(*msg1, field1);
      double rhs = ref2->GetDouble(*msg2, field2);
      /// @todo float or double should not be compared directly. correct one should like: abs(lhs - rhs) < 0.0000001
      return (lhs == rhs) ? 0 : ((lhs > rhs) ? 2 : -2);
    }
    case FieldDescriptor::CPPTYPE_FLOAT: {
      float lhs = ref1->GetFloat(*msg1, field1);
      float rhs = ref2->GetFloat(*msg2, field2);
      /// @todo float or double should not be compared directly. correct one should like: abs(lhs - rhs) < 0.0000001
      return (lhs == rhs) ? 0 : ((lhs > rhs) ? 2 : -2);
    }
    case FieldDescriptor::CPPTYPE_BOOL:
      return ref1->GetBool(*msg1, field1) - ref2->GetBool(*msg2, field2);
    case FieldDescriptor::CPPTYPE_ENUM:
      return ref1->GetEnum(*msg1, field1)->number() - ref2->GetEnum(*msg2, field2)->number();
    case FieldDescriptor::CPPTYPE_MESSAGE:
      return compare(&ref1->GetMessage(*msg1, field1), &ref2->GetMessage(*msg2, field2));
    default:
      LOG(ERROR)<< "The type of protobuf is not supported";
      return 0;
  }
}
Ejemplo n.º 2
0
void* getValueOfField(char* fieldname) {
    struct HEADERFIELD* data = getFieldData(fieldname);
    if (data != NULL) {
        return getFieldValue(data->location, data->type);
    }
    return (void*) -1;
}
Ejemplo n.º 3
0
bool GREv0Layer::unsetChecksum()
{
	gre_basic_header* header = getGreHeader();

	if (header->checksumBit == 0)
	{
		LOG_ERROR("Couldn't unset checksum as it's already unset");
		return false;
	}

	// if both routing and checksum are unset we need to shorted the layer
	bool needToShortenLayer = (header->routingBit == 0);

	uint8_t* offsetPtr = getFieldValue(GreChecksumOrRouting, true);
	int offset = offsetPtr - m_Data;
	if (needToShortenLayer && !shortenLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't extend layer to unset checksum");
		return false;
	}

	if (!needToShortenLayer) // meaning routing bit is set - only zero the checksum field
	{
		uint16_t* checksumPtr = (uint16_t*)(m_Data + offset);
		*checksumPtr = 0;
	}

	header = getGreHeader();
	header->checksumBit = 0;

	return true;
}
Ejemplo n.º 4
0
bool GREv0Layer::setKey(uint32_t key)
{
	gre_basic_header* header = getGreHeader();

	bool needToExtendLayer = false;

	if (header->keyBit == 0)
		needToExtendLayer = true;

	uint8_t* offsetPtr = getFieldValue(GreKey, true);

	int offset = offsetPtr - m_Data;
	if (needToExtendLayer && !extendLayer(offset, sizeof(uint32_t)))
	{
		header->keyBit = 0;
		LOG_ERROR("Couldn't extend layer to set key");
		return false;
	}

	header = getGreHeader();
	header->keyBit = 1;
	uint32_t* keyPtr = (uint32_t*)(m_Data + offset);
	*keyPtr = htonl(key);

	return true;
}
Ejemplo n.º 5
0
// this function registers callback for vhpiCbValueChange reason  
// arguments: handles to signal and to user data 
bool isRegisteredCbValueChange( PLI_VOID( *cb_rtn_name ) (const struct vhpiCbDataS *), vhpiHandleT _hSigHdl, PLI_VOID*  _hUserData )
{
	vhpiCbDataT	cbData;
	vhpiHandleT	cbData_Hdl;
	vhpiErrorInfoT errInf;
	
	cbData.cb_rtn = cb_rtn_name;
	cbData.reason = vhpiCbValueChange;
	cbData.obj = _hSigHdl;
	cbData.value = getFieldValue( cbData.obj );
	cbData.time = NULL;				
	cbData.user_data = _hUserData;	 // pass user data handle to callback 
 	
	vhpi_register_cb( &cbData, vhpiReturnCb );
	if ( ( cbData_Hdl = vhpi_register_cb( &cbData, vhpiReturnCb ) ) )
		return true;
	else 
	{
	// check error message and print failure info
		vhpi_printf( "isRegisteredCbValueChange(): Callback on vhpiCbValueChange reason for signal: %s NOT registered \n", vhpi_get_str( vhpiFullNameP, _hSigHdl ) );
		if ( vhpi_check_error( &errInf ) )
			vhpi_printf( errInf.message );
		else
			vhpi_printf( "isRegisteredCbValueChange(): No vhpi_check_error() message...\n" ); 
		return false;
	}
}	
Ejemplo n.º 6
0
JNIEXPORT jobject  Java_com_chenjw_knife_agent_utils_NativeHelper_getFieldValue0(
		JNIEnv * env, jclass thisClass, jobject obj, jclass fieldClass,
		jstring fieldName, jclass fieldType) {

	initJvmti(env);
	char* fieldNameChars = (char*) (*env)->GetStringUTFChars(env, fieldName, 0);
	jclass klass = fieldClass;
	jint count = 0;
	jfieldID* fieldIds;
	(*jvmti)->GetClassFields(jvmti, klass, &count, &fieldIds);
	jint i;
	for (i = 0; i < count; i++) {
		char* tFieldName;
		(*jvmti)->GetFieldName(jvmti, klass, fieldIds[i], &tFieldName, 0, 0);
		if (strcmp(tFieldName, fieldNameChars) == 0) {
			jobject result = getFieldValue(env, obj, fieldType, fieldIds[i]);
			deallocate(tFieldName);
			deallocate(fieldIds);
			(*env)->ReleaseStringUTFChars(env, fieldName, fieldNameChars);
			return result;
		}
	}
	throwException(env, 0, "field not found");
	deallocate(fieldIds);
	(*env)->ReleaseStringUTFChars(env, fieldName, fieldNameChars);
	return 0 ;
}
Ejemplo n.º 7
0
bool GreLayer::setSequenceNumber(uint32_t seqNumber)
{
	gre_basic_header* header = (gre_basic_header*)m_Data;

	bool needToExtendLayer = false;

	if (header->sequenceNumBit == 0)
		needToExtendLayer = true;

	uint8_t* offsetPtr = getFieldValue(GreSeq, true);

	int offset = offsetPtr - m_Data;
	if (needToExtendLayer && !extendLayer(offset, sizeof(uint32_t)))
	{
		header->sequenceNumBit = 0;
		LOG_ERROR("Couldn't extend layer to set sequence number");
		return false;
	}

	header = (gre_basic_header*)m_Data;
	header->sequenceNumBit = 1;
	uint32_t* seqPtr = (uint32_t*)(m_Data + offset);
	*seqPtr = htonl(seqNumber);

	return true;
}
Ejemplo n.º 8
0
bool GREv0Layer::setChecksum(uint16_t checksum)
{
	gre_basic_header* header = getGreHeader();

	bool needToExtendLayer = false;

	if (header->routingBit == 0 && header->checksumBit == 0)
		needToExtendLayer = true;

	uint8_t* offsetPtr = getFieldValue(GreChecksumOrRouting, true);
	int offset = offsetPtr - m_Data;
	// extend layer in 4 bytes to keep 4-byte alignment
	if (needToExtendLayer && !extendLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't extend layer to set checksum");
		return false;
	}

	uint16_t* checksumPtr = (uint16_t*)(m_Data + offset);
	*checksumPtr = htons(checksum);

	// if layer was extended in 4 bytes, make sure the offset field stays 0
	if (needToExtendLayer)
	{
		checksumPtr++;
		*checksumPtr = 0;
	}

	header = getGreHeader();
	header->checksumBit = 1;

	return true;
}
Ejemplo n.º 9
0
BaseHybridClass* HybridData::getNativePointer() {
  static auto pointerField = getClass()->getField<jlong>("mNativePointer");
  auto* value = reinterpret_cast<BaseHybridClass*>(getFieldValue(pointerField));
  if (!value) {
    throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException");
  }
  return value;
}
Ejemplo n.º 10
0
void listHeader() {
    int rows = sizeof(fields) / sizeof(struct HEADERFIELD);
    //int rows = 6;
    for(int i = 0; i < rows; i++) {
        //printf("DEBUG: header field[%d].name = %s, location = %04x, type = %d\n", i, fields[i].name, fields[i].location, fields[i].type);
        printf(fields[i].description, getFieldValue(fields[i].location, fields[i].type));
    }
}
Ejemplo n.º 11
0
Archivo: post.c Proyecto: xinzou/cweb
form_data *post_get_field_value(post *self, char *field_name) {
	form_data *current_post_data = getFieldValue((BASE(self)), field_name);
	if (current_post_data) {
#ifdef SHOW_FIELD_KEY_VALUE
		fprintf(cgiOut, "%s = %s<br/>", current_post_data->field_name,
				current_post_data->field_value);
#endif
		return current_post_data;
	}
	return NULL;
}
Ejemplo n.º 12
0
OptObjective* OptObjectiveResult::equivOptObjective()
{
    OptObjective* newVar = new OptObjective();

    // copying fields
    for(int i=0;i<OptObjective::nbFields;i++)
    {
        newVar->setFieldValue(i,getFieldValue(i));
    }

    return newVar;
}
Ejemplo n.º 13
0
bool GREv0Layer::getKey(uint32_t& key)
{
	if (getGreHeader()->keyBit == 0)
		return false;

	uint32_t* val = (uint32_t*)getFieldValue(GreKey, false);
	if (val == NULL)
		return false;

	key = ntohl(*val);
	return true;
}
Ejemplo n.º 14
0
bool GREv1Layer::getAcknowledgmentNum(uint32_t& ackNum)
{
	if (getGreHeader()->ackSequenceNumBit == 0)
		return false;

	uint32_t* val = (uint32_t*)getFieldValue(GreAck, false);
	if (val == NULL)
		return false;

	ackNum = ntohl(*val);
	return true;
}
Ejemplo n.º 15
0
void
traceInstructionEnd(Trace *trace, Instruction instr, InstructionData *data, ThreadState *state)
{
   if (!trace) {
      return;
   }

   for (auto i = 0u; i < data->write.size(); ++i) {
      auto field = data->write[i];
      trace->write[i] = getFieldValue(state, instr, field);
   }
}
Ejemplo n.º 16
0
bool GREv0Layer::getChecksum(uint16_t& checksum)
{
	if (getGreHeader()->checksumBit == 0)
		return false;

	uint16_t* val = (uint16_t*)getFieldValue(GreChecksumOrRouting, false);
	if (val == NULL)
		return false;

	checksum = ntohs(*val);
	return true;
}
Ejemplo n.º 17
0
bool GREv0Layer::getOffset(uint16_t& offset)
{
	if (getGreHeader()->routingBit == 0)
		return false;

	uint8_t* val = (uint8_t*)getFieldValue(GreChecksumOrRouting, false);
	if (val == NULL)
		return false;

	offset = ntohs(*(val+2));
	return true;
}
Ejemplo n.º 18
0
bool GreLayer::getSequenceNumber(uint32_t& seqNumber)
{
	gre_basic_header* header = (gre_basic_header*)m_Data;

	if (header->sequenceNumBit == 0)
		return false;

	uint32_t* val = (uint32_t*)getFieldValue(GreSeq, false);
	if (val == NULL)
		return false;

	seqNumber = ntohl(*val);
	return true;
}
Ejemplo n.º 19
0
OptObjectiveResult* OptObjectiveResult::clone() const
{
    OptObjectiveResult* newObj = new OptObjectiveResult();

    // copying fields
    for(int i=0;i<nbFields;i++)
    {
        newObj->setFieldValue(i,getFieldValue(i));
    }
    newObj->_filledFields = _filledFields;
    newObj->_protectedFields = _protectedFields;

    //copying final values
    newObj->setFinalValues(_finalValues);

    return newObj;
}
Ejemplo n.º 20
0
/**
* Equivalent to MOItem::toXmlData() but here, we do not save
* index field. Because if index changed (e.g. order is changed between two versions),
* there would be misunderstanding to keep index. Name is the field used to refer.
* @sa MOItem::toXmlData()
*/
QDomElement MOParameter::toXmlData(QDomDocument & doc)
{
    QDomElement cItem = doc.createElement(this->getClassName());
    QString fieldName;
    QString fieldValue;
    for(int iF=0;iF<getNbFields();iF++)
    {
        //        if(iF!=MOParameter::INDEX)
        //        {
        fieldName = getFieldName(iF,Qt::UserRole);
        fieldName.replace(" ",XMLTools::space());
        fieldValue = getFieldValue(iF).toString();
        fieldValue.replace(" ",XMLTools::space());
        cItem.setAttribute(fieldName,fieldValue);
        //        }
    }
    return cItem;
}
Ejemplo n.º 21
0
void HybridData::setNativePointer(std::unique_ptr<BaseHybridClass> new_value) {
  static auto pointerField = getClass()->getField<jlong>("mNativePointer");
  auto* old_value = reinterpret_cast<BaseHybridClass*>(getFieldValue(pointerField));
  if (new_value) {
    // Modify should only ever be called once with a non-null
    // new_value.  If this happens again it's a programmer error, so
    // blow up.
    FBASSERTMSGF(old_value == 0, "Attempt to set C++ native pointer twice");
  } else if (old_value == 0) {
    return;
  }
  // delete on a null pointer is defined to be a noop.
  delete old_value;
  // This releases ownership from the unique_ptr, and passes the pointer, and
  // ownership of it, to HybridData which is managed by the java GC.  The
  // finalizer on hybridData calls resetNative which will delete the object, if
  // resetNative has not already been called.
  setFieldValue(pointerField, reinterpret_cast<jlong>(new_value.release()));
}
Ejemplo n.º 22
0
bool GREv1Layer::setAcknowledgmentNum(uint32_t ackNum)
{
	bool needToExtendLayer = false;

	gre1_header* header = getGreHeader();

	if (header->ackSequenceNumBit == 0)
		needToExtendLayer = true;

	uint8_t* offsetPtr = getFieldValue(GreAck, true);
	int offset = offsetPtr - m_Data;
	if (needToExtendLayer && !extendLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't extend layer to set ack number");
		return false;
	}

	header = getGreHeader();
	header->ackSequenceNumBit = 1;
	uint32_t* ackPtr = (uint32_t*)(m_Data + offset);
	*ackPtr = htonl(ackNum);
	return true;
}
Ejemplo n.º 23
0
bool GREv1Layer::unsetAcknowledgmentNum()
{
	gre1_header* header = getGreHeader();

	if (header->ackSequenceNumBit == 0)
	{
		LOG_ERROR("Couldn't unset ack number as it's already unset");
		return false;
	}

	uint8_t* offsetPtr = getFieldValue(GreAck, true);

	int offset = offsetPtr - m_Data;
	if (!shortenLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't shorted layer to unset ack number");
		return false;
	}

	header = getGreHeader();
	header->ackSequenceNumBit = 0;
	return true;
}
Ejemplo n.º 24
0
bool GREv0Layer::unsetKey()
{
	gre_basic_header* header = getGreHeader();

	if (header->keyBit == 0)
	{
		LOG_ERROR("Couldn't unset key as it's already unset");
		return false;
	}

	uint8_t* offsetPtr = getFieldValue(GreKey, true);

	int offset = offsetPtr - m_Data;
	if (!shortenLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't shorted layer to unset key");
		return false;
	}

	header = (gre_basic_header*)m_Data;
	header->keyBit = 0;
	return true;
}
Ejemplo n.º 25
0
int main(){
    Lol a,b,*z;
    GenericField *k;
    Queue *fila;

    strcpy(a.c,"CASA1");
    strcpy(b.c,"CASA2");
    a.v=10;
    b.v=20;

    fila=createQueue();
    insertElement(fila,&a,STRUCT1);
    insertElement(fila,&b,STRUCT1);
    do{
        z=(Lol *)getFieldValue(getElement(fila));
		if(z!=NULL){
        	printf("%d  %s\n",z->v,z->c);
		}
    }while(nextElement(fila)==0);
    clearQueue(fila);
    getchar();
    return 0;
}
Ejemplo n.º 26
0
Trace *
traceInstructionStart(Instruction instr, InstructionData *data, ThreadState *state)
{
   if (!state->tracer) {
      return nullptr;
   }

   auto tracer = state->tracer;
   auto &trace = tracer->trace[tracer->index];
   tracer->index = (tracer->index + 1) % tracer->trace.size();
   
   memset(&trace, 0xDC, sizeof(Trace));
   trace.data = data;
   trace.instr = instr;
   trace.cia = state->cia;

   for (auto i = 0u; i < data->read.size(); ++i) {
      auto field = data->read[i];
      trace.read[i] = getFieldValue(state, instr, field);
   }

   return &trace;
}
Ejemplo n.º 27
0
bool GreLayer::unsetSequenceNumber()
{
	gre_basic_header* header = (gre_basic_header*)m_Data;

	if (header->sequenceNumBit == 0)
	{
		LOG_ERROR("Couldn't unset sequence number as it's already unset");
		return false;
	}

	uint8_t* offsetPtr = getFieldValue(GreSeq, true);

	int offset = offsetPtr - m_Data;
	if (!shortenLayer(offset, sizeof(uint32_t)))
	{
		LOG_ERROR("Couldn't shorted layer to unset sequence number");
		return false;
	}

	header = (gre_basic_header*)m_Data;
	header->sequenceNumBit = 0;
	return true;
}
Ejemplo n.º 28
0
int32_t compareRepeatedFieldValue(const Message* msg1, const Message* msg2, const FieldDescriptor* field1, const FieldDescriptor * field2) {
  int32_t result = 0;
  const Reflection* ref1 = msg1->GetReflection();
  const Reflection* ref2 = msg2->GetReflection();
  int size1 = ref1->FieldSize(* msg1, field1);
  int size2 = ref2->FieldSize(* msg2, field2);
  int size = std::min(size1, size2);

  if (field1->cpp_type() != field2->cpp_type()) {
    if (field1->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || field2->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
      return 1;
    }

    for (int32_t i = 0; i < size && result == 0; ++ i) {
      PbVariant lvar = getFieldValue(msg1, field1, i);
      PbVariant rvar = getFieldValue(msg2, field2, i);

      if (lvar == rvar) {
        result = 0;
      } else if (lvar < rvar) {
        result = -1;
      } else {
        result = 1;
      }
    }
  } else {
    switch (field1->cpp_type()) {
    case FieldDescriptor::CPPTYPE_UINT64:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, UInt64);
      break;
    case FieldDescriptor::CPPTYPE_INT64:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, Int64);
      break;
    case FieldDescriptor::CPPTYPE_UINT32:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, UInt32);
      break;
    case FieldDescriptor::CPPTYPE_INT32:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, Int32);
      break;
    case FieldDescriptor::CPPTYPE_STRING:
      for (int i = 0; i < size && result == 0; ++i) {
        result = ref1->GetRepeatedString(*msg1, field1, i).compare(ref2->GetRepeatedString(*msg2, field2, i));
      }
      break;
    case FieldDescriptor::CPPTYPE_DOUBLE:
      for (int i = 0; i < size && result == 0; ++i) {
        auto v1 = ref1->GetRepeatedDouble(*msg1, field1, i);
        auto v2 = ref2->GetRepeatedDouble(*msg2, field2, i);
        /// @todo compare double
        if (v1 < v2) {
          result = -1;
        } else if (v1 > v2) {
          result = 1;
        }
      }
      break;
    case FieldDescriptor::CPPTYPE_FLOAT:
      for (int i = 0; i < size && result == 0; ++i) {
        auto v1 = ref1->GetRepeatedFloat(*msg1, field1, i);
        auto v2 = ref2->GetRepeatedFloat(*msg2, field2, i);
        /// @todo compare double
        if (v1 < v2) {
          result = -1;
        } else if (v1 > v2) {
          result = 1;
        }
      }
      break;
    case FieldDescriptor::CPPTYPE_BOOL:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, Bool);
      break;
    case FieldDescriptor::CPPTYPE_ENUM:
      COMPARE_ARRAY_FIELD(msg1, msg2, field1, field2, Enum);
      break;
    case FieldDescriptor::CPPTYPE_MESSAGE:
      for (int i = 0; i < size && result == 0; ++ i) {
        result = compare(&ref1->GetMessage(*msg1, field1), &ref2->GetMessage(*msg2, field2));
      }
      break;
    default:
      LOG(ERROR)<< "The type of protobuf is not supported";
      result = 0;
      break;
    }
  }

  if (result == 0) {
    if (size1 < size2) {
      return -1;
    } else if (size1 > size2) {
      return 1;
    }
  }

  return result;
}
Ejemplo n.º 29
0
/*!
 * \copydoc MetaIO::read()
 */
Metadata* MetaIOMP4::read(const QString &filename)
{
    QString title, artist, album, genre;
    int year = 0, tracknum = 0, length = 0;
    bool compilation = false;

    AVFormatContext* p_context = NULL;
    AVInputFormat* p_inputformat = NULL;

    QByteArray local8bit = filename.toLocal8Bit();
    if ((avformat_open_input(&p_context, local8bit.constData(),
                             p_inputformat, NULL) < 0))
    {
        return NULL;
    }

    if (avformat_find_stream_info(p_context, NULL) < 0)
        return NULL;

#if 0
    //### Debugging, enable to dump a list of all field names/values found

    AVDictionaryEntry *tag = av_dict_get(p_context->metadata, "\0", NULL,
                                         AV_METADATA_IGNORE_SUFFIX);
    while (tag != NULL)
    {
        LOG(VB_GENERAL, LOG_DEBUG, QString("Tag: %1 Value: %2")
                .arg(tag->key) .arg(QString::fromUtf8(tag->value)));
        tag = av_dict_get(p_context->metadata, "\0", tag,
                          AV_METADATA_IGNORE_SUFFIX);
    }
    //####
#endif

    title = getFieldValue(p_context, "title");
    if (title.isEmpty())
    {
        readFromFilename(filename, artist, album, title, genre, tracknum);
    }
    else
    {
        title = getFieldValue(p_context, "title");
        artist = getFieldValue(p_context, "author");
        // Author is the correct fieldname, but
        // we've been saving to artist for years
        if (artist.isEmpty())
            artist = getFieldValue(p_context, "artist");
        album = getFieldValue(p_context, "album");
        year = getFieldValue(p_context, "year").toInt();
        genre = getFieldValue(p_context, "genre");
        tracknum = getFieldValue(p_context, "track").toInt();
        compilation = getFieldValue(p_context, "").toInt();
        length = getTrackLength(p_context);
    }

    metadataSanityCheck(&artist, &album, &title, &genre);

    Metadata *retdata = new Metadata(filename,
                                     artist,
                                     compilation ? artist : "",
                                     album,
                                     title,
                                     genre,
                                     year,
                                     tracknum,
                                     length);

    retdata->setCompilation(compilation);

    avformat_close_input(&p_context);

    return retdata;
}
Ejemplo n.º 30
0
// this function adds new object to structure
TValObjPtrs* addValObj( vhpiHandleT _hNewHandle, TValObjPtrs* _pActualPointer, int _nActualSize )
{								

	TValObjPtrs hNewHandle;
	hNewHandle.hHdl = _hNewHandle;
	hNewHandle.vValue = getFieldValue( _hNewHandle );
	hNewHandle.nIndex = _nActualSize;
	hNewHandle.nType = 0;
	for ( int i = 0; i < 10; i++ )
	{
		hNewHandle.enumOnes[i] = -1;
		hNewHandle.enumZeros[i] = -1;
	}	
	hNewHandle.enumMin = 2147483647;
	hNewHandle.enumMax = 0;
	hNewHandle.szName = strdup( (char*)vhpi_get_str( vhpiNameP, _hNewHandle ) );
	hNewHandle.pBoolVar = new bool;
	hNewHandle.pIntVar = new int;
	hNewHandle.pRealVar = new double;	
	hNewHandle.pUserVars = NULL;	
	if ( _hNewHandle )
	{
		if ( ( hNewHandle.vValue->format >= vhpiEnumVecVal ) && ( hNewHandle.vValue->format <= vhpiRealVecVal ) )
		{																 
		// if array type ports, when numElems is defined
			hNewHandle.pBoolVecVar = new bool [hNewHandle.vValue->numElems];
			hNewHandle.pIntVecVar = new int [hNewHandle.vValue->numElems];
			hNewHandle.pRealVecVar = new double [hNewHandle.vValue->numElems];
		}
		else
		{
			hNewHandle.pBoolVecVar = new bool;
			hNewHandle.pIntVecVar = new int;
			hNewHandle.pRealVecVar = new double;
		}

		// detect binary logic enum types to enable numerical conversions
		if ( ( hNewHandle.vValue->format == vhpiEnumVal ) || ( hNewHandle.vValue->format == vhpiEnumVecVal ) )
		{			
			vhpiHandleT hLiteralIt = NULL;
			vhpiHandleT hLiteralHdl = NULL;
			vhpiHandleT hTypeHdl = NULL;
			int nTypeIndex = 0;
			int nOnesIndex = 0; 
			int nZerosIndex = 0;
													   
			// get handle to object type													   
			hTypeHdl = vhpi_handle( vhpiBaseType, _hNewHandle );
			// iterate on all literals of scalar type
			if (( hLiteralIt = vhpi_iterator( vhpiEnumLiterals, hTypeHdl ) ));
			// iterate on all literals of array's element type
			else (( hLiteralIt = vhpi_iterator( vhpiEnumLiterals, vhpi_handle( vhpiElemSubtype, hTypeHdl ) ) ));
			if ( hLiteralIt ) 
				while (( hLiteralHdl = vhpi_scan( hLiteralIt ) ))
				{								   
					// get literal string value	   
					char* szStrVal;
					szStrVal = strdup( (char*)vhpi_get_str( vhpiStrValP, hLiteralHdl ) );
					// get its position (index) in enum type
					nTypeIndex = vhpi_get( vhpiPositionP, hLiteralHdl );
					// set the limits of indexes in enum type
					if ( nTypeIndex > hNewHandle.enumMax )
						hNewHandle.enumMax = nTypeIndex;
					if ( nTypeIndex < hNewHandle.enumMin )
						hNewHandle.enumMin = nTypeIndex;
					// check if literal string value belongs to binary logic values set
					if ( ( strcmp( szStrVal, "1" ) == 0 ) || ( strcmp( szStrVal, "H" ) == 0 ) )
						// store indexes of literals treated as one in numeric calculations
						hNewHandle.enumOnes[nOnesIndex++] = nTypeIndex;
					else if ( ( strcmp( szStrVal, "0" ) == 0 ) || ( strcmp( szStrVal, "L" ) == 0 ) )
						// store indexes of literals treated as zero in numeric calculations
						hNewHandle.enumZeros[nZerosIndex++] = nTypeIndex;
					free( szStrVal );
				}			  
			else 
				vhpi_printf( "addVAlObj(): No enum literals found.\n" );		
			// if type contains one and zero literals	
			if ( ( nZerosIndex != 0 ) && ( nOnesIndex != 0 ) )
				hNewHandle.nType = 1;																			   
			
			// release handles	 			
			vhpi_release_handle( hTypeHdl );
			vhpi_release_handle( hLiteralHdl );
		}
	}				  
	
	// reallocate array appended with new structure
	TValObjPtrs* hTempHandle;
	int index;	 
	// allocate memory for copy of actual handles array
	hTempHandle = new TValObjPtrs [_nActualSize+1];
	// copy array contents
	for ( index = 0; index < _nActualSize; index++ ) 
	{
		hTempHandle[index] = _pActualPointer[index];
	}
	// append array with new object handle
	hTempHandle[index++] = hNewHandle;
	// remove actual array from memory
	delete [] _pActualPointer ;
	// allocate memory for new actual array
	_pActualPointer = new TValObjPtrs [_nActualSize+1];
	// copy array contents from temp array
	for ( index = 0; index < _nActualSize + 1; index++ )
	{
		_pActualPointer[index] = hTempHandle[index];
	}								  	  
	// remove temp array															  
	delete [] hTempHandle;
	return _pActualPointer;
}