示例#1
0
void SettingsArchiverBin::saveNode( AbstractNode *node, std::ostream& out )
{
	_write<int8_t>(out, node->type());

	switch( node->type() ) {
	case AbstractNode::Map:
		_write<int32_t>(out, dynamic_cast<MapNode*>(node)->size());

		for( MapNode::const_iterator itm = dynamic_cast<MapNode*>(node)->begin();
				itm != dynamic_cast<MapNode*>(node)->end(); itm++ ) {
			_write_string(out, itm->first.c_str(), itm->first.length());
			saveNode(itm->second, out);
		}

		break;

	case AbstractNode::Vector:
		_write<int32_t>(out, dynamic_cast<VectorNode*>(node)->size());

		for( VectorNode::const_iterator itv = dynamic_cast<VectorNode*>(node)->begin();
				itv != dynamic_cast<VectorNode*>(node)->end(); itv++ ) {
			saveNode(*itv, out);
		}
		break;

	case AbstractNode::Scalar: {
			jq::String s(dynamic_cast<ScalarNode*>(node)->value());
			_write_string(out, s.c_str(), s.length());
		}
		break;

	default:
		break;
	}
}
示例#2
0
void VaultShopMain::tabChanged(int tabIdx)
{
    if (tabIdx == 0)
        saveNode(fVaultTree->currentItem(), 1);
    else
        saveNode(fVaultTree->currentItem(), 0);
}
示例#3
0
bool
HeapSnapshot::init(JSContext* cx, const uint8_t* buffer, uint32_t size)
{
  if (!nodes.init() || !frames.init())
    return false;

  ArrayInputStream stream(buffer, size);
  GzipInputStream gzipStream(&stream);

  // First is the metadata.

  protobuf::Metadata metadata;
  if (!parseMessage(gzipStream, metadata))
    return false;
  if (metadata.has_timestamp())
    timestamp.emplace(metadata.timestamp());

  // Next is the root node.

  protobuf::Node root;
  if (!parseMessage(gzipStream, root))
    return false;

  // Although the id is optional in the protobuf format for future proofing, we
  // can't currently do anything without it.
  if (NS_WARN_IF(!root.has_id()))
    return false;
  rootId = root.id();

  // The set of all node ids we've found edges pointing to.
  NodeIdSet edgeReferents(cx);
  if (NS_WARN_IF(!edgeReferents.init()))
    return false;

  if (NS_WARN_IF(!saveNode(root, edgeReferents)))
    return false;

  // Finally, the rest of the nodes in the core dump.

  while (StreamHasData(gzipStream)) {
    protobuf::Node node;
    if (!parseMessage(gzipStream, node))
      return false;
    if (NS_WARN_IF(!saveNode(node, edgeReferents)))
      return false;
  }

  // Check the set of node ids referred to by edges we found and ensure that we
  // have the node corresponding to each id. If we don't have all of them, it is
  // unsafe to perform analyses of this heap snapshot.
  for (auto range = edgeReferents.all(); !range.empty(); range.popFront()) {
    if (NS_WARN_IF(!nodes.has(range.front())))
      return false;
  }

  return true;
}
示例#4
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::saveNode(ostream& out, TreeNode *node)
{
  if(node)
  {
    if(node->save)
      node->props->save(out);
    saveNode(out, node->left);
    saveNode(out, node->right);
  }
}
示例#5
0
int monthReport(struct Node *node){
  
  int i;
  struct Node nextNode;

  for (i = 0; i < node->count; i++){

    if (node->offsets[0] != -1){
      if(node->offsets[i] != -1){
        getNode(node->offsets[i], &nextNode);
        monthReport(&nextNode);
      }
    }

    printItem(node, i);

  }

  if (node->offsets[0] != -1){
    if(node->offsets[i] != -1){
      getNode(node->offsets[i], &nextNode);
      monthReport(&nextNode);
    }
  }

  saveNode(node);

  return 0;
}
示例#6
0
/* 
  function changePrice
  input: 1. line: original line from transaction file.
         2. node: node in btree that holds item.
         3. datapos: position of the item being changed in node
         4. linepos: current position in line. 
                     (will be after action name and item code)
  Return: 0 on compelete. (value not used)

  Builds gets new price and updates the information in the Data struct.
  first while loop gathers dollar amount, second gets cent amount.
  Saves node once done.

  Uses saveNode() from btree.c

 */
int changePrice(char *line, struct Node *node, int datapos, int linepos){

  int i = 0;
  char dollars[5];
  char cents[3];

  linepos++;

  while(line[linepos] != '.'){
    dollars[i] = line[linepos];
    linepos++;
    i++;
  }

  i = 0;
  // skip passed '.'
  linepos++;

  while((line[linepos] != '\n') && (line[linepos] != EOF)){
    cents[i] = line[linepos];
    linepos++;
    i++;
  }

  node->data[datapos].dollar = atoi(dollars);
  node->data[datapos].cent = atoi(cents);

  saveNode(node);
  return 0;
}
示例#7
0
QByteArray XMLerSaveFileThread::toBuffer ( BaseXMLNode *node )
{
  QByteArray data;
  QBuffer buffer ( &data );
  bool result_open = buffer.open ( QIODevice::WriteOnly );
  if ( !result_open ) {
    emit error ( tr("Can not open memory buffer.") );
    return data;
  }
  QXmlStreamWriter writer ( &buffer );
  writer.setCodec ( DEFAULT_ENCODING );
  QString msg_progress = tr( "Save XML to memory buffer" );
  emit beginProgress ( msg_progress, 0 );
  emit beginProgress ( msg_progress, node->size() );

  qint64 pos = 0;
  bool result = saveNode ( writer, node, pos );
  
  if ( !result ) {
    emit error ( tr("Error while writing the node") );
    return QByteArray();
  }
  
  return data;
}
示例#8
0
bool
HeapSnapshot::init(const uint8_t* buffer, uint32_t size)
{
  if (!nodes.init() || !frames.init() || !strings.init())
    return false;

  ArrayInputStream stream(buffer, size);
  GzipInputStream gzipStream(&stream);

  // First is the metadata.

  protobuf::Metadata metadata;
  if (!parseMessage(gzipStream, metadata))
    return false;
  if (metadata.has_timestamp())
    timestamp.emplace(metadata.timestamp());

  // Next is the root node.

  protobuf::Node root;
  if (!parseMessage(gzipStream, root))
    return false;

  // Although the id is optional in the protobuf format for future proofing, we
  // can't currently do anything without it.
  if (NS_WARN_IF(!root.has_id()))
    return false;
  rootId = root.id();

  if (NS_WARN_IF(!saveNode(root)))
    return false;

  // Finally, the rest of the nodes in the core dump.

  while (StreamHasData(gzipStream)) {
    protobuf::Node node;
    if (!parseMessage(gzipStream, node))
      return false;
    if (NS_WARN_IF(!saveNode(node)))
      return false;
  }

  return true;
}
void ShaderEditor::save(const char* path)
{
	FILE* fp = fopen(path, "wb");
	if (!fp)
	{
		Lumix::g_log_error.log("Editor") << "Could not save shader " << path;
		return;
	}

	Lumix::OutputBlob blob(m_allocator);
	blob.reserve(4096);
	for (int i = 0; i < Lumix::lengthOf(m_textures); ++i)
	{
		blob.writeString(m_textures[i]);
	}

	int nodes_count = m_vertex_nodes.size();
	blob.write(nodes_count);
	for(auto* node : m_vertex_nodes)
	{
		saveNode(blob, *node);
	}

	for(auto* node : m_vertex_nodes)
	{
		saveNodeConnections(blob, *node);
	}

	nodes_count = m_fragment_nodes.size();
	blob.write(nodes_count);
	for (auto* node : m_fragment_nodes)
	{
		saveNode(blob, *node);
	}

	for (auto* node : m_fragment_nodes)
	{
		saveNodeConnections(blob, *node);
	}

	fwrite(blob.getData(), blob.getSize(), 1, fp);
	fclose(fp);
}
示例#10
0
/*
  function: itemChange
  Input: 1. action: action to be perfomed.
         2. code: item changed by action. 
         3. line: original line from transaction file.
         4. linepos: position in line after transaction type and item code.

  Return: 0 on complete. (value not used)

  Handles sales, delivery, and price changes for items.
  Part (a): Search for the item in question.
  Part (b): If the action is not a price change pull out amount of
            sale or delivery for use.
  Part (c): Perform correct transaction based on action input.
            - Sale: Item's stock is updated and the profit field
                    of the item is calculated based on current price.
            - Delivery: Item's stock is updated.
            - Price change: function changePrice is called to handle change.

  Uses saveNode(), and getNode() from btree.c

 */
int itemChange(char *action, char *code, char *line, int linepos){

  int j = 0;
  int newStock;
  int datapos;
  char amount[4];
  struct Node root;
  struct Node node;

  getNode(0, &root);

  //Part (a)
  if ((datapos = search(&root, code, &node)) == -1){
    printf("ERROR: No item with code %s. Cannot complete %s.\n", code, action);
    return 0;
  }

  // Part (b)
  if (strcmp(action, "PRICE") != 0){
    linepos++;

    while(line[linepos] != '\0'){
      amount[j] = line[linepos];
      j++;
      linepos++;
    }
    line[linepos] = '\0';
  }

  //Part (c)
  if (strcmp(action, "SALE") == 0){
    newStock = (node.data[datapos].stock) - atoi(amount); 
    if (newStock < 0){
      printf("ERROR: Quantity Sold of item %s is greater than current stock.\n", code);
    }else{
      node.data[datapos].stock = newStock;
      updateHistory(&(node.data[datapos]), atoi(amount));
      updateSales(&(node.data[datapos]), atoi(amount));
    }

  }else if (strcmp(action, "DELIVERY") == 0){
    newStock = (node.data[datapos].stock) + atoi(amount); 
    node.data[datapos].stock = newStock;
  }else{
    changePrice(line, &node, datapos, linepos);
  }

  saveNode(&node);

  return 0;
}
示例#11
0
// Methods from Persistent Store
void SystemClipboard::saveModel(::Model::Model* model, const QString &name)
{
	if (model->root())
	{
		SAFE_DELETE(xml);
		xml = new XMLModel();

		xml->beginSaveChildNode(CLIPBOARD_TAG);
		saveNode(model->root(), name, false);
		xml->endSaveChildNode();

		QApplication::clipboard()->setText(xml->documentText());

		SAFE_DELETE(xml);
		numNodes_ = 0;
	}
}
示例#12
0
void MaterialWindow::saveMaterial()
{
    if (mMaterialAsset == NULL)
        return;

    for (S32 n = 0; n < nodeList.size(); ++n)
    {
        Node* node = &nodeList[n];
        saveNode(mMaterialAsset->getTemplate(), node);
    }

    for (S32 n = 0; n < connectionList.size(); ++n)
    {
        Connection* connection = &connectionList[n];
        saveConnection(connection);
    }

    mMaterialAsset->saveMaterial();
    mMaterialAsset->reloadMaterial();
}
示例#13
0
/* self */
void XMLerSaveFileThread::run () 
{
  if ( !_document ) {
    emit warning ( tr("Document is empty or doesn't set.") );
    return;
  }

  QFile xml ( fileName() );

  if ( !xml.open ( QIODevice::WriteOnly ) ) {
    emit error ( tr("Can not open file %1.").arg( fileName() ) );
    return;
  }

  QXmlStreamWriter writer( &xml );

  /* set information about document */
  writer.setAutoFormatting ( _document->autoFormatting() );
  writer.setAutoFormattingIndent ( _document->formattingIndent() );
  writer.setCodec ( _document->codec() );

  emit beginProgress ( progressMessage(), 0 );
  emit beginProgress ( progressMessage(), _document->size() );
  bool result = true;
  qint64 pos = 0;

  /* save a document */
  result = saveNode ( writer, _document, pos );

  xml.close();
  emit endProgress ();

  /* set filename */
  if ( result && _document->fileName() != fileName() )
    _document->setFileName ( fileName() );

  if ( !result )
    emit error ( tr("Error while writing the document.").arg( fileName() ) );
  else
    emit done ();
}
示例#14
0
void VaultShopMain::typeModified()
{
    saveNode(fVaultTree->currentItem(), fNodeTab->currentIndex());
    if (fCustomEditor != NULL) {
        fEditorTabPreference = fNodeTab->currentIndex();
        fNodeTab->removeTab(0);
        disconnect(fCustomEditor, 0, 0, 0);
        delete fCustomEditor;
        fCustomEditor = NULL;
    }

    QTreeWidgetItem* current = fVaultTree->currentItem();
    VaultInfo* vault = findCurrentVault(current);
    if (vault != NULL) {
        plVaultNode node = vault->fVault->getNode(current->data(0, kRoleNodeID).toInt());
        fCustomEditor = QVaultNodeEdit::MakeEditor(fNodeTab, node, &fResMgr, &fSDLMgr);
        if (fCustomEditor != NULL) {
            fNodeTab->insertTab(0, fCustomEditor, fCustomEditor->getEditorTitle());
            fNodeTab->setCurrentIndex(fEditorTabPreference);
            connect(fCustomEditor, SIGNAL(subscribe(unsigned int)),
                    this, SLOT(subscribe(unsigned int)));
        }
示例#15
0
void PersistentStoreMock::saveModel(Model* model, const QString &name)
{
	saveNode(model->root(), name, false);
}
示例#16
0
bool dtkComposerWidget::save(QString file, dtkComposerWriter::Type type)
{
    return saveNode(d->scene->root(), file, type);
}
示例#17
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::save(ostream& out)
{
  saveNode(out, myRoot);
}
示例#18
0
bool XMLerSaveFileThread::saveNode ( QXmlStreamWriter &writer, BaseXMLNode *node, qint64 &pos )
{
  bool result = true;
  pos += 1;

  if ( ElementXMLNode *element = qobject_cast<ElementXMLNode *>(node) ) {
    /* prefix mapping */
    if ( element->hasPrefixMapping() ) {
      QMap<QString,QString> prefixMapping = element->prefixMapping();
      QMap<QString,QString>::const_iterator it;

      for ( it = prefixMapping.begin(); it != prefixMapping.end(); ++it )
        writer.writeNamespace ( it.value(), it.key() );
    }


    if ( element->namespaceURI().isEmpty () )
      writer.writeStartElement ( element->qName() );
    else
      writer.writeStartElement ( element->namespaceURI(), element->name() );

    XMLNodePtrList chlist = element->childs();
    XMLNodePtrList::iterator it;

    for ( it = chlist.begin(); it != chlist.end(); ++it ) {
      BaseXMLNode *child_node = (*it);
      result &= saveNode ( writer, child_node, pos );
    }

    writer.writeEndElement();
  }
  else if ( AttrXMLNode *attr = qobject_cast<AttrXMLNode *>(node) ) {
    if ( attr->namespaceURI().isEmpty() )
      writer.writeAttribute ( attr->qName(), attr->value() );
    else
      writer.writeAttribute ( attr->namespaceURI(), attr->name(), attr->value() );
  }
  else if ( DataXMLNode *data = qobject_cast<DataXMLNode *>(node) ) {
    writer.writeCharacters ( data->data() );
  }
  else if ( DocumentXMLNode *doc = qobject_cast<DocumentXMLNode *>(node) ) {
    writer.writeStartDocument( doc->version() );

    if ( doc->hasPI() ) {
      const QMap<QString,QString> &pi = _document->processingInstructions();
      QMap<QString,QString>::const_iterator it;
      for ( it = pi.begin(); it != pi.end(); ++it ) {
        if ( it.key().trimmed().isEmpty() )
          continue;
        writer.writeProcessingInstruction ( it.key(), it.value() );
      }
    }
  
    if ( doc->documentNode() )
      result &= saveNode ( writer, doc->documentNode(), pos );

    writer.writeEndDocument();
  }

  emit progress ( pos );

  return result;
}