Пример #1
0
void        Properties::setProperty( QString propertyName, const QDateTime& propertyDateTime, QVariant propertyValue )
{
    //qDebug( ) << "setProperty(" << propertyName << " " << propertyDateTime.toString( ) << " " << propertyValue.toString( );
    if ( !hasProperty( propertyName ) )
        addProperty( propertyName, propertyValue );
    if ( hasProperty( propertyName ) ) // Test is property exists or new property creation was successfull
    {
        TimeValueMap* timeValueMap = nullptr;
        if ( !_propertiesTimeValueMap.contains( propertyName ) )
        {
            timeValueMap = new QMap< QDateTime, QVariant >( );
            _propertiesTimeValueMap.insert( propertyName, timeValueMap );
        }
        else timeValueMap = _propertiesTimeValueMap.value( propertyName, nullptr );

        Q_ASSERT( timeValueMap != nullptr );
        timeValueMap->insert( propertyDateTime, propertyValue );

        // First and last initialization
        if ( !_last.isValid( ) )
            _last = propertyDateTime;
        if ( !_first.isValid( ) )
            _first = propertyDateTime;

        if ( propertyDateTime > _last ) // Update object date time interval
            _last = propertyDateTime;
        else if ( propertyDateTime < _first )
            _first = propertyDateTime;
    }
}
Пример #2
0
void Demultiplexer::dataChanged()
{
	if ( hasProperty("numInput") && dataInt("numInput") != -1 )
	{
		int addressSize = int( std::ceil( std::log( (double)dataInt("numInput") ) / std::log(2.0) ) );
		property("numInput")->setValue(-1);
		
		if ( addressSize < 1 )
			addressSize = 1;
		else if ( addressSize > 8 )
			addressSize = 8;
		
		// This function will get called again when we set the value of numInput
		property("addressSize")->setValue(addressSize);
		return;
	}
	
	if ( hasProperty("numInput") )
	{
		m_variantData["numInput"]->deleteLater();
		m_variantData.remove("numInput");
	}
	
	initPins( unsigned(dataInt("addressSize")) );
}
void TCPUnixAccountHandler::loadProperties()
{
	UT_DEBUGMSG(("TCPUnixAccountHandler::loadProperties()\n"));

	bool serve = getProperty("server") == "";

	if (server_button && GTK_IS_TOGGLE_BUTTON(server_button))
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(server_button), serve);

	if (client_button && GTK_IS_TOGGLE_BUTTON(client_button))
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(client_button), !serve);

	if (server_entry && GTK_IS_ENTRY(server_entry))
		gtk_entry_set_text(GTK_ENTRY(server_entry), getProperty("server").c_str());

	int port = DEFAULT_TCP_PORT;
	try {
		if (hasProperty("port"))
			port = boost::lexical_cast<int>(getProperty("port"));
	} catch (boost::bad_lexical_cast &) {
		UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
	}
	if (port_button && GTK_IS_ENTRY(port_button))
		gtk_spin_button_set_value(GTK_SPIN_BUTTON(port_button), port);

	if (allow_all_button && GTK_IS_TOGGLE_BUTTON(allow_all_button))
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(allow_all_button), hasProperty("allow-all") ? getProperty("allow-all") == "true" : false);

	bool autoconnect = hasProperty("autoconnect") ? getProperty("autoconnect") == "true" : true;
	if (autoconnect_button && GTK_IS_TOGGLE_BUTTON(autoconnect_button))
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoconnect_button), autoconnect);
}
Пример #4
0
/** Return the run start time as given by the 'start_time' or 'run_start'
 * property.
 *  'start_time' is tried first, falling back to 'run_start' if the former isn't
 * found.
 *  @returns The start time of the run
 *  @throws std::runtime_error if neither property is defined
 */
const Kernel::DateAndTime LogManager::startTime() const {
  const std::string start_prop("start_time");
  if (hasProperty(start_prop)) {
    try {
      DateAndTime start_time(getProperty(start_prop)->value());
      if (start_time != DateAndTimeHelpers::GPS_EPOCH) {
        return start_time;
      }
    } catch (std::invalid_argument &) { /*Swallow and move on*/
    }
  }

  const std::string run_start_prop("run_start");
  if (hasProperty(run_start_prop)) {
    try {
      DateAndTime start_time(getProperty(run_start_prop)->value());
      if (start_time != DateAndTimeHelpers::GPS_EPOCH) {
        return start_time;
      }
    } catch (std::invalid_argument &) { /*Swallow and move on*/
    }
  }

  throw std::runtime_error("No valid start time has been set for this run.");
}
Пример #5
0
bool    Properties::duplicateTo( qps::Properties* destination ) const
{
    if ( destination == nullptr )
        return false;
    if ( getTarget() == nullptr )
        return false;

    // Duplicate static properties
    int staticPropertyCount = getTarget()->metaObject( )->propertyCount( );
    for ( int s = 0; s < staticPropertyCount; s++ ) {
        QMetaProperty metaProperty = getTarget()->metaObject( )->property( s );
        const char* propertyName = metaProperty.name( );
        if ( propertyName == nullptr )
            continue;
        if ( std::strcmp( propertyName, "target" ) == 0 )    // Do not modify destination target
            continue;
        QVariant srcValue = getTarget()->property( propertyName );
        if ( hasProperty( propertyName ) && metaProperty.isWritable( ) )
            destination->setProperty( propertyName, srcValue );
        else
            destination->addDynamicProperty( propertyName, srcValue );
    }

    // Duplicate dynamic properties
    QList< QByteArray > dynamicProperties = getTarget()->dynamicPropertyNames( );
    for ( int d = 0; d < dynamicProperties.size( ); d++ ) {
        QString propertyName = dynamicProperties.at( d );
        QVariant srcValue = getTarget()->property( propertyName.toLatin1( ) );
        if ( hasProperty( propertyName ) )
            destination->setProperty( propertyName, srcValue );
        else
            destination->addDynamicProperty( propertyName, srcValue );
    }
    return true;
}
Пример #6
0
// also handle an xlfd with %d for size?
static char*
makeFontOfSize(char *font, int size, char *fallback)
{
    FcPattern *pattern;
    char *result;

    if (font[0]=='-') {
        char *fname;

        fname = fixXLFD(font, size);
        pattern = XftXlfdParse(fname, False, False);
        wfree(fname);
    } else {
        pattern = FcNameParse(font);
    }

    //FcPatternPrint(pattern);
    if (size > 0) {
        FcPatternDel(pattern, "pixelsize");
        FcPatternAddDouble(pattern, "pixelsize", (double)size);
    } else if (size==0 && !hasProperty(pattern, "size") &&
               !hasProperty(pattern, "pixelsize")) {
        FcPatternAddDouble(pattern, "pixelsize", (double)DEFAULT_SIZE);
    }

    if (fallback && !hasPropertyWithStringValue(pattern, "family", fallback)) {
        FcPatternAddString(pattern, "family", fallback);
    }

    result = FcNameUnparse(pattern);
    FcPatternDestroy(pattern);

    return result;
}
Пример #7
0
	void MaterialInstance::create (Platform* platform)
	{
		mMaterial = platform->createMaterial(mName);

		if (hasProperty ("shadow_caster_material"))
			mMaterial->setShadowCasterMaterial (retrieveValue<StringValue>(getProperty("shadow_caster_material"), NULL).get());

		if (hasProperty ("lod_values"))
			mMaterial->setLodLevels (retrieveValue<StringValue>(getProperty("lod_values"), NULL).get());
	}
Пример #8
0
/*!
    \internal
    Return true if the format has number format.
 */
bool Format::hasNumFmtData() const
{
    if (!d)
        return false;

    if (hasProperty(FormatPrivate::P_NumFmt_Id)
            || hasProperty(FormatPrivate::P_NumFmt_FormatCode)) {
        return true;
    }
    return false;
}
Пример #9
0
//
// Convert javascript's json object to libsvm's svm_node
//
struct svm_node* SVMPredict::FromJsonObj(v8::Local<v8::Object> obj){
  //v8::Isolate* isolate = v8::Isolate::GetCurrent();
  //v8::EscapableHandleScope scope(isolate);
#if defined(PROCESS_DEBUG)
  log("is called.");
#endif
  struct svm_node *prob_node = nullptr;
  v8::Local<v8::Value> id;
  v8::Local<v8::Object> values;
  bool ok;
  if (hasProperty(obj,std::string("id")) &&
      hasProperty(obj,std::string("values"))){

    id = obj->Get(ToV8<std::string>(std::string("id")));
    values = v8::Local<v8::Object>::Cast(
                                         obj->Get(ToV8<std::string>(std::string("values"))));

    if ( !values->IsObject() ){
      ThrowError("Values field seem not to be json object.");
      //return scope.Close(v8::Null());
      return nullptr;
    }

    v8::Local<v8::Array> v = values->GetOwnPropertyNames();
    int length = v->Length();
    //#if PROCESS_DEBUG
    //  std::cout<< "feature length: " <<  length << std::endl;
    //#endif
    prob_node =
    reinterpret_cast<svm_node*>(malloc((length+1) * sizeof(struct svm_node)));
    //(struct svm_node *) malloc ((length+1) * sizeof(struct svm_node));
    if (prob_node == NULL){
      std::cout<<"Failed to allocate memory for svm_node"<<std::endl;
      return nullptr;
    }

    for(int i=0; i<length; i++){
      prob_node[i].index = FromV8<int32_t>(v->Get(i),&ok);
      prob_node[i].value = FromV8<double>(values->Get(v->Get(i)),&ok);
      //std::cout<< "index " << i <<" :" << prob_node[i].index<< ", value: " << prob_node[i].value << std::endl;
    }
    prob_node[length].index = -1;
    struct svm_node *p = prob_node;
    printf("In FromJsonObj:");
    while(p->index != -1) {
      printf("%d:%.8g ",p->index,p->value);
      p++;
    }
    printf("\n");
    return prob_node;
  }
  return nullptr;
}
Пример #10
0
bool PlyReader::requestProperty(const std::string& elementName,
								const std::string& propertyName,
								int dataType, int dataOffset,
								int countType, int countOffset)
{
	SURGSIM_ASSERT(isValid()) << "'" << m_filename << "' is an invalid .ply file";

	SURGSIM_ASSERT(hasElement(elementName)) <<
		"The element <" << elementName << "> has not been requested yet, you cannot access properties for it";
	SURGSIM_ASSERT(hasProperty(elementName, propertyName)) <<
		"The requested property <" << propertyName << "> cannot be found in element <" << elementName << ">.";



	bool result = false;

	bool scalar = isScalar(elementName, propertyName);

	bool wantScalar = (countType == 0);
	if (wantScalar && !scalar)
	{
		SURGSIM_FAILURE() << "Trying to access a list property as a scalar." <<
			"for element <" << elementName << "> and property <" << propertyName << ">.";
	}
	else if (!wantScalar && scalar)
	{
		SURGSIM_FAILURE() << "Trying to access a scalar property as a list." <<
			"for element <" << elementName << "> and property <" << propertyName << ">.";
	}

	if (hasProperty(elementName, propertyName) && (scalar == wantScalar))
	{
		auto itBegin = std::begin(m_requestedElements[elementName].requestedProperties);
		auto itEnd = std::end(m_requestedElements[elementName].requestedProperties);

		bool doAdd = std::find_if(itBegin, itEnd,
			[propertyName](PropertyInfo p){return p.propertyName == propertyName;}) == itEnd;

		if (doAdd)
		{
			PropertyInfo info;
			info.propertyName = propertyName;
			info.dataType = m_data->types[dataType];
			info.dataOffset = dataOffset;
			info.countType = m_data->types[countType];
			info.countOffset = countOffset;
			m_requestedElements[elementName].requestedProperties.push_back(info);
			result = true;
		}
	}

	return result;
}
Пример #11
0
/*!
 * Turn on/off shrink to fit base on \a shink.
 */
void Format::setShrinkToFit(bool shink)
{
    if (shink && hasProperty(FormatPrivate::P_Alignment_Wrap))
        clearProperty(FormatPrivate::P_Alignment_Wrap);

    if (shink && hasProperty(FormatPrivate::P_Alignment_AlignH)) {
        HorizontalAlignment hl = horizontalAlignment();
        if (hl == AlignHFill || hl == AlignHJustify || hl == AlignHDistributed)
            setHorizontalAlignment(AlignLeft);
    }

    setProperty(FormatPrivate::P_Alignment_ShinkToFit, shink, false);
}
Пример #12
0
/**
*	_getOptionArgs
*
*		Returns the address of an OPTIONS struct with all supported options decoded. 
*		Two types of optional parameters are supported, that is, 'queryOptions' and
*		'options'.
*
*			query-options	:== 'queryOptions' '=' '{' (object (',' object)*))? '}'
*			options			:== 'options' '=' '[' (string (',' string)*)? ']'
*			object			:== '{' (property (',' property)*)? '}'
*			property		:== string ':' value
*			array			:== '[' (value (',' value)*)? ']'
*			value			:== string | number | object | array | 'true' | 'false'
*			string			:== '"' char* '"'
*
*		Example:
*
*			queryOptions={"deep":true, "ignoreCase":false}
*			options=["dirsOnly", "showHiddenFiles"]
*
*	@note:	Strict JSON encoding rules are enforced when decoding parameters.
*
*	@param	pGET			Address of a variable data type. (php style $_GET variable)
*	@param	piResult		Address integer receiving the final result code:
*							HTTP_V_OK, HTTP_V_BAD_REQUEST or HTTP_V_SERVER_ERROR
*
*	@return		On success the address of an OPTIONS struct otherwise NULL
**/
static OPTIONS * _getOptionArgs( DATA *pGET, int *piResult )
{
	OPTIONS	*pOptions;
	DATA	*ptQueryOptions,
			*ptOptions;
			
	if( (pOptions = (OPTIONS *)calloc(1, sizeof(OPTIONS))) )
	{
		if( hasProperty( "options", pGET ) )
		{
			if( (ptOptions = jsonDecode( varGetProperty("options", pGET))) )
			{
				pOptions->bShowHiddenFiles = varInArray("showHiddenFiles", ptOptions);
				pOptions->bDebug		   = varInArray("debug", ptOptions);

				destroy( ptOptions );
			}
			else // Ill formatted JSON array
			{
				cbtDebug( "options parameter is not a valid JSON object." );
				*piResult = HTTP_V_BAD_REQUEST;
				destroy( pOptions );
				return NULL;
			}
		}

		if( hasProperty( "queryOptions", pGET ) )
		{
			if( (ptQueryOptions = jsonDecode( varGetProperty("queryOptions", pGET))) )
			{
				pOptions->bIgnoreCase = (bool)varGet( varGetProperty("ignoreCase", ptQueryOptions) );
				pOptions->bDeep		  = (bool)varGet( varGetProperty("deep", ptQueryOptions) );
				destroy( ptQueryOptions );
			}
			else // Ill formatted JSON object
			{
				cbtDebug( "queryOptions parameter is not a valid JSON object." );
				*piResult = HTTP_V_BAD_REQUEST;
				destroy( pOptions );
				return NULL;
			}
		}
		*piResult = HTTP_V_OK;	// Success
	}
	else // Out of memory...
	{
		*piResult = HTTP_V_SERVER_ERROR;
	}
	return pOptions;
}
Пример #13
0
/*!
 * Set the horizontal alignment with the given \a align.
 */
void Format::setHorizontalAlignment(HorizontalAlignment align)
{
    if (hasProperty(FormatPrivate::P_Alignment_Indent)
            &&(align != AlignHGeneral && align != AlignLeft && align != AlignRight && align != AlignHDistributed)) {
        clearProperty(FormatPrivate::P_Alignment_Indent);
    }

    if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit)
            && (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) {
        clearProperty(FormatPrivate::P_Alignment_ShinkToFit);
    }

    setProperty(FormatPrivate::P_Alignment_AlignH, align, AlignHGeneral);
}
Пример #14
0
void Item::restoreFromItemData( const ItemData &itemData )
{
	move( itemData.x, itemData.y );
	if ( canResize() )
		setSize( itemData.size );
	
	Item *parentItem = p_itemDocument->itemWithID( itemData.parentId );
	if (parentItem)
		setParentItem(parentItem);
	else
		m_baseZ = itemData.z;
	
	//BEGIN Restore data
	const QStringMap::const_iterator stringEnd = itemData.dataString.end();
	for ( QStringMap::const_iterator it = itemData.dataString.begin(); it != stringEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const DoubleMap::const_iterator numberEnd = itemData.dataNumber.end();
	for ( DoubleMap::const_iterator it = itemData.dataNumber.begin(); it != numberEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const QColorMap::const_iterator colorEnd = itemData.dataColor.end();
	for ( QColorMap::const_iterator it = itemData.dataColor.begin(); it != colorEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	
	const BoolMap::const_iterator boolEnd = itemData.dataBool.end();
	for ( BoolMap::const_iterator it = itemData.dataBool.begin(); it != boolEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( QVariant( it.value() /*, 0*/ ) );
	}
	
	const QBitArrayMap::const_iterator rawEnd = itemData.dataRaw.end();
	for ( QBitArrayMap::const_iterator it = itemData.dataRaw.begin(); it != rawEnd; ++it )
	{
		if ( hasProperty(it.key()) )
			property( it.key() )->setValue( it.value() );
	}
	//END Restore Data
}
Пример #15
0
bool KisBrushBasedPaintOpSettings::paintIncremental()
{
    if (hasProperty("PaintOpAction")) {
        return (enumPaintActionType)getInt("PaintOpAction", WASH) == BUILDUP;
    }
    return true;
}
Пример #16
0
	void MaterialInstance::destroyAll ()
	{
		if (hasProperty("create_configuration"))
			return;
		mMaterial->removeAll();
		mTexUnits.clear();
	}
Пример #17
0
/*!
 * Enable the text wrap if \a wrap is true.
 */
void Format::setTextWarp(bool wrap)
{
    if (wrap && hasProperty(FormatPrivate::P_Alignment_ShinkToFit))
        clearProperty(FormatPrivate::P_Alignment_ShinkToFit);

    setProperty(FormatPrivate::P_Alignment_Wrap, wrap, false);
}
Пример #18
0
const std::string &Map::getName() const
{
    if (hasProperty("name"))
        return getProperty("name");

    return getProperty("mapname");
}
Пример #19
0
void Properties::setPoint(const std::string &name, const Point &value, bool warnDuplicates) {
	if (hasProperty(name) && warnDuplicates)
		SLog(EWarn, "Property \"%s\" has already been specified!", name.c_str());
	m_elements[name].type = EPoint;
	m_elements[name].v_point = value;
	m_elements[name].queried = false;
}
Пример #20
0
void Map::initializeOverlays()
{
    ResourceManager *resman = ResourceManager::getInstance();

    for (int i = 0;
         hasProperty("overlay" + toString(i) + "image");
         i++)
    {
        const std::string name = "overlay" + toString(i);

        Image *img = resman->getImage(getProperty(name + "image"));
        const float speedX = getFloatProperty(name + "scrollX");
        const float speedY = getFloatProperty(name + "scrollY");
        const float parallax = getFloatProperty(name + "parallax");
        const bool keepRatio = getBoolProperty(name + "keepratio");

        if (img)
        {
            mOverlays.push_back(
                    new AmbientOverlay(img, parallax, speedX, speedY, keepRatio));

            // The AmbientOverlay takes control over the image.
            img->decRef();
        }
    }
}
void InterfacePointerValue::put(const std::string& name, Value* value, int attributes)
{
    InterfacePrototypeValue* proto = static_cast<InterfacePrototypeValue*>(prototype);
    AttributeSetterValue* setter;

    if (!canPut(name))
    {
        return;
    }
    if (hasProperty(name))
    {
        ObjectValue::put(name, value, attributes);
    }
    else if ((setter = static_cast<AttributeSetterValue*>(proto->getOpObject(InterfacePrototypeValue::IndexSetter)))
             && isIndexAccessor(name))
    {
        setter->put(this, name, value);
    }
    else if ((setter = static_cast<AttributeSetterValue*>(proto->getOpObject(InterfacePrototypeValue::NameSetter))))
    {
        setter->put(this, name, value);
    }
    else
    {
        ObjectValue::put(name, value, attributes);
    }
}
Пример #22
0
void Properties::setInteger(const std::string &name, int value, bool warnDuplicates) {
	if (hasProperty(name) && warnDuplicates)
		SLog(EWarn, "Property \"%s\" has already been specified!", name.c_str());
	m_elements[name].type = EInteger;
	m_elements[name].v_long = value;
	m_elements[name].queried = false;
}
/**
 * \brief set a property
 */
void	Properties::setProperty(const std::string& name,
		const std::string& value) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "adding %s -> %s",
		name.c_str(), value.c_str());
	properties.insert(std::make_pair(name, value));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "has value: %s",
		hasProperty(name) ? "YES" : "NO");
}
Пример #24
0
	void Event::setProperty(const string inName, const string inValue) {
		if ( hasProperty(inName) ) {
			mProperties.find(inName)->second = inValue;
			return;
		}

		mProperties.insert( make_pair<string, string>(inName, inValue) );
		nrProperties++;
	}
TITANIUM_FUNCTION(Properties, hasProperty)
{
    ENSURE_STRING_AT_INDEX(property, 0);

    const auto js_context = this_object.get_context();
    const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>();

    return js_context.CreateBoolean(object_ptr->hasProperty(property));
}
Пример #26
0
Spectrum Properties::getSpectrum(const std::string &name, const Spectrum &defVal) const {
	if (!hasProperty(name))
		return defVal;
	std::map<std::string, Element>::const_iterator it = m_elements.find(name);
	if ((*it).second.type != ESpectrum)
		SLog(EError, "Property \"%s\" has wrong type", name.c_str());
	(*it).second.queried = true;
	return (*it).second.v_spectrum;
}
Пример #27
0
int Properties::getInteger(const std::string &name, int defVal) const {
	if (!hasProperty(name))
		return defVal;
	std::map<std::string, Element>::const_iterator it = m_elements.find(name);
	if ((*it).second.type != EInteger)
		SLog(EError, "Property \"%s\" has wrong type", name.c_str());
	(*it).second.queried = true;
	return (int) (*it).second.v_long;
}
Пример #28
0
bool Properties::getBoolean(const std::string &name, bool defVal) const {
	if (!hasProperty(name))
		return defVal;
	std::map<std::string, Element>::const_iterator it = m_elements.find(name);
	if ((*it).second.type != EBoolean)
		SLog(EError, "Property \"%s\" has wrong type", name.c_str());
	(*it).second.queried = true;
	return (*it).second.v_boolean;
}
Пример #29
0
Point Properties::getPoint(const std::string &name) const {
	if (!hasProperty(name))
		SLog(EError, "Property \"%s\" missing", name.c_str());
	std::map<std::string, Element>::const_iterator it = m_elements.find(name);
	if ((*it).second.type != EPoint)
		SLog(EError, "Property \"%s\" has wrong type", name.c_str());
	(*it).second.queried = true;
	return (*it).second.v_point;
}
Пример #30
0
/*!
 * \internal
 */
QColor Format::colorProperty(int propertyId, const QColor &defaultValue) const
{
    if (!hasProperty(propertyId))
        return defaultValue;

    const QVariant prop = d->property[propertyId];
    if (prop.userType() != qMetaTypeId<XlsxColor>())
        return defaultValue;
    return qvariant_cast<XlsxColor>(prop).rgbColor();
}