void BtLineEdit::setText( BeerXMLElement* element, int precision ) { double amount = 0.0; QString display; if ( _section.isEmpty() ) initializeSection(); if ( _property.isEmpty() ) initializeProperties(); if ( _type == STRING ) display = element->property(_property.toLatin1().constData()).toString(); else if ( element->property(_property.toLatin1().constData()).canConvert(QVariant::Double) ) { // Get the amount bool ok = false; QString tmp = element->property(_property.toLatin1().constData()).toString(); amount = Brewtarget::toDouble(tmp, &ok); if ( !ok ) Brewtarget::logW( QString("BtLineEdit::setText(BeerXMLElement*,int) could not convert %1 to double").arg(tmp) ); display = displayAmount(amount, precision); } else { display = "?"; } QLineEdit::setText(display); }
int insertProperty(const char *key, void* value) { #ifdef SDFAPIONLY /* SDFSetPropery may be called before loadProperties, initialize the hash here in this case */ if (!_sdf_globalPropertiesMap) { initializeProperties(); } #endif if (strcmp(key, "ZS_LOG_LEVEL") == 0) set_log_level(value); return ((SDF_TRUE == HashMap_put(_sdf_globalPropertiesMap, key, value)) ? 0 : 1); }
double BtLineEdit::toSI(Unit::unitDisplay oldUnit,Unit::unitScale oldScale,bool force) { UnitSystem* temp; Unit* works; Unit::unitDisplay dspUnit = oldUnit; Unit::unitScale dspScale = oldScale; if ( _section.isEmpty() ) initializeSection(); if ( _property.isEmpty() ) initializeProperties(); // If force is set, just use what is provided in the call. If we are // not forcing the unit & scale, we need to read the configured properties if ( ! force ) { // If the display unit is forced, use this unit the default one. if ( _forceUnit != Unit::noUnit ) dspUnit = _forceUnit; else dspUnit = (Unit::unitDisplay)Brewtarget::option(_property, Unit::noUnit, _section, Brewtarget::UNIT).toInt(); dspScale = (Unit::unitScale)Brewtarget::option(_property, Unit::noUnit, _section, Brewtarget::SCALE).toInt(); } // Find the unit system containing dspUnit temp = Brewtarget::findUnitSystem(_units,dspUnit); if ( temp ) { // If we found it, find the unit referred by dspScale works = temp->scaleUnit(dspScale); if (! works ) // If we didn't find the unit, default to the UnitSystem's default // unit works = temp->unit(); // get the qstringToSI() from the unit system, using the found unit. // Force the issue in qstringToSI() unless dspScale is Unit::noScale. return temp->qstringToSI(text(), works, dspScale != Unit::noScale); } else if ( _type == STRING ) return 0.0; // If all else fails, simply try to force the contents of the field to a // double. This doesn't seem advisable? bool ok = false; double amt = Brewtarget::toDouble(text(), &ok); if ( ! ok ) Brewtarget::logW( QString("BtLineEdit::toSI : could not convert %1 to double").arg(text()) ); return amt; }
void ServiceRegistrationImpl::setProperties(const osgi::ServiceProperties& dict) { osgi::ServiceProperties oldProps; { Lock l(*this); // Make sure registration is valid. if (!isValid_unlocked()) { throw osgi::IllegalStateException( "The service registration is no longer valid."); } // Remember old properties. oldProps = m_propMap; // Set the properties. initializeProperties(dict); } // Tell registry about it. m_registry->servicePropertiesModified(this, oldProps); }
int setProperty(const char *key, void* value) { #ifdef SDFAPIONLY /* SDFSetPropery may be called before loadProperties, initialize the hash here in this case */ if (!_sdf_globalPropertiesMap) { initializeProperties(); } #endif if (strcmp(key, "ZS_LOG_LEVEL") == 0) set_log_level(value); if (SDF_TRUE != HashMap_put(_sdf_globalPropertiesMap, key, value)) { void *p = HashMap_replace(_sdf_globalPropertiesMap, key, value); if (p) { plat_free(p); return 0; } else { return 1; } } return 0; }
ServiceRegistrationImpl::ServiceRegistrationImpl(ServiceRegistry* registry, osgi::Bundle* bundle, const std::map<std::string,ServiceHandle>& svcHandles, ServiceType svcType, long int serviceId, const osgi::ServiceProperties& dict ) : m_registry(registry), m_bundle(bundle), m_svcHandles(svcHandles), m_svcType(svcType), m_serviceId(serviceId), m_isUnregistering(false) { for(std::map<std::string,ServiceHandle>::const_iterator i = svcHandles.begin(); i != svcHandles.end(); ++i) { if (i->second.f_CInterface) { // This reference is the "standard" reference for this // service and will always be returned by getReference(std::string). osgi::ServiceReferenceBase ref(new ServiceReferenceImpl(i->first, false, this)); m_cRefs.insert(std::make_pair(i->first, ref)); m_cInterfaces.push_back(i->first); } if (i->second.f_CppInterface) { // This reference is the "standard" reference for this // service and will always be returned by getReference(std::string). osgi::ServiceReferenceBase ref(new ServiceReferenceImpl(i->first, true, this)); m_cppRefs.insert(std::make_pair(i->first, ref)); m_cppInterfaces.push_back(i->first); } } // m_factory = (m_svcObj instanceof ServiceFactory) // ? (ServiceFactory) m_svcObj : null; initializeProperties(dict); }
QString BtLineEdit::displayAmount( double amount, int precision) { Unit::unitDisplay unitDsp; Unit::unitScale scale; if ( _section.isEmpty() ) initializeSection(); if ( _property.isEmpty() ) initializeProperties(); if ( _forceUnit != Unit::noUnit ) unitDsp = _forceUnit; else unitDsp = (Unit::unitDisplay)Brewtarget::option(_property, Unit::noUnit, _section, Brewtarget::UNIT).toInt(); scale = (Unit::unitScale)Brewtarget::option(_property, Unit::noScale, _section, Brewtarget::SCALE).toInt(); // I find this a nice level of abstraction. This lets all of the setText() // methods make a single call w/o having to do the logic for finding the // unit and scale. return Brewtarget::displayAmount(amount, _units, precision, unitDsp, scale); }
void BtLineEdit::lineChanged(Unit::unitDisplay oldUnit, Unit::unitScale oldScale) { // This is where it gets hard double val = -1.0; QString amt; bool force = false; bool ok = false; // editingFinished happens on focus being lost, regardless of anything // being changed. I am hoping this short circuits properly and we do // nothing if nothing changed. if ( sender() == this && ! isModified() ) { return; } // If we are here because somebody else sent the signal (ie, a label) or we // generated the signal but nothing has changed then don't try to guess the // units. if ( sender() != this ) { force = true; } if ( _section.isEmpty() ) initializeSection(); if ( _property.isEmpty() ) initializeProperties(); if (text().isEmpty()) { return; } // The idea here is we need to first translate the field into a known // amount (aka to SI) and then into the unit we want. switch( _type ) { case MASS: case VOLUME: case TEMPERATURE: case TIME: val = toSI(oldUnit,oldScale,force); amt = displayAmount(val,3); break; case DENSITY: case COLOR: val = toSI(oldUnit,oldScale,force); amt = displayAmount(val,0); break; case STRING: amt = text(); break; case GENERIC: default: val = Brewtarget::toDouble(text(),&ok); if ( ! ok ) Brewtarget::logW( QString("BtLineEdit::lineChanged: failed to convert %1 toDouble").arg(text()) ); amt = displayAmount(val); } QLineEdit::setText(amt); if ( ! force ) { emit textModified(); } }
int loadProperties(const char *path_arg) { #ifndef SDFAPIONLY /* In SDF library the hash can be initialized already by SDFSetPropery API*/ if (NULL != _sdf_globalPropertiesMap) { return 0; } #endif int ret = 0; const char *path = NULL; path = path_arg; if (!path) return 0; FILE *fp = fopen(path, "r"); if (!fp) { plat_log_msg(21756, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_ERROR, "Reading properties file '%s' has an error!\n", path); return -1; } if (!_sdf_globalPropertiesMap) { initializeProperties(); } char *line = (char *) plat_alloc(2048), *beg, *str, *key, *val; while(fgets(line, 2048, fp)) { // aah... really needed Boost here beg = line; while(' ' == *beg) { // trim beginning beg++; } if('#' == *beg || '\0' == *beg || '\n' == *beg) { // search for comment continue; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get key str++; } if (str-beg) { key = strndup(beg, str-beg); } else { continue; } beg = str++; while(' ' == *beg || '=' == *beg) { // trim beginning beg++; } str = beg; while('=' != *str && '\0' != *str && ' ' != *str && '\n' != *str) { // get value str++; } if (str-beg) { val = strndup(beg, str-beg); } else { free(key); continue; } #ifdef SDFAPIONLY /* in SDF library properties from file override properties set in runtime using SDFSetProperty */ setProperty(key, val); #else if (0 != insertProperty(key, val)) { ret--; plat_log_msg(21757, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_ERROR, "Parsed property error (ret:%d)('%s', '%s')", ret, key, val); } #endif /** * XXX: drew 2008-12-17 It would be better to log at the point of use * so we can output whether the default value was being used; but * this will get us the current settings in Patrick's memcached * runs. */ if (ZS_log_level <= PLAT_LOG_LEVEL_TRACE_LOW) { plat_log_msg(21758, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_TRACE_LOW, "Parsed property ('%s', '%s')", key, val); } } if (ZS_log_level <= PLAT_LOG_LEVEL_TRACE_LOW) { plat_log_msg(70124, PLAT_LOG_CAT_PRINT_ARGS, PLAT_LOG_LEVEL_TRACE_LOW, "Read from properties file '%s'", path); } fclose(fp); plat_free(line); return (ret); }
CompositeMobilityTensor::CompositeMobilityTensor(const InputParameters & parameters) : CompositeTensorBase<RealTensorValue>(parameters) { _M_name = getParam<MaterialPropertyName>("M_name"); initializeProperties(); }
X509Certificate::X509Certificate(const FB::BrowserHostPtr& host, std::string name) : JSAPIAuto(name), m_host(host) { initializeProperties(); }