Beispiel #1
0
WFCB_p ClauseOrientWeightParse(Scanner_p in, OCB_p ocb, ProofState_p
				state)
{
   ClausePrioFun prio_fun;
   int fweight, vweight;
   double pos_multiplier, max_literal_multiplier,
      unorientable_literal_multiplier;

   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   unorientable_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);
   
   return ClauseOrientWeightInit(prio_fun, fweight, vweight, ocb,
				 unorientable_literal_multiplier,
				 max_literal_multiplier,
				 pos_multiplier);
}
Beispiel #2
0
 void ParseVec2(std::vector<Vec2>& buffer)
 {
     Vec2 v;
     v.x = ParseFloat();
     v.y = ParseFloat();
     buffer.push_back(v);
 }
Beispiel #3
0
WFCB_p TPTPTypeWeightParse(Scanner_p in, OCB_p ocb, ProofState_p
			   state)
{
   ClausePrioFun prio_fun;
   int           fweight, vweight;
   double        max_term_multiplier, max_literal_multiplier,
                 pos_multiplier, conjecture_multiplier,
                 hypothesis_multiplier;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   max_term_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   conjecture_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   hypothesis_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);   

   return TPTPTypeWeightInit(prio_fun, fweight, vweight, ocb,
			     max_term_multiplier,
			     max_literal_multiplier, pos_multiplier,
			     conjecture_multiplier,
			     hypothesis_multiplier);
}
	sf::Vector3f ParseVector3f(const std::string theValue, const sf::Vector3f theDefault)
	{
		sf::Vector3f anResult = theDefault;

		// Try to find the first comma
		size_t anComma1Offset = theValue.find_first_of(',', 0);
		if(anComma1Offset != std::string::npos)
		{
			float anX = ParseFloat(theValue.substr(0, anComma1Offset), theDefault.x);

			// Try to find the next comma
			size_t anComma2Offset = theValue.find_first_of(',',anComma1Offset+1);
			if(anComma2Offset != std::string::npos)
			{
				float anY = ParseFloat(theValue.substr(anComma1Offset+1, anComma2Offset), theDefault.y);
				float anZ = ParseFloat(theValue.substr(anComma2Offset+1), theDefault.z);

				// Now that all 3 values have been parsed, return the Vector3f found
				anResult.x = anX;
				anResult.y = anY;
				anResult.z = anZ;
			}
		}

		// Return the result found or theDefault assigned above
		return anResult;
	}
Beispiel #5
0
Features_p NumFeaturesParse(Scanner_p in)
{
   Features_p handle = FeaturesAlloc();
   long i;

   AcceptInpId(in, "PA");
   AcceptInpTok(in, Colon);
   handle->pred_max_arity = parse_sig_distrib(in,
					      handle->pred_distrib);

   AcceptInpId(in, "FA");
   AcceptInpTok(in, Colon);
   handle->func_max_arity = parse_sig_distrib(in,
					      handle->func_distrib);
   AcceptInpTok(in, OpenBracket);
   handle->features[0] = ParseFloat(in);
   for(i=1; i< FEATURE_NUMBER; i++)
   {
      AcceptInpTok(in, Comma);
      handle->features[i] = ParseFloat(in);
   }
   AcceptInpTok(in, CloseBracket);

   return handle;
}
Beispiel #6
0
WFCB_p WeightLessDepthParse(Scanner_p in, OCB_p ocb, ProofState_p
		      state)
{
   ClausePrioFun prio_fun;
   int           fweight, vweight;
   double        max_term_multiplier, max_literal_multiplier,
                 pos_multiplier, term_depth_multiplier;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   max_term_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   max_literal_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   term_depth_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);   
   
   return WeightLessDepthInit(prio_fun, fweight, vweight, ocb,
			      max_term_multiplier, max_literal_multiplier,
			      pos_multiplier, term_depth_multiplier);
}
Beispiel #7
0
novatel_gps_msgs::GpgsaPtr novatel_gps_driver::GpgsaParser::ParseAscii(const novatel_gps_driver::NmeaSentence& sentence) throw(ParseException)
{
  // Check the length first -- should be 18 elements long
  const size_t LENGTH = 18;
  if (sentence.body.size() != LENGTH)
  {
    std::stringstream error;
    error << "Expected GPGSA length " << LENGTH
          << ", actual length " << sentence.body.size();
    throw ParseException(error.str());
  }

  novatel_gps_msgs::GpgsaPtr msg = boost::make_shared<novatel_gps_msgs::Gpgsa>();
  msg->message_id = sentence.body[0];
  msg->auto_manual_mode = sentence.body[1];
  ParseUInt8(sentence.body[2], msg->fix_mode);
  // Words 3-14 of the sentence are SV IDs. Copy only the non-null strings.
  msg->sv_ids.resize(12, 0);
  size_t n_svs = 0;
  for (std::vector<std::string>::const_iterator id = sentence.body.begin()+3; id < sentence.body.begin()+15; ++id)
  {
    if (! id->empty())
    {
      ParseUInt8(*id, msg->sv_ids[n_svs]);
      ++n_svs;
    }
  }
  msg->sv_ids.resize(n_svs);

  ParseFloat(sentence.body[15], msg->pdop);
  ParseFloat(sentence.body[16], msg->hdop);
  ParseFloat(sentence.body[17], msg->vdop);
  return msg;
}
   glm::vec3
   POVRayParser::ParseVec3FromStream(std::istringstream& tokens)
   {
      std::string token;

      std::getline(tokens, token, ',');
      float x = ParseFloat(token);

      std::getline(tokens, token, ',');
      float y = ParseFloat(token);

      std::getline(tokens, token, '>');
      float z = ParseFloat(token);

      return glm::vec3(x, y, z);
   }
Beispiel #9
0
KBDesc_p KBDescParse(Scanner_p in)
{
   KBDesc_p handle = KBDescCellAlloc();
   
   AcceptInpId(in, "Version");
   AcceptInpTok(in, Colon);
   CheckInpTok(in, String);
   handle->version = DStrCopy(AktToken(in)->literal);
   
   if(strcmp(handle->version, KB_VERSION) > 0)
   {
      Error("Knowledge base is younger than your tool set. Please"
	    " update from" E_URL, USAGE_ERROR);
   }
   NextToken(in);
   AcceptInpId(in, "NegProp");
   AcceptInpTok(in, Colon);
   handle->neg_proportion = ParseFloat(in);
   AcceptInpId(in, "FailExamples");
   AcceptInpTok(in, Colon);
   handle->fail_neg_examples = AktToken(in)->numval;
   AcceptInpTok(in, PosInt);

   return handle;
}
	float ConfigReader::GetFloat(const std::string theSection,
		const std::string theName, const float theDefault) const
	{
		float anResult = theDefault;

		// Check if theSection really exists
		std::map<const std::string, typeNameValue*>::const_iterator iter;
		iter = mSections.find(theSection);
		if(iter != mSections.end())
		{
			// Try to obtain the name, value pair
			typeNameValue* anMap = iter->second;
			if(NULL != anMap)
			{
				typeNameValueIter iterNameValue;
				iterNameValue = anMap->find(theName);
				if(iterNameValue != anMap->end())
				{
					anResult = ParseFloat(iterNameValue->second, theDefault);
				}
			}
		}

		// Return the result found or theDefault assigned above
		return anResult;
	}
	sf::Vector2f ParseVector2f(const std::string theValue, const sf::Vector2f theDefault)
	{
		sf::Vector2f anResult = theDefault;

		// Try to find the first comma
		size_t anCommaOffset = theValue.find_first_of(',');
		if(anCommaOffset != std::string::npos)
		{
			float anX = ParseFloat(theValue.substr(0,anCommaOffset), theDefault.x);
			float anY = ParseFloat(theValue.substr(anCommaOffset+1), theDefault.y);

			// Now that both values have been parsed, return the vector found
			anResult.x = anX;
			anResult.y = anY;
		}

		// Return the result found or theDefault assigned above
		return anResult;
	}
void FeatureDataIterator::readNext() {
  m_next.clear();
  try {
    StringPiece marker = m_in->ReadDelimited();
    if (marker != StringPiece(FEATURES_TXT_BEGIN)) {
      throw FileFormatException(m_in->FileName(), marker.as_string());
    }
    size_t sentenceId = m_in->ReadULong();
    size_t count = m_in->ReadULong();
    size_t length = m_in->ReadULong();
    m_in->ReadLine(); //discard rest of line
    for (size_t i = 0; i < count; ++i) {
      StringPiece line = m_in->ReadLine();
      m_next.push_back(FeatureDataItem());
      for (TokenIter<AnyCharacter, true> token(line, AnyCharacter(" \t")); token; ++token) {
        TokenIter<AnyCharacter,false> value(*token,AnyCharacter(":"));
        if (!value) throw FileFormatException(m_in->FileName(), line.as_string());
        StringPiece first = *value;
        ++value;
        if (!value) {
          //regular feature
          float floatValue = ParseFloat(first);
          m_next.back().dense.push_back(floatValue);
        } else {
          //sparse feature
          StringPiece second = *value;
          float floatValue = ParseFloat(second);
          m_next.back().sparse.set(first.as_string(),floatValue); 
        }
      }
      if (length != m_next.back().dense.size()) {
        throw FileFormatException(m_in->FileName(), line.as_string());
      }
    }
    StringPiece line = m_in->ReadLine();
    if (line != StringPiece(FEATURES_TXT_END)) {
      throw FileFormatException(m_in->FileName(), line.as_string());
    }
  } catch (EndOfFileException &e) {
    m_in.reset();
  }
}
Beispiel #13
0
WFCB_p ClauseWeightAgeParse(Scanner_p in, OCB_p ocb, ProofState_p state)
{
   ClausePrioFun prio_fun;
   int fweight, vweight;
   double pos_multiplier, weight_multiplier;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   fweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   vweight = ParseInt(in);
   AcceptInpTok(in, Comma);
   pos_multiplier = ParseFloat(in);
   AcceptInpTok(in, Comma);
   weight_multiplier = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);
   
   return ClauseWeightAgeInit(prio_fun, fweight, vweight,
			      pos_multiplier, weight_multiplier); 
}
Beispiel #14
0
//------------------------------------------------------
// ParseRotationDelta
//	Reads in a ranged rotationDelta value
//
// input:
//	string that contains one or two floats
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseRotationDelta( const gsl::cstring_view& val )
{
	float min, max;

	if ( ParseFloat( val, min, max ) == qtrue )
	{
		mRotationDelta.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #15
0
//------------------------------------------------------
// ParseRotationDelta
//	Reads in a ranged rotationDelta value
//
// input:
//	string that contains one or two floats
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseRotationDelta( const char *val )
{
	float min, max;

	if ( ParseFloat( val, &min, &max ) == qtrue )
	{
		mRotationDelta.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #16
0
//------------------------------------------------------
// ParseRGBParm
//	Reads in a ranged rgbParm field in float format
//
// input:
//	string that contains one or two floats
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseRGBParm( const char *val )
{
	float min, max;

	if ( ParseFloat( val, &min, &max ) == true )
	{
		mRGBParm.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #17
0
//------------------------------------------------------
// ParseCount
//	Reads in a ranged count value
//
// input:
//	string that contains a float range ( two vals )
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseCount( const char *val )
{
	float min, max;

	if ( ParseFloat( val, &min, &max ) == true )
	{
		mSpawnCount.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #18
0
/** Parse opacity (a float between 0.0 and 1.0). */
unsigned int ParseOpacity(const TokenNode *tp, const char *str)
{
   const float value = ParseFloat(str);
   if(JUNLIKELY(value <= 0.0 || value > 1.0)) {
      ParseError(tp, _("invalid opacity: %s"), str);
      return UINT_MAX;
   } else if(value == 1.0) {
      return UINT_MAX;
   } else {
      return (unsigned int)(value * UINT_MAX);
   }
}
Beispiel #19
0
//------------------------------------------------------
// ParseLengthStart
//	Reads in a ranged lengthStart field in float format
//
// input:
//	string that contains one or two floats
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseLengthStart( const char *val )
{
	float min, max;

	if ( ParseFloat( val, &min, &max ) == true )
	{
		mLengthStart.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #20
0
WFCB_p SimWeightParse(Scanner_p in, OCB_p ocb, ProofState_p state)
{
   ClausePrioFun prio_fun;
   double equal_weight, var_var_clash, var_term_clash,
      term_term_clash;

   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   equal_weight = ParseFloat(in);
   AcceptInpTok(in, Comma);
   var_var_clash = ParseFloat(in);
   AcceptInpTok(in, Comma);
   var_term_clash = ParseFloat(in);
   AcceptInpTok(in, Comma);
   term_term_clash = ParseFloat(in);
   AcceptInpTok(in, CloseBracket);
   
   return SimWeightInit(prio_fun, equal_weight, var_var_clash,
			var_term_clash, term_term_clash);
}
Beispiel #21
0
//------------------------------------------------------
// ParseRGBParm
//	Reads in a ranged rgbParm field in float format
//
// input:
//	string that contains one or two floats
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseRGBParm( const gsl::cstring_view& val )
{
	float min, max;

	if ( ParseFloat( val, min, max ) == true )
	{
		mRGBParm.SetRange( min, max );
		return true;
	}

	return false;
}
Beispiel #22
0
WFCB_p StaggeredWeightParse(Scanner_p in, OCB_p ocb, ProofState_p
			  state)
{
   ClausePrioFun prio_fun;
   double stagger_factor;
   
   AcceptInpTok(in, OpenBracket);
   prio_fun = ParsePrioFun(in);
   AcceptInpTok(in, Comma);
   stagger_factor = ParseFloat(in);   
   AcceptInpTok(in, CloseBracket);
      
   return StaggeredWeightInit(prio_fun, stagger_factor, state->axioms);
}
Beispiel #23
0
//------------------------------------------------------
// ParseElasticity
//	Reads in a ranged elasticity value
//
// input:
//	string that contains a float range ( two vals )
//
// return:
//	success of parse operation.
//------------------------------------------------------
bool CPrimitiveTemplate::ParseElasticity( const char *val )
{
	float min, max;

	if ( ParseFloat( val, &min, &max ) == true )
	{
		mElasticity.SetRange( min, max );

		// We assume that if elasticity is set that we are using physics, but don't assume we are
		//	using a bounding box unless a min/max are explicitly set
//		mFlags |= FX_APPLY_PHYSICS;
		return true;
	}

	return false;
}
// ------------------------------------------------------------------------------------------------
void ColladaModelFactory::ParseEffectFloat(xml_node* node, const char * name, float * out)
{
    if(node)
    {
        // get 'float' descendant
        xml_node* parentNode = FindFirstByName(node, name);
        xml_node* floatNode = FindFirstByName(parentNode, "float");
        if (floatNode)
        {
            // get single floats
            if (!ParseFloat(floatNode, out))
            {
                ParseError("'%s' 'float' element has no floats\n", name);
            }
        }
    }
}
Beispiel #25
0
 Finish
 POVRayParser::ParseFinish(std::istringstream& tokens)
 {
    float ambient, diffuse, emissive, specular, roughness, reflection, refraction, ior;
    ambient = diffuse = emissive = specular = roughness = reflection = refraction = ior = 0.f;
    std::string token;
    bool running(true);
    while (running && std::getline(tokens, token, ' ')) {
       if (token.find("}") != std::string::npos) //Exit if we reach the closing '}'
          running = false;
       //Parse different types of Finish floats
       if (token.find("ambient") != std::string::npos) {
          tokens >> token;
          if (token.find("}") != std::string::npos) //Exit if we reach the closing '}'
          running = false;
          ambient = ParseFloat(token);
       }
       else if (token.find("diffuse") != std::string::npos) {
Beispiel #26
0
novatel_gps_msgs::TrackstatPtr
novatel_gps_driver::TrackstatParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
{
  if (sentence.body.size() < ASCII_BODY_FIELDS)
  {
    std::stringstream error;
    error << "Unexpected number of body fields in TRACKSTAT log: " << sentence.body.size();
    throw ParseException(error.str());
  }

  uint32_t n_channels = 0;
  ParseUInt32(sentence.body[3], n_channels, 10);

  if (sentence.body.size() != ASCII_BODY_FIELDS + n_channels * ASCII_CHANNEL_FIELDS)
  {
    std::stringstream error;
    error << "Size of TRACKSTAT log did not match expected size.";
    throw ParseException(error.str());
  }

  bool valid = true;
  novatel_gps_msgs::TrackstatPtr msg = boost::make_shared<novatel_gps_msgs::Trackstat>();
  msg->solution_status = sentence.body[0];
  msg->position_type = sentence.body[1];
  valid &= ParseFloat(sentence.body[2], msg->cutoff);

  msg->channels.resize(n_channels);
  for (size_t i = 0; i < static_cast<size_t>(n_channels); ++i)
  {
    size_t offset = 4 + i * ASCII_CHANNEL_FIELDS;
    novatel_gps_msgs::TrackstatChannel& channel = msg->channels[i];
    valid &= ParseInt16(sentence.body[offset], channel.prn);
    valid &= ParseInt16(sentence.body[offset+1], channel.glofreq);
    valid &= ParseUInt32(sentence.body[offset+2], channel.ch_tr_status, 16);
    valid &= ParseDouble(sentence.body[offset+3], channel.psr);
    valid &= ParseFloat(sentence.body[offset+4], channel.doppler);
    valid &= ParseFloat(sentence.body[offset+5], channel.c_no);
    valid &= ParseFloat(sentence.body[offset+6], channel.locktime);
    valid &= ParseFloat(sentence.body[offset+7], channel.psr_res);
    channel.reject = sentence.body[offset+8];
    valid &= ParseFloat(sentence.body[offset+9], channel.psr_weight);
  }

  if (!valid)
  {
    std::stringstream error;
    error << "Error parsing TRACKSTAT log.";
    throw ParseException(error.str());
  }
  return msg;
}
Beispiel #27
0
/*
============
idAASSettings::FromParser
============
*/
bool idAASSettings::FromParser( idLexer &src )
{
    idToken token;

    if ( !src.ExpectTokenString( "{" ) )
    {
        return false;
    }

    // parse the file
    while ( 1 )
    {
        if ( !src.ReadToken( &token ) )
        {
            break;
        }

        if ( token == "}" )
        {
            break;
        }

        if ( token == "bboxes" )
        {
            if ( !ParseBBoxes( src ) )
            {
                return false;
            }
        }
        else if ( token == "usePatches" )
        {
            if ( !ParseBool( src, usePatches ) )
            {
                return false;
            }
        }
        else if ( token == "writeBrushMap" )
        {
            if ( !ParseBool( src, writeBrushMap ) )
            {
                return false;
            }
        }
        else if ( token == "playerFlood" )
        {
            if ( !ParseBool( src, playerFlood ) )
            {
                return false;
            }
        }
        else if ( token == "allowSwimReachabilities" )
        {
            if ( !ParseBool( src, allowSwimReachabilities ) )
            {
                return false;
            }
        }
        else if ( token == "allowFlyReachabilities" )
        {
            if ( !ParseBool( src, allowFlyReachabilities ) )
            {
                return false;
            }
        }
        else if ( token == "fileExtension" )
        {
            src.ExpectTokenString( "=" );
            src.ExpectTokenType( TT_STRING, 0, &token );
            fileExtension = token;
        }
        else if ( token == "gravity" )
        {
            ParseVector( src, gravity );
            gravityDir = gravity;
            gravityValue = gravityDir.Normalize();
            invGravityDir = -gravityDir;
        }
        else if ( token == "maxStepHeight" )
        {
            if ( !ParseFloat( src, maxStepHeight ) )
            {
                return false;
            }
        }
        else if ( token == "maxBarrierHeight" )
        {
            if ( !ParseFloat( src, maxBarrierHeight ) )
            {
                return false;
            }
        }
        else if ( token == "maxWaterJumpHeight" )
        {
            if ( !ParseFloat( src, maxWaterJumpHeight ) )
            {
                return false;
            }
        }
        else if ( token == "maxFallHeight" )
        {
            if ( !ParseFloat( src, maxFallHeight ) )
            {
                return false;
            }
        }
        else if ( token == "minFloorCos" )
        {
            if ( !ParseFloat( src, minFloorCos ) )
            {
                return false;
            }
        }
        else if ( token == "tt_barrierJump" )
        {
            if ( !ParseInt( src, tt_barrierJump ) )
            {
                return false;
            }
        }
        else if ( token == "tt_startCrouching" )
        {
            if ( !ParseInt( src, tt_startCrouching ) )
            {
                return false;
            }
        }
        else if ( token == "tt_waterJump" )
        {
            if ( !ParseInt( src, tt_waterJump ) )
            {
                return false;
            }
        }
        else if ( token == "tt_startWalkOffLedge" )
        {
            if ( !ParseInt( src, tt_startWalkOffLedge ) )
            {
                return false;
            }
        }
        else
        {
            src.Error( "invalid token '%s'", token.c_str() );
        }
    }

    if ( numBoundingBoxes <= 0 )
    {
        src.Error( "no valid bounding box" );
    }

    return true;
}
Beispiel #28
0
static bool DecodeField(DecodeState& ds, TxtNode *firstNode, TxtNode *defaultFirstNode, FieldMetadata *fieldDef, uint8_t *structDataStart)
{
    Type type = fieldDef->type;
    uint8_t *structDataPtr = structDataStart + fieldDef->offset;

    if ((type & TYPE_NO_STORE_MASK) != 0) {
        WriteDefaultValue(structDataPtr, type);
        return true;
    }

    bool isCompact = ((type & TYPE_STORE_COMPACT_MASK) != 0);
    type = (Type)(type & TYPE_NO_FLAGS_MASK);

    const char *fieldName = ds.fieldNamesSeq + fieldDef->nameOffset;
    size_t fieldNameLen = str::Len(fieldName);
    TxtNode *dataNode = FindNode(firstNode, fieldName, fieldNameLen);
    TxtNode *defaultNode = FindNode(defaultFirstNode, fieldName, fieldNameLen);

    // if the node doesn't exist in data, try to get it from default data
    TxtNode *node = dataNode ? dataNode : defaultNode;
    if (!node) {
        WriteDefaultValue(structDataPtr, type);
        return true;
    }
    bool ok;
    if (TYPE_BOOL == type) {
        bool bVal;
        ok = ParseBool(node->valStart, node->valEnd, &bVal);
        if (!ok)
            return false;
        WriteStructBool(structDataPtr, bVal);
    } else if (TYPE_COLOR == type) {
        COLORREF val;
        ok = ParseColor(node->valStart, node->valEnd, &val);
        if (ok)
            WriteStructUInt(structDataPtr, TYPE_COLOR, val);
    } else if (IsUnsignedIntType(type)) {
        uint64_t n;
        ok = ParseUInt(node->valStart, node->valEnd, &n);
        if (ok)
            ok = WriteStructUInt(structDataPtr, type, n);
    } else if (IsSignedIntType(type)) {
        int64_t n;
        ok = ParseInt(node->valStart, node->valEnd, &n);
        if (ok)
            ok = WriteStructInt(structDataPtr, type, n);
    } else if (TYPE_STRUCT_PTR == type) {
        uint8_t *d = NULL;
        if (isCompact && (TextNode == node->type)) {
            d = DeserializeCompact(ds, node, defaultNode, fieldDef->def);
        } else {
            if (StructNode != node->type)
                return false;
            d = DeserializeRec(ds, node, defaultNode, fieldDef->def);
        }
        if (!d)
            goto Error;
        WriteStructPtrVal(structDataPtr, d);
    } else if (TYPE_STR == type) {
        char *s = node->valStart;
        size_t sLen = node->valEnd - s;
        if (s && (sLen > 0)) {
            // note: we don't free s because it's remembered in structDataPtr
            s = str::DupN(s, sLen);
            WriteStructStr(structDataPtr, s);
        }
    } else if (TYPE_WSTR == type) {
        char *s = node->valStart;
        size_t sLen = node->valEnd - s;
        if (s && (sLen > 0)) {
            // note: we don't free ws because it's remembered in structDataPtr
            WCHAR *ws = str::conv::FromUtf8(s);
            WriteStructWStr(structDataPtr, ws);
        }
    }  else if (TYPE_FLOAT == type) {
        float f;
        ok = ParseFloat(node->valStart, node->valEnd, &f);
        if (ok)
            WriteStructFloat(structDataPtr, f);
    } else if (TYPE_ARRAY == type) {
        CrashIf(!fieldDef->def); // array elements must be a struct
        if (StructNode != node->type)
            return false;
        TxtNode *child;
        ListNode<void> *last = NULL;
        for (size_t i = 0; i < node->children->Count(); i++) {
            child = node->children->At(i);
            if (ArrayNode != child->type)
                return false;
            uint8_t *d = DeserializeRec(ds, child, NULL, fieldDef->def);
            if (!d)
                goto Error; // TODO: free root
            ListNode<void> *tmp = AllocArray<ListNode<void>>(1);
            tmp->val = (void*)d;
            if (!last) {
                // this is root
                last = tmp;
                // we remember it so that it gets freed in case of error
                WriteStructPtrVal(structDataPtr, (void*)last);
            } else {
                last->next = tmp;
                last = tmp;
            }
        }
    } else {
        CrashIf(true);
        return false;
    }
    return true;
Error:
    return false;
}
Beispiel #29
0
static float ParseLayoutFloat(const char* s) {
    if (str::EqI(s, "self"))
        return SizeSelf;
    return ParseFloat(s);
}
Beispiel #30
0
static void AddStyleProp(Style* style, TxtNode* prop) {
    AutoFree tmp(prop->ValDup());

    if (prop->IsTextWithKey("name")) {
        style->SetName(tmp);
        return;
    }

    if (prop->IsTextWithKey("bg_col")) {
        style->Set(Prop::AllocColorSolid(PropBgColor, tmp));
        return;
    }

    if (prop->IsTextWithKey("col")) {
        style->Set(Prop::AllocColorSolid(PropColor, tmp));
        return;
    }

    if (prop->IsTextWithKey("parent")) {
        Style* parentStyle = StyleByName(tmp);
        CrashIf(!parentStyle);
        style->SetInheritsFrom(parentStyle);
        return;
    }

    if (prop->IsTextWithKey("border_width")) {
        style->SetBorderWidth(ParseFloat(tmp));
        return;
    }

    if (prop->IsTextWithKey("padding")) {
        ParsedPadding padding = {0};
        ParsePadding(tmp, padding);
        style->SetPadding(padding.top, padding.right, padding.bottom, padding.left);
        return;
    }

    if (prop->IsTextWithKey("stroke_width")) {
        style->Set(Prop::AllocWidth(PropStrokeWidth, ParseFloat(tmp)));
        return;
    }

    if (prop->IsTextWithKey("fill")) {
        style->Set(Prop::AllocColorSolid(PropFill, tmp));
        return;
    }

    if (prop->IsTextWithKey("vert_align")) {
        style->Set(Prop::AllocAlign(PropVertAlign, ParseElAlign(tmp)));
        return;
    }

    if (prop->IsTextWithKey("text_align")) {
        style->Set(Prop::AllocTextAlign(ParseAlignAttr(tmp)));
        return;
    }

    if (prop->IsTextWithKey("font_size")) {
        style->Set(Prop::AllocFontSize(ParseFloat(tmp)));
        return;
    }

    if (prop->IsTextWithKey("font_weight")) {
        style->Set(Prop::AllocFontWeight(ParseFontWeight(tmp)));
        return;
    }

    CrashIf(true);
}