示例#1
0
//------------------------------------------------------------------------------
void ISerializable::writeObject(std::ostream &ostr)
{
  setOperation(OP_WRITE);
  ostr_ = &ostr;
  serializeObject();

}
示例#2
0
//------------------------------------------------------------------------------
void ISerializable::serializeSubObject(ISerializable * const other)
{
  istr_ = other->istr_;
  ostr_ = other->ostr_;
  operation_ = other->operation_;
  setGameVersion(other->gameVersion_);
  serializeObject();
}
示例#3
0
//------------------------------------------------------------------------------
size_t ISerializable::objectSize(void)
{
  size_ = 0;

  setOperation(OP_CALC_SIZE);
  serializeObject();

  return size_;
}
示例#4
0
void PQBaseItem::serializeProperty(QTextStream &stream, const QDeclarativeProperty &property, unsigned indentSize) const
{
    QString str;
    QTextStream outStream(&str);
    if (property.propertyTypeCategory() == QDeclarativeProperty::Normal) { // Normal value property
        const int propertyType = property.propertyType();
        const QString propertyValue = property.read().toString();
        if (propertyType >= QVariant::Bool && propertyType <= QVariant::Double) { // Numerical, unquoted values
            outStream << propertyValue;
        } else {
            if (!propertyValue.isEmpty()) {
                QString value = propertyValue;
                value.replace(QLatin1Char('\\'), QLatin1String("\\\\")) // escape backslashes in rich text
                     .replace(QLatin1Char('"'), QLatin1String("\\\"")); // escape quotes
                value = QLatin1Char('"') % value % QLatin1Char('"');
                outStream << value;
            }
        }
    } else if (property.propertyTypeCategory() == QDeclarativeProperty::Object) { // Complex Object type
        const QVariant variantValue = property.read();
        if (variantValue.isValid() && !variantValue.isNull()) {
            serializeObject(outStream, variantValue.value<QObject *>(), indentSize);
        }
    } else if (property.propertyTypeCategory() == QDeclarativeProperty::List) { // List of objects
        const QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read());

        outStream << QLatin1Char('[') << endl;
        for (int itemIndex = 0, c = list.count(); itemIndex < c; ++itemIndex) {
            QObject *item = list.at(itemIndex);
            serializeObject(outStream, item, indentSize+1);
            if (itemIndex + 1 != list.count()) {
                outStream << QLatin1Char(','); // separator
            }
            outStream << endl;
        }
        outStream << PQSerializer::indentStep().repeated(indentSize) << QLatin1String("]"); // close list
    }

    if (!str.isEmpty()) {
        stream << PQSerializer::indentStep().repeated(indentSize) 
               << property.name() << QLatin1String(": ") << str
               << endl;
    }
}
示例#5
0
//------------------------------------------------------------------------------
void ISerializable::readObject(std::istream &istr)
{
  setOperation(OP_READ);
  istr_ = &istr;

  istr_->seekg(init_read_pos_);

  serializeObject();

}
示例#6
0
 void serializeVector(const std::string & n, const J *objs, std::size_t nObjs) {
     completeAttrEnding();
     if(n != "") {
         serializeAttrName(n);
         write(":");
     }
     write("[");
     m_attrsPush.push_back(0);
     for(std::size_t i = 0; i < nObjs; ++i) {
         serializeObject("", objs + i);
     }
     m_attrsPush.pop_back();
     write("]");
 }
示例#7
0
 void serializeVector(const std::string & n, const std::vector<J *> & objs) {
     completeAttrEnding();
     if(n != "") {
         serializeAttrName(n);
         write(":");
     }
     write("[");
     m_attrsPush.push_back(0);
     for(typename std::vector<J *>::const_iterator i = objs.begin(); i != objs.end(); ++i) {
         serializeObject("", (*i));
     }
     m_attrsPush.pop_back();
     write("]");
 }
示例#8
0
bool SerializerNew::serializeToDocument(const Variant& v, SerializationDocument* doc)
{
	if (doc == nullptr)
		return false;

	doc->clear();

	auto rootNode = doc->getRootNode();
	auto objectRootNode = rootNode->createEmptyChild("object", 6);

	// TODO: Set the name properly here once handlers are implemented
	objectRootNode->setName("object", 6);

	serializeObject(v, objectRootNode);

	return true;
}
示例#9
0
QJsonArray Utils::serializeType(const QMetaObject& meta, qlonglong timestamp)
{
    QString className = meta.className();
    QStringList properties;
    properties << "_id" << "modified" << "deleted";
    properties << propertyNames(meta);
    
    QSqlQuery query;
    query.prepare(QString("SELECT %1 FROM %2 WHERE modified>:timestamp OR deleted>:timestamp").arg(properties.join(",")).arg(className));
    query.bindValue(":timestamp", timestamp);
    query.exec();
    
    QJsonArray array;
    while (query.next())
    {
        array.append(serializeObject(properties, query));
    }
    
    return array;
}
示例#10
0
 /**
  * \brief Write a JSONizable object as a root
  *
  * \param obj the reference to the JSONizable object
  */
 void serializeRootObject(const JSONizable & obj) {
     serializeObject("", &obj);
 }