Exemplo n.º 1
0
void 
StyledWriter::writeValue( const Value &value )
{
   switch ( value.type() )
   {
   case nullValue:
      pushValue( "null" );
      break;
   case intValue:
      pushValue( valueToString( value.asLargestInt() ) );
      break;
   case uintValue:
      pushValue( valueToString( value.asLargestUInt() ) );
      break;
   case realValue:
      pushValue( valueToString( value.asDouble() ) );
      break;
   case stringValue:
      pushValue( valueToQuotedString( value.asCString() ) );
      break;
   case booleanValue:
      pushValue( valueToString( value.asBool() ) );
      break;
   case arrayValue:
      writeArrayValue( value);
      break;
   case objectValue:
      {
         Value::Members members( value.getMemberNames() );
         if ( members.empty() )
            pushValue( "{}" );
         else
         {
            writeWithIndent( "{" );
            indent();
            Value::Members::iterator it = members.begin();
            for (;;)
            {
               const std::string &name = *it;
               const Value &childValue = value[name];
               writeCommentBeforeValue( childValue );
               writeWithIndent( valueToQuotedString( name.c_str() ) );
               document_ += " : ";
               writeValue( childValue );
               if ( ++it == members.end() )
               {
                  writeCommentAfterValueOnSameLine( childValue );
                  break;
               }
               document_ += ",";
               writeCommentAfterValueOnSameLine( childValue );
            }
            unindent();
            writeWithIndent( "}" );
         }
      }
      break;
   }
}
Exemplo n.º 2
0
void StyledStreamWriter::writeValue(const Value& value) {
    switch (value.type()) {
    case nullValue:
        pushValue("null");
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble()));
        break;
    case stringValue:
    {
        // Is NULL possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                const std::string& name = *it;
                const Value& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedString(name.c_str()));
                *document_ << " : ";
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *document_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Exemplo n.º 3
0
void BuiltStyledStreamWriter::writeValue(Value const& value) {
    switch (value.type()) {
    case nullValue:
        pushValue(nullSymbol_);
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_));
        break;
    case stringValue:
    {
        // Is NULL is possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                std::string const& name = *it;
                Value const& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
                *sout_ << colonSymbol_;
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *sout_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Exemplo n.º 4
0
void
StyledStreamWriter::writeValue ( const Value& value )
{
    switch ( value.type () )
    {
    case nullValue:
        pushValue ( "null" );
        break;

    case intValue:
        pushValue ( valueToString ( value.asInt () ) );
        break;

    case uintValue:
        pushValue ( valueToString ( value.asUInt () ) );
        break;

    case realValue:
        pushValue ( valueToString ( value.asDouble () ) );
        break;

    case stringValue:
        pushValue ( valueToQuotedString ( value.asCString () ) );
        break;

    case booleanValue:
        pushValue ( valueToString ( value.asBool () ) );
        break;

    case arrayValue:
        writeArrayValue ( value);
        break;

    case objectValue:
    {
        Value::Members members ( value.getMemberNames () );

        if ( members.empty () )
            pushValue ( "{}" );
        else
        {
            writeWithIndent ( "{" );
            indent ();
            Value::Members::iterator it = members.begin ();

            while ( true )
            {
                std::string const& name = *it;
                const Value& childValue = value[name];
                writeWithIndent ( valueToQuotedString ( name.c_str () ) );
                *document_ << " : ";
                writeValue ( childValue );

                if ( ++it == members.end () )
                    break;

                *document_ << ",";
            }

            unindent ();
            writeWithIndent ( "}" );
        }
    }
    break;
    }
}
asynStatus NetShrVarDriver::writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value, size_t nElements)
{
    return writeArrayValue(pasynUser, "writeFloat32Array", value, nElements);
}