Ejemplo n.º 1
0
DataValue Database::Query::getValue(int column)
{
	if (_stmt == NULL) return DataValue::Void();

	switch (sqlite3_column_type(_stmt, column))
	{
	case SQLITE_INTEGER:				return sqlite3_column_int64(_stmt, column);

	case SQLITE_FLOAT:					return sqlite3_column_double(_stmt, column);

	case SQLITE_NULL:					return DataValue::Null();

	case SQLITE_BLOB:
		{ 
			const void* blob = sqlite3_column_blob(_stmt, column);
			size_t size = sqlite3_column_bytes(_stmt, column);

			if (size < sizeof(uint32) + sizeof(uint8))
				return DataValue(blob, size);

			// check DATA or ZDATA signature and try to convert to (or load) a DataValue
			uint32 signature = *(uint32*)blob;
			if (signature == NIT_DATA_SIGNATURE || signature == NIT_ZDATA_SIGNATURE)
			{
				DataValue blobValue(blob, size);

				try
				{
					uint8 type = ((uint8*)blob)[4];
					blobValue.convertTo((DataValue::Type)type);
				}
				catch (...)
				{
					// Conversion or load fail: return as just a plain blob
				}

				return blobValue;
			}

			// If signature doesn't tell it's a DataValue, return a plain blob
			return DataValue(blob, size);
		}

	case SQLITE3_TEXT:
		{
			const char* text = (const char*)sqlite3_column_text(_stmt, column);
			int len = sqlite3_column_bytes(_stmt, column);
			return DataValue(text, len);
		}

	default:							NIT_THROW(EX_NOT_SUPPORTED);
	}
}
Ejemplo n.º 2
0
void Database::Query::bindValue(int paramIndex, const DataValue& value)
{
	switch (value.getType())
	{
	case DataValue::TYPE_VOID:
	case DataValue::TYPE_NULL:			bindNull(paramIndex); break;

	case DataValue::TYPE_BOOL:			bind(paramIndex, DataValue(value).toInt()); break;
	case DataValue::TYPE_INT:			bind(paramIndex, value.getData<int>()); break;

	case DataValue::TYPE_INT64:			bind(paramIndex, value.getData<int64>()); break;

	case DataValue::TYPE_FLOAT:			bind(paramIndex, value.getData<float>()); break;
	case DataValue::TYPE_DOUBLE:		bind(paramIndex, value.getData<double>()); break;

	case DataValue::TYPE_STRING:		bind(paramIndex, value.getStringPtr(), value.getStringSize()); break;
	case DataValue::TYPE_BLOB:			bindBlob(paramIndex, value.getBlobPtr(), value.getBlobSize()); break;

	case DataValue::TYPE_TIMESTAMP:		bind(paramIndex, value.getData<Timestamp>().getUnixTime64()); break;

	// types which sqlite doesn't support natively are treated as blob
	case DataValue::TYPE_FLOAT2:		
	case DataValue::TYPE_FLOAT3:
	case DataValue::TYPE_FLOAT4:
	case DataValue::TYPE_FLOAT3X3:
	case DataValue::TYPE_FLOAT4X4:

	case DataValue::TYPE_VECTOR2:
	case DataValue::TYPE_VECTOR3:
	case DataValue::TYPE_VECTOR4:
	case DataValue::TYPE_QUAT:
	case DataValue::TYPE_MATRIX3:
	case DataValue::TYPE_MATRIX4:
		{ 
			DataValue copy(value); 
			size_t size; 
			const void* blob = copy.toBlob(&size); 
			bindBlob(paramIndex, blob, size); 
		} 
		break;

	case DataValue::TYPE_ARRAY:			bind(paramIndex, DataValue(value).toBuffer());
	case DataValue::TYPE_RECORD:		bind(paramIndex, DataValue(value).toBuffer());
	case DataValue::TYPE_OBJECT:		bind(paramIndex, DataValue(value).toBuffer());
	case DataValue::TYPE_BUFFER:		bind(paramIndex, value.getRef<MemoryBuffer>()); break;

	default:							NIT_THROW(EX_NOT_SUPPORTED);
	}
}
Ejemplo n.º 3
0
/**
 * Reads the value in the buffer from the specified offset and specified size.
 *
 * @param offset The offset where to read from.
 * @param amount The number of bytes to read.
 *
 * @return DataValue representing the read value.
 */
DataValue DataBuffer::read(std::size_t offset, std::size_t amount) const
{
	// Check of boundaries
	if (offset >= getSize())
		return DataValue();

	// Calculate amount of bytes to copy in case we can run out of buffer boundaries
	std::size_t bytesToCopy = offset + amount >= getSize() ? getSize() - offset : amount;
	std::vector<std::uint8_t> bytes;
	bytes.reserve(bytesToCopy);

	// Copy using back inserter
	std::copy(_data.begin() + offset, _data.begin() + offset + bytesToCopy, std::back_inserter(bytes));
	return DataValue(bytes);
}
Ejemplo n.º 4
0
 /// set the file path to the primary MS run (usually the mzML file obtained after data conversion from raw files)
 void FeatureMap::setPrimaryMSRunPath(const StringList& s)
 {
   if (!s.empty())
   {
     this->setMetaValue("spectra_data", DataValue(s));
   }
 }
Ejemplo n.º 5
0
/**
 * Reads the specific bits from the byte at the specified offset. Method also
 * access neighbour elements if bitCount overlaps current byte. No more than
 * 64 bits are read.
 *
 * @param byteOffset The offset of the byte.
 * @param bitOffset The bit from which to start reading. 0 is LSB.
 * @param bitCount The number of bits to read.
 *
 * @return DataValue representing the read value.
 */
DataValue DataBuffer::readBits(std::size_t byteOffset, std::uint8_t bitOffset, std::size_t bitCount) const
{
	if (byteOffset >= getSize())
		return DataValue();

	if (bitOffset >= 8)
		return DataValue();

	// We don't read more than 64 bits
	if (bitCount >= (sizeof(std::uint64_t) * 8))
		bitCount = 64;

	std::uint8_t currentByte = _data[byteOffset] >> bitOffset;
	std::size_t bitsWritten = 0;
	std::uint64_t val = 0;
	while (bitCount > 0)
	{
		// We take the current byte and mask it out so only required number of bits is taken into account
		// We then shift it right so it fits right position based on the amount of bits already read
		val |= static_cast<std::uint64_t>((currentByte & _getBitMask(bitCount))) << bitsWritten;

		// We now need to calculate how many bits we have written
		// If there is less than 8 bits left, use that count as number of bits we have written
		// Otherwise, calculate it with formula 8 - bitOffset
		if (bitOffset + bitCount < 8)
		{
			bitsWritten += bitCount;
			bitCount -= bitCount;
		}
		else
		{
			bitsWritten += 8 - bitOffset;
			bitCount -= 8 - bitOffset;
		}

		byteOffset++;
		if (byteOffset >= getSize())
			break;

		currentByte = _data[byteOffset];
		bitOffset = 0; // We must set bitOffset to 0 because we will be reading from this offset in all consecutive iterations 
	}

	return DataValue(val);
}
Ejemplo n.º 6
0
void PackageService::onInit()
{
	bool useAsyncLoading = DataValue(g_App->getConfig("async_loading", "false")).toBool();

	if (useAsyncLoading)
		_asyncLoader = new AsyncLoader(this);

	g_App->getClock()->channel()->bind(EVT::CLOCK, this, &PackageService::onClock);
	g_App->channel()->bind(EVT::SESSION_START, this, &PackageService::onSessionStart);
	g_App->channel()->bind(EVT::SESSION_STOP, this, &PackageService::onSessionStop);
	g_App->channel()->bind(EVT::SESSION_CHANGE, this, &PackageService::onSessionChange);

	InitSqliteVFS();
}
Ejemplo n.º 7
0
void InputService::onInit()
{
	float timerPriority = DataValue(g_App->getConfig("input_priority", "-100"));

	_timer = new TickTimer();
	g_App->getClock()->channel()->priority(timerPriority)->bind(EVT::CLOCK, _timer->sourceTimeHandler());

	_timer->channel()->bind(EVT::TICK, this, &InputService::onTick);

	_systemUser = new InputUser("$system", 0);
	_defaultUser = new InputUser("$default", 1);

	_frame = 0;
}
Ejemplo n.º 8
0
  void TOPPASResources::store(const QString& file_name)
  {
    Param save_param;

    for (Map<QString, QList<TOPPASResource> >::ConstIterator it = map_.begin(); it != map_.end(); ++it)
    {
      const String& key = String(it->first);
      const QList<TOPPASResource>& resource_list = it->second;
      StringList url_list;
      foreach(const TOPPASResource &res, resource_list)
      {
        url_list.push_back(String(res.getURL().toString()));
      }
      save_param.setValue(key + ":url_list", DataValue(url_list));
    }
void QuantitativeExperimentalDesign::mergeFeatureMaps_(FeatureMap<> & out, const String & experiment, StringList & file_paths)
{
    FeatureMap<> map;

    LOG_INFO << "Merge feature maps: " << endl;
    UInt counter = 1;
    for (StringList::Iterator file_it = file_paths.begin(); file_it != file_paths.end(); ++file_it, ++counter)
    {
        //load should clear the map
        FeatureXMLFile().load(*file_it, map);
        for (FeatureMap<>::iterator it = map.begin(); it != map.end(); ++it)
        {
            it->setMetaValue("experiment", DataValue(experiment));
        }
        out += map;
    }
}
Ejemplo n.º 10
0
  void CVMappingFile::startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const Attributes & attributes)
  {

    tag_ = String(sm_.convert(qname));

    if (tag_ == "CvReference")
    {
      // CvReference cvName="PSI-PI" cvIdentifier="PSI-PI"/>
      CVReference ref;
      ref.setName(attributeAsString_(attributes, "cvName"));
      ref.setIdentifier(attributeAsString_(attributes, "cvIdentifier"));
      cv_references_.push_back(ref);
      return;
    }

    if (tag_ == "CvMappingRule")
    {
      // id="R1" cvElementPath="/psi-pi:MzIdentML/psi-pi:AnalysisSoftwareList/psi-pi:AnalysisSoftware/pf:ContactRole/pf:role/pf:cvParam" requirementLevel="MUST"  scopePath="" cvTermsCombinationLogic="OR
      actual_rule_.setIdentifier(attributeAsString_(attributes, "id"));
      String element_path = attributeAsString_(attributes, "cvElementPath");
      if (strip_namespaces_)
      {
        vector<String> slash_split;
        element_path.split('/', slash_split);
        if (slash_split.empty())
        {
          slash_split.push_back(element_path);
        }
        element_path = "";
        for (vector<String>::const_iterator it = slash_split.begin(); it != slash_split.end(); ++it)
        {
          if (it->empty())
          {
            continue;
          }

          vector<String> split;
          it->split(':', split);
          if (split.empty())
          {
            element_path += "/" + *it;
          }
          else
          {
            if (split.size() == 2)
            {
              element_path += "/" + split[1];
            }
            else
            {
              fatalError(LOAD, String("Cannot parse namespaces of path: '") + element_path + "'");
            }
          }
        }
      }
      actual_rule_.setElementPath(element_path);
      CVMappingRule::RequirementLevel level = CVMappingRule::MUST;
      String lvl = attributeAsString_(attributes, "requirementLevel");
      if (lvl == "MAY")
      {
        level = CVMappingRule::MAY;
      }
      else
      {
        if (lvl == "SHOULD")
        {
          level = CVMappingRule::SHOULD;
        }
        else
        {
          if (lvl == "MUST")
          {
            level = CVMappingRule::MUST;
          }
          else
          {
            // throw Exception
          }
        }
      }

      actual_rule_.setRequirementLevel(level);

      actual_rule_.setScopePath(attributeAsString_(attributes, "scopePath"));
      CVMappingRule::CombinationsLogic logic = CVMappingRule::OR;
      String lgc = attributeAsString_(attributes, "cvTermsCombinationLogic");
      if (lgc == "OR")
      {
        logic = CVMappingRule::OR;
      }
      else
      {
        if (lgc == "AND")
        {
          logic = CVMappingRule::AND;
        }
        else
        {
          if (lgc == "XOR")
          {
            logic = CVMappingRule::XOR;
          }
          else
          {
            // throw Exception;
          }
        }
      }
      actual_rule_.setCombinationsLogic(logic);
      return;
    }

    if (tag_ == "CvTerm")
    {
      // termAccession="PI:00266" useTermName="false" useTerm="false" termName="role type" isRepeatable="true" allowChildren="true" cvIdentifierRef="PSI-PI"
      CVMappingTerm term;

      term.setAccession(attributeAsString_(attributes, "termAccession"));
      term.setUseTerm(DataValue(attributeAsString_(attributes, "useTerm")).toBool());

      String use_term_name;
      optionalAttributeAsString_(use_term_name, attributes, "useTermName");
      if (use_term_name != "")
      {
        term.setUseTermName(DataValue(use_term_name).toBool());
      }
      else
      {
        term.setUseTermName(false);
      }
      term.setTermName(attributeAsString_(attributes, "termName"));

      String is_repeatable;
      optionalAttributeAsString_(is_repeatable, attributes, "isRepeatable");
      if (is_repeatable != "")
      {
        term.setIsRepeatable(DataValue(is_repeatable).toBool());
      }
      else
      {
        term.setIsRepeatable(true);
      }
      term.setAllowChildren(DataValue(attributeAsString_(attributes, "allowChildren")).toBool());
      term.setCVIdentifierRef(attributeAsString_(attributes, "cvIdentifierRef"));

      actual_rule_.addCVTerm(term);
      return;
    }

    return;
  }
Ejemplo n.º 11
0
bool DataProperty::setValue(DataObject* obj, const DataValue& value) const
{
	return _setter && _setter(obj, const_cast<DataProperty*>(this), DataValue(value).convertTo(_type));
}
void QuantitativeExperimentalDesign::mergeIDFiles_(vector<ProteinIdentification> & proteins, vector<PeptideIdentification> & peptides, const String & experiment, StringList & file_paths)
{
    set<String> used_ids;
    vector<ProteinIdentification> additional_proteins;
    vector<PeptideIdentification> additional_peptides;

    LOG_INFO << "Merge idXML-files:" << endl;
    for (StringList::Iterator file_it = file_paths.begin(); file_it != file_paths.end(); ++file_it)
    {
        // load should clear the vectors
        IdXMLFile().load(*file_it, additional_proteins, additional_peptides);

        for (vector<ProteinIdentification>::iterator prot_it =
                    additional_proteins.begin(); prot_it !=
                additional_proteins.end(); ++prot_it)
        {
            prot_it->setMetaValue("experiment", DataValue(experiment));
        }

        for (vector<PeptideIdentification>::iterator pep_it =
                    additional_peptides.begin(); pep_it !=
                additional_peptides.end(); ++pep_it)
        {
            pep_it->setMetaValue("experiment", DataValue(experiment));
        }

        UInt counter = 1;
        for (vector<ProteinIdentification>::iterator prot_it = additional_proteins.begin(); prot_it != additional_proteins.end(); ++prot_it, ++counter)
        {
            String id = prot_it->getIdentifier();
            if (used_ids.find(id) != used_ids.end()) // ID used previously
            {
                LOG_INFO << "Warning: The identifier '" + id + "' was used before!" << endl;
                // generate a new ID:
                DateTime date_time = prot_it->getDateTime();
                String new_id;
                String search_engine = prot_it->getSearchEngine();
                do
                {
                    date_time = date_time.addSecs(1);
                    new_id = search_engine + "_" + date_time.toString(Qt::ISODate);
                }
                while (used_ids.find(new_id) != used_ids.end());
                LOG_INFO << "New identifier '" + new_id + "' generated as replacement." << endl;
                // update fields:
                prot_it->setIdentifier(new_id);
                prot_it->setDateTime(date_time);
                for (vector<PeptideIdentification>::iterator pep_it = additional_peptides.begin(); pep_it != additional_peptides.end(); ++pep_it)
                {
                    if (pep_it->getIdentifier() == id)
                        pep_it->setIdentifier(new_id);
                }
                used_ids.insert(new_id);
            }
            else
                used_ids.insert(id);
        }

        proteins.insert(proteins.end(), additional_proteins.begin(), additional_proteins.end());
        peptides.insert(peptides.end(), additional_peptides.begin(), additional_peptides.end());
    }
}
Ejemplo n.º 13
0
    void DisassemblerDatabase::load()
    {
        this->_disassemblerdb.open(this->_filename.toUtf8().constData());
        SQLiteStatement s(this->_disassemblerdb, "SELECT * FROM SymbolTable");

        while(s.step())
        {
            DataValue addressvalue = DataValue::create(s.column(0).integer64(), this->_symboltable->addressType());
            DataValue sizevalue = DataValue::create(s.column(3).integer64(), this->_symboltable->addressType());
            this->_symboltable->set(static_cast<Symbol::Type>(s.column(2).integer()), addressvalue, sizevalue, DataValue(), QString::fromUtf8(s.column(1).text()));

            if(s.column(4).integer64())
            {
                Symbol* symbol = this->_symboltable->get(addressvalue);
                SQLiteStatement refs(this->_disassemblerdb, "SELECT * FROM ReferenceTable WHERE Address = ?");
                refs.bind(1, s.column(0).integer64());

                while(refs.step())
                {
                    DataValue referencevalue = DataValue::create(refs.column(1).integer64(), this->_symboltable->addressType());
                    symbol->addSource(referencevalue);
                }
            }
        }

        this->_disassemblerdb.close();
    }