Exemplo n.º 1
0
void JsonWriter::writeNode(const JsonNode &node)
{
	switch(node.getType())
	{
		break; case JsonNode::DATA_NULL:
			out << "null";

		break; case JsonNode::DATA_BOOL:
			if (node.Bool())
				out << "true";
			else
				out << "false";

		break; case JsonNode::DATA_FLOAT:
			out << node.Float();

		break; case JsonNode::DATA_STRING:
			writeString(node.String());

		break; case JsonNode::DATA_VECTOR:
			out << "[" << "\n";
			writeContainer(node.Vector().begin(), node.Vector().end());
			out << prefix << "]";

		break; case JsonNode::DATA_STRUCT:
			out << "{" << "\n";
			writeContainer(node.Struct().begin(), node.Struct().end());
			out << prefix << "}";
	}
}
Exemplo n.º 2
0
 void writeMap( std::ostream& stream, const Map& m)
 {
     const unsigned int mapEntries = m.size();
     writeValue( stream, mapEntries );
     if( mapEntries > 0 )
     {
         const auto& end = m.end();
         for(auto it = m.begin(); it != end; ++it )
         {
             // write key (assume that key is a container)
             writeContainer( stream, (*it).first );
             // write value (assume that value is a container)
             writeContainer( stream, (*it).second );
         }
     }
 }
Exemplo n.º 3
0
// ---------------------------------------------------------------------------
//	write 
// ---------------------------------------------------------------------------
//!	Export the sample data represented by this AiffFile to
//!	the file having the specified filename or path. Export
//!	signed integer samples of the specified size, in bits
//!	(8, 16, 24, or 32).
//!
//!	\param filename is the name or path of the AIFF samples file
//!	to be created or overwritten.
//!	\param bps is the number of bits per sample to store in the
//!	samples file (8, 16, 24, or 32).If unspeicified, 16 bits
//!	is assumed.
//
void
AiffFile::write( const std::string & filename, unsigned int bps )
{
	static const unsigned int ValidSizes[] = { 8, 16, 24, 32 };
	if ( std::find( ValidSizes, ValidSizes+4, bps ) == ValidSizes+4 )
	{
		Throw( InvalidArgument, "Invalid bits-per-sample." );
	}

	std::ofstream s( filename.c_str(), std::ofstream::binary );
	if ( ! s )
	{
		std::string s = "Could not create file \"";
		s += filename;
		s += "\". Failed to write AIFF file.";
		Throw( FileIOException, s );
	}
	
	unsigned long dataSize = 0;

	CommonCk commonChunk;
	configureCommonCk( commonChunk, samples_.size() / numchans_, numchans_, bps, rate_ );
	dataSize += commonChunk.header.size + sizeof(CkHeader);
	
	SoundDataCk soundDataChunk;
	configureSoundDataCk( soundDataChunk, samples_, bps );
	dataSize += soundDataChunk.header.size + sizeof(CkHeader);
	
	InstrumentCk instrumentChunk;
	configureInstrumentCk( instrumentChunk, notenum_ );
	dataSize += instrumentChunk.header.size + sizeof(CkHeader);

	MarkerCk markerChunk;
	if ( ! markers_.empty() )
	{
		configureMarkerCk( markerChunk, markers_, rate_ );
		dataSize += markerChunk.header.size + sizeof(CkHeader);
	}
	
	ContainerCk containerChunk;
	configureContainer( containerChunk, dataSize );
	
	try 
	{
		writeContainer( s, containerChunk );
		writeCommonData( s, commonChunk );
		if ( ! markers_.empty() )
			writeMarkerData( s, markerChunk );
		writeInstrumentData( s, instrumentChunk );
		writeSampleData( s, soundDataChunk );
		
		s.close();
	}
	catch ( Exception & ex ) 
	{
		ex.append( " Failed to write AIFF file." );
		throw;
	}
}
 EL::StatusCode
 HgammaHandler<partType, partContainer, auxContainer>::writeTruthContainer(partContainer &container, TString name)
 {
   if (name == "") {
     name = m_MxAODname + m_truthName;
   }
   return writeContainer(container, name);
 }
Exemplo n.º 5
0
/*! Write a single FieldContainer with all its "children", i.e. everything
 *  that can be reached via Ptr-Fields.
 */
void OSGWriter::write(FieldContainer *container)
{
    _visitedFCMap.clear();
//    _indent.setIndent(0);

    _outStream << "#OSG V1.0 ";
    _outStream << "\n";

    visitContainer(container);
    writeContainer(container, true);
}
Exemplo n.º 6
0
tstring Writer::formatDocument(DocumentPtr document)
{
	ASSERT(document.get() != nullptr);

	m_buffer.clear();

	writeContainer(*document.get());

	ASSERT(m_depth == 0);

	return m_buffer;
}
Exemplo n.º 7
0
/*! Write all FieldContainers in containers with their "children",
 *  i.e. everything that can be reached via Ptr-Fields.
 */
void OSGWriter::write(std::vector<FieldContainer *> containers)
{
    _visitedFCMap.clear();
//    _indent.setIndent(0);

    _outStream << "#OSG V1.0 " << "\n";

    std::vector<FieldContainer *>::reverse_iterator iter;

    for(iter = containers.rbegin(); iter != containers.rend(); ++iter)
    {
        visitContainer(*iter);
    }

    for(iter = containers.rbegin(); iter != containers.rend(); ++iter)
    {
        writeContainer(*iter, true);
    }
}
Exemplo n.º 8
0
UT_Error IE_Exp_EPUB::_writeDocument()
{
    UT_Error errOptions = doOptions();

    if (errOptions == UT_SAVE_CANCELLED) //see Bug 10840
    {
        return UT_SAVE_CANCELLED;
    }
    else if (errOptions != UT_OK) {
        return UT_ERROR;
    }

    m_root = gsf_outfile_zip_new(getFp(), NULL);

    if (m_root == NULL)
    {
        UT_DEBUGMSG(("ZIP output is null\n"));
        return UT_ERROR;
    }

    m_oebps = gsf_outfile_new_child(m_root, "OEBPS", TRUE);
    if (m_oebps == NULL)
    {
        UT_DEBUGMSG(("Can`t create oebps output object\n"));
        return UT_ERROR;
    }

    // mimetype must a first file in archive
    GsfOutput *mimetype = gsf_outfile_new_child_full(m_root, "mimetype", FALSE,
        "compression-level", 0, NULL);
    gsf_output_write(mimetype, strlen(EPUB_MIMETYPE),
            (const guint8*) EPUB_MIMETYPE);
    gsf_output_close(mimetype);

    // We need to create temporary directory to which
    // HTML plugin will export our document
    m_baseTempDir = UT_go_filename_to_uri(g_get_tmp_dir());
    m_baseTempDir += G_DIR_SEPARATOR_S;

    // To generate unique directory name we`ll use document UUID
    m_baseTempDir += getDoc()->getDocUUIDString();
    // We should delete any previous temporary data for this document to prevent
    // odd files appearing in the container
    UT_go_file_remove(m_baseTempDir.c_str(), NULL);
    UT_go_directory_create(m_baseTempDir.c_str(), NULL);

    if (writeContainer() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write container\n"));
        return UT_ERROR;
    }
    if (writeStructure() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write document structure\n"));
        return UT_ERROR;
    }
    if (writeNavigation() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to write navigation\n"));
        return UT_ERROR;
    }
    if (package() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to package document\n"));
        return UT_ERROR;
    }

    gsf_output_close(m_oebps);
    gsf_output_close(GSF_OUTPUT(m_root));
    
    // After doing all job we should delete temporary files
    UT_go_file_remove(m_baseTempDir.c_str(), NULL);
    return UT_OK;
}
Exemplo n.º 9
0
void Writer::writeElement(ElementNodePtr element)
{
	tstring indentation;
	tstring terminator;

	if (!(m_flags & NO_FORMATTING))
	{
		for (uint i = 0; i != m_depth; ++i)
			indentation += m_indentStyle;

		terminator = DEFAULT_TERMINATOR;
	}

	if (element->hasChildren())
	{
		const bool inlineValue = ( (element->getChildCount() == 1)
								&& (element->getChild(0)->type() == TEXT_NODE) );

		if (!element->getAttributes().isEmpty())
		{
			m_buffer += indentation;
			m_buffer += Core::fmt(TXT("<%s"), element->name().c_str());

			writeAttributes(element->getAttributes());

			m_buffer += TXT(">");

			if (!inlineValue)
				m_buffer += terminator;
		}
		else
		{
			m_buffer += indentation;
			m_buffer += Core::fmt(TXT("<%s>"), element->name().c_str());

			if (!inlineValue)
				m_buffer += terminator;
		}

		++m_depth;
		writeContainer(*element);
		--m_depth;

		if (!inlineValue)
			m_buffer += indentation;

		m_buffer += Core::fmt(TXT("</%s>"), element->name().c_str());
		m_buffer += terminator;
	}
	else
	{
		if (!element->getAttributes().isEmpty())
		{
			m_buffer += indentation;
			m_buffer += Core::fmt(TXT("<%s"), element->name().c_str());

			writeAttributes(element->getAttributes());

			m_buffer += TXT("/>");
			m_buffer += terminator;
		}
		else
		{
			m_buffer += indentation;
			m_buffer += Core::fmt(TXT("<%s/>"), element->name().c_str());
			m_buffer += terminator;
		}
	}
}
Exemplo n.º 10
0
void OSGWriter::writeField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType& fType = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrSFieldBase::GetHandle>(hF);
    
    FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrMFieldBase::GetHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        _outStream << BeginElem 
                   << hF->getName();

        //if the Attachment Map is empty write [] as its content
        if(sfMap->empty() == true)
        {
            _outStream << " [ ] " << EndElemNL;
        }
        else
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "["
                       << EndElemNL;

            _outStream << IncIndent;
        
            EditMapFieldHandle::MapList fcList;

            sfMap->flatten(fcList);

            EditMapFieldHandle::MapList::iterator iter = fcList.begin();
            EditMapFieldHandle::MapList::iterator end  = fcList.end  ();

            for(; iter!=end; ++iter)
            {
                _outStream << BeginElem
                           << "MapHelper"
                           << EndElemNL
                           << BeginElem
                           << "{"
                           << EndElemNL;

                _outStream << IncIndent;

                _outStream << BeginElem
                           << "keys"
                           << EndElemNL
                           << BeginElem
                           << "["
                           << EndElemNL;

                _outStream << IncIndent;

                std::vector<std::string>::const_iterator kIt  = 
                    iter->first.begin();

                std::vector<std::string>::const_iterator kEnd = 
                    iter->first.end();

                for(; kIt != kEnd; ++kIt)
                {
                    _outStream << BeginElem
                               << "\""
                               << *kIt
                               << "\""
                               << EndElemNL;
                }

                _outStream << DecIndent;

                _outStream << BeginElem
                           << "]"
                           << EndElemNL;

                _outStream << BeginElem
                           << "container ";
                    
                if(iter->second == NULL)
                {
                    _outStream << "NULL"
                               << EndElemNL;
                }
                else
                {
                    writeContainer(iter->second, false);
                    _outStream << EndElemNL;
                }

                _outStream << DecIndent;
                                    
                _outStream << BeginElem
                           << "}"
                           << EndElemNL;
            }

            _outStream << DecIndent; 
            
            _outStream << BeginElem
                       << "]"
                       << EndElemNL;
        }
    }
    else if(sfFCPtr != NULL || mfFCPtr != NULL)
    {
        //this Field points to FC

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem 
                       << hF->getName();
        }

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            if((*sfFCPtr)->getValue() == NULL)
            {
                _outStream << " NULL" << EndElemNL;
            }
            else
            {
                _outStream << " ";
                writeContainer((*sfFCPtr)->getValue(), false);
            }
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                if((*(*mfFCPtr))[i] == NULL)
                {
                    _outStream << BeginElem
                               << "NULL" 
                               << EndElemNL;
                }
                else
                {
                    writeContainer((*(*mfFCPtr))[i], true);
                }
            }

            _outStream << DecIndent;

            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
    else
    {
        //this Field contains data -> write it out

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem << hF->getName();
        }

        //to access the content of a field via a Field*
        //one must know the cardinality
        if(hF->getCardinality() == FieldType::SingleField)
        {
            _outStream << " ";

            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
        }
        else if(hF->getCardinality() == FieldType::MultiField)
        {
            _outStream << " #";

            hF->pushSizeToStream(_outStream);

            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

#ifdef WFC
            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
#endif


            _outStream << DecIndent;
            
            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
}