Ejemplo n.º 1
0
// static 
ASTType* ASTType::fromString(const String& type)
{
   std::size_t pos = type.lastIndexOf('[');
   if ( pos != String::npos )
   {
      String arraytype = type.subStr(0, pos);
      ASTType* parray = new ASTType(ASTType::eArray);
      parray->setArrayType(fromString(arraytype));
      parray->determineArrayDimension();
      return parray;
   }

   if ( type == SBool )
   {
      return new ASTType(ASTType::eBoolean);
   }
   else if ( type == SInt  )
   {
      return new ASTType(ASTType::eInt);
   }
   else if ( type == SReal )
   {
      return new ASTType(ASTType::eReal);
   }
   else if ( type == SChar )
   {
      return new ASTType(ASTType::eChar);
   }
   else if ( type == SString )
   {
      return new ASTType(ASTType::eString);
   }
   else if ( type == SVoid )
   {
      return new ASTType(ASTType::eVoid);
   }
   else
   {
      String value;

      // todo, what with generics?
      ASTType::Kind kind = ASTType::eObject;
      if ( type[0] == '~' ) {
         kind = ASTType::eGeneric;
         value = type.subStr(1, type.length() - 1);
      }
      else
         value = type;

      ASTType* ptype = new ASTType(kind);
      ptype->setObjectName(value);
      return ptype;
   }
   return NULL;
}
Ejemplo n.º 2
0
	bool CommandLine::hasArg(double& _value, const char _short, const char* _long) const
	{
		const char* arg = findOption(_short, _long, 1);
		if (NULL != arg)
		{
			fromString(&_value, arg);
			return true;
		}

		return false;
	}
Ejemplo n.º 3
0
static Variant strtotimeImpl(const String& input, int64_t timestamp) {
  if (input.empty()) {
    return false;
  }
  auto dt = req::make<DateTime>(timestamp);
  if (!dt->fromString(input, req::ptr<TimeZone>(), nullptr, false)) {
    return false;
  }
  bool error;
  return dt->toTimeStamp(error);
}
Ejemplo n.º 4
0
void LoadBackpackPage::setSellList( char *inSellList ) {
    mSellRecords.deleteAll();
    
    fromString( inSellList, &mSellRecords );

    // this is a fresh loading session
    // undoing old purchase history here would be confusing (and sometimes
    // incorrect)
    mPurchaseHistory.deleteAll();
    mUndoButton.setVisible( false );
    }
Ejemplo n.º 5
0
QDecNumber& QDecNumber::fromDouble(double d)
{
  char str[MaxStrSize] = { 0 };

 #if defined(_MSC_VER)
  _snprintf(str, MaxStrSize, "%.*g", QDecNumDigits, d);
 #else
  snprintf(str, MaxStrSize, "%.*g", QDecNumDigits, d);
 #endif
  return fromString(str);
}
Ejemplo n.º 6
0
/** Constructor. Creates a new Policy object from the given string. */
Policy::Policy(QString policy)
{
  /* Set the defaults */
  _action   = Accept;
  _address  = QHostAddress::Any;
  _fromPort = _toPort = 0;
  _mask = 0;

  /* Parse the given string to override the defaults. */
  fromString(policy);
}
bool Enum::operator=(QString other) {
    return fromString(other);

/*    if (nameMap()names().contains(other)) {
        m_Val = names().indexOf(other);
        return true;
    }
    qDebug() << "operator= Undefined other: " << other;
    return false;
*/
}
Ejemplo n.º 8
0
std::string getLinuxPath(const std::string& path)
{
#ifdef WIN32
  QString command("cygpath -u \"");
  command += fromString(path) + "\"";
  ProcessRunner r(command);
  return toString(r.getOutput().trimmed());
#else
  return path;
#endif
}
Ejemplo n.º 9
0
		void run()
		{
			// Test IP construction
			IP fromString("192.168.0.1");

			if (fromString.getOctet(0) != 192
			        || fromString.getOctet(1) != 168
			        || fromString.getOctet(2) != 0
			        || fromString.getOctet(3) != 1)
				throw TestFailedException("An IP could not be properly constructed from a string.");

			// Test provided octet construction
			IP fromOctets(192, 168, 0, 1);

			if (fromOctets.getOctet(0) != 192
			        || fromOctets.getOctet(1) != 168
			        || fromOctets.getOctet(2) != 0
			        || fromOctets.getOctet(3) != 1)
				throw TestFailedException("An IP could not be properly constructed from octets.");

			// Test string representation
			if (strcmp("192.168.0.1", fromOctets.getAsString().c_str()) != 0)
				throw TestFailedException("An IP's string representation was incorrect.");

			// Test inequality
			if (fromString != fromOctets)
				throw TestFailedException("Inequality operator failed");

			// Test equality
			IP different = (std::string) "127.0.0.1";

			if (different.getOctet(0) != 127 || different.getOctet(1) != 0
			        || different.getOctet(2) != 0 || different.getOctet(3) != 1)
				throw TestFailedException("An IP could not be constructed from a string.");

			if (fromOctets == different)
				throw TestFailedException("Equality operator failed");

			// Test assignment from string
			different = "74.125.113.99";

			if (different.getOctet(0) != 74
			        || different.getOctet(1) != 125
			        || different.getOctet(2) != 113
			        || different.getOctet(3) != 99)
				throw TestFailedException("An IP could not be assigned from a string.");

			// Test binary representation
			unsigned int binRep = (208 << 24) + (47 << 16) + (17 << 8) + 18;
			IP fromBin(binRep, IP::BO_HOST);

			if (binRep != fromBin.getAsBinary(IP::BO_HOST))
				throw TestFailedException("An IP's binary representation was incorrect.");
		}
Ejemplo n.º 10
0
bool Format::load( const QString &f )
{
  if ( !QFile::exists( f ) ) return false;

  QFile file( f );
  if ( !file.open( QIODevice::ReadOnly ) ) return false;

  QByteArray data = file.readAll();
  QString str = QString::fromUtf8( data );

  return fromString( str );
}
Ejemplo n.º 11
0
bool SCPCmd::SCPTask::execute()
{
  ProcessRunner r(context(), fromString(command));
  r.run();

  if(r.error())
  {
    context().errorLine(robot->name + ": scp command failed.");
    return false;
  }
  return true;
}
Ejemplo n.º 12
0
Variant f_date_create(const String& time /* = null_string */,
                      CObjRef timezone /* = null_object */) {
  c_DateTime *cdt = NEWOBJ(c_DateTime)();
  Object ret(cdt);
  // Don't set the time here because it will throw if it is bad
  cdt->t___construct();
  auto dt = c_DateTime::unwrap(ret);
  if (!dt->fromString(time, c_DateTimeZone::unwrap(timezone), nullptr, false)) {
    return false;
  }
  return ret;
}
Ejemplo n.º 13
0
bool StimParams::fromFile(const QString & fn)
{
    QFile f(fn);
    if (!f.open(QIODevice::ReadOnly|QIODevice::Text)) return false;
    QString line, str("");
    QTextStream ts(&f), strts(&str, QIODevice::WriteOnly|QIODevice::Append|QIODevice::Text);
    while ( !(line = ts.readLine()).isNull() ) {
        strts << line << "\n";
    }
    strts.flush();
    fromString(str);
    return true;
}
Ejemplo n.º 14
0
 Engine* Importer::fromFile(const std::string& path) const {
     std::ifstream reader(path.c_str());
     if (not reader.is_open()) {
         throw fl::Exception("[file error] file <" + path + "> could not be opened", FL_AT);
     }
     std::ostringstream textEngine;
     std::string line;
     while (std::getline(reader, line)) {
         textEngine << line << std::endl;
     }
     reader.close();
     return fromString(textEngine.str());
 }
Ejemplo n.º 15
0
	ParserImpl& fromStream(std::istream& stream_, const std::string filename){
		std::stringstream ss;
		char buff[8192];
		while(!stream_.eof()){
			stream_.read(buff, sizeof(buff));
			if ( stream_.fail() && !stream_.eof() ) {
				break;
			}
			ss.write(buff, stream_.gcount());
		}
		std::string src = ss.str();
		return fromString(src, filename, 0);
	}
bool UpdateWirelessCmd::UpdateWirelessTask::execute()
{
  ProcessRunner r(context(), fromString(command));
  r.run();

  if(r.error())
  {
    context().errorLine("UpdateWireless of \"" + robot->name + "\" failed!");
    return false;
  }
  else
    return true;
}
Ejemplo n.º 17
0
size_t Convert::fromString(PVStructurePtr const &pvStructure, StringArray const & from, size_t fromStartIndex)
{
    size_t processed = 0;
    
    PVFieldPtrArray const & fieldsData = pvStructure->getPVFields();
    if (fieldsData.size() != 0) {
        size_t length = pvStructure->getStructure()->getNumberFields();
        for(size_t i=0; i<length; i++) {
            PVFieldPtr fieldField = fieldsData[i];

            Type type = fieldField->getField()->getType();
            if(type==structure) {
                PVStructurePtr pv = static_pointer_cast<PVStructure>(fieldField);
                size_t count = fromString(pv, from, fromStartIndex);
                processed += count;
                fromStartIndex += count;
            }
            else if(type==scalarArray) {
                PVScalarArrayPtr pv = static_pointer_cast<PVScalarArray>(fieldField);
                size_t count = fromString(pv, from[fromStartIndex]);
                processed += count;
                fromStartIndex += count;
            }
            else if(type==scalar) {
                PVScalarPtr pv = static_pointer_cast<PVScalar>(fieldField);
                fromString(pv, from[fromStartIndex++]);
                processed++;
            }
            else {
                // union, structureArray, unionArray not supported
                std::ostringstream oss;
                oss << "Convert::fromString unsupported fieldType " << type;
                throw std::logic_error(oss.str());
            }
        }
    }
    
    return processed;
}
Ejemplo n.º 18
0
Colour::Colour(const std::string& str)
{
  try
  {
    //First attempt to load as JSON string
    json jval = json::parse(str);
    fromJSON(jval);
  }
  catch (std::exception& e)
  {
    //Not valid JSON, assume other string value
    fromString(str);
  }
}
Ejemplo n.º 19
0
QVector<QUuid> qVectorQUuidFromScriptValue(const QScriptValue& array) {
    if (!array.isArray()) {
        return QVector<QUuid>();
    }
    QVector<QUuid> newVector;
    int length = array.property("length").toInteger();
    newVector.reserve(length);
    for (int i = 0; i < length; i++) {
        QString uuidAsString = array.property(i).toString();
        QUuid fromString(uuidAsString);
        newVector << fromString;
    }
    return newVector;
}
Ejemplo n.º 20
0
bool DownloadLogsCmd::DownloadLogsTask::execute()
{
  QString command = getCommand();
  QStringList args = QStringList();
  args.push_back("-d"); //delete files after download.

  args.push_back(fromString(robot->name));
  args.push_back(fromString(robot->getBestIP()));

  ProcessRunner r(context(), command, args);
  r.run();

  if(r.error())
  {
    context().errorLine("Download failed!");
  }
  else
  {
    context().printLine("Success! (" + robot->name + ")");
  }

  return true;
}
Ejemplo n.º 21
0
void loadPattern(const string &filename)
{
	FILE* in = tryOpen(filename, "r");
	for (;getLine(in);) {
		vector<string> tokens = splitBy(line, ',');
		string pattern = tolower(tokens[0]);
		int occurrence;
		fromString(tokens[1], occurrence);

		oldProb[pattern] = occurrence;
	}
	fclose(in);
//	cerr << "# old prob = " << oldProb.size() << endl;
}
Ejemplo n.º 22
0
QString AnchorHandleItem::toolTipString() const
{
    QString templateString("<p>Anchor Handle</p><p>%1</p><p>%2</p>");
    QmlItemNode fromNode(anchorController().formEditorItem()->qmlItemNode());
    QString fromString(QString("%3: %1(%2)").arg(fromNode.simplifiedTypeName(), fromNode.id(), anchorLineToString(sourceAnchorLine())));

    AnchorLine toAnchorLine(targetAnchorLine());
    QmlItemNode toNode(toAnchorLine.qmlItemNode());
    QString toString;
    if (toNode.isValid())
        toString = QString("%3: %1(%2)").arg(toNode.simplifiedTypeName(), toNode.id(), anchorLineToString(toAnchorLine.type()));

    return templateString.arg(fromString).arg(toString);
}
Ejemplo n.º 23
0
/*
 * advanceInputParser :: Parser
 *
 * Advances the parser down the input chain.
 * Loads input from chain buffers when the present
 * buffer is exhausted.
 */
static void advanceInputParser(Parser *parser) {
  if (*parser->input) {
    parser->input++;
    if (! *parser->input) advanceInputParser(parser);
  } else if (parser->inputChain->next) {
    InputChain *c = parser->inputChain;
    parser->inputChain = parser->inputChain->next;
    parser->input = fromString(parser->inputChain->input);
    freeInputChain(c);
  } else {
    parser->last = NULL;
  }

  return;
}
Ejemplo n.º 24
0
QVariant GCF::Components::ListEditorCreator::editorValue(QWidget* editor)
{
    QLineEdit* lineEdit = qobject_cast<QLineEdit*>(editor);
    if(lineEdit)
    {
        QString text = lineEdit->text();
        QVariant ret = fromString(text);
        QList<QVariant> retList = ret.toList();
        int expectedSize = lineEdit->property("_ListSize_").toInt();
        while(retList.count() < expectedSize)
            retList << 0;
        return retList;
    }
    return QVariant();
}
Ejemplo n.º 25
0
static Variant HHVM_FUNCTION(strtotime, int64_t argc,
                             const String& input, int64_t timestamp) {
  if (input.empty()) {
    return false;
  }
  if (argc < 2) {
    timestamp = TimeStamp::Current();
  }
  auto dt = req::make<DateTime>(timestamp);
  if (!dt->fromString(input, req::ptr<TimeZone>(), nullptr, false)) {
    return false;
  }
  bool error;
  return dt->toTimeStamp(error);
}
Ejemplo n.º 26
0
/**
 * Loads AssociationLine information saved in \a qElement XMI element.
 */
bool AssociationLine::loadFromXMI(QDomElement &qElement)
{
    QString layout = qElement.attribute(QLatin1String("layout"), QLatin1String("polyline"));
    m_layout = fromString(layout);

    QDomNode node = qElement.firstChild();

    m_points.clear();

    QDomElement startElement = node.toElement();
    if(startElement.isNull() || startElement.tagName() != QLatin1String("startpoint")) {
        return false;
    }
    QString x = startElement.attribute(QLatin1String("startx"), QLatin1String("0"));
    qreal nX = x.toFloat();
    QString y = startElement.attribute(QLatin1String("starty"), QLatin1String("0"));
    qreal nY = y.toFloat();
    QPointF startPoint(nX, nY);

    node = startElement.nextSibling();
    QDomElement endElement = node.toElement();
    if(endElement.isNull() || endElement.tagName() != QLatin1String("endpoint")) {
        return false;
    }
    x = endElement.attribute(QLatin1String("endx"), QLatin1String("0"));
    nX = x.toFloat();
    y = endElement.attribute(QLatin1String("endy"), QLatin1String("0"));
    nY = y.toFloat();
    QPointF endPoint(nX, nY);
    setEndPoints(startPoint, endPoint);
    QPointF point;
    node = endElement.nextSibling();
    QDomElement element = node.toElement();
    int i = 1;
    while(!element.isNull()) {
        if(element.tagName() == QLatin1String("point")) {
            x = element.attribute(QLatin1String("x"), QLatin1String("0"));
            y = element.attribute(QLatin1String("y"), QLatin1String("0"));
            point.setX(x.toFloat());
            point.setY(y.toFloat());
            insertPoint(i++, point);
        }
        node = element.nextSibling();
        element = node.toElement();
    }

    return true;
}
Ejemplo n.º 27
0
QUuid RecordBase::DecodeGuid
(
	const QString& decodeMe
) 
{
	QString temp(decodeMe);

	if (temp[0] != QChar('{'))
		temp = QChar('{') + temp;

	if (temp[temp.size() - 1] != QChar('}'))
		temp = temp + QChar('}');

	QUuid fromString(temp);

	return fromString;	
}
Ejemplo n.º 28
0
static bool fromString(const CString& str, PrintTemplate& pt)
{
	CStringArray parts;
	splitString(str, parts, _T('*'));
	if (parts.GetCount() != 6)
		return false;

	// it this a compatible version?
	if (parts[0] != _T("1"))
		return false;

	for (int i=0; i<5; ++i)
		if (fromString(parts[i+1], pt.headings[i]) == false)
			return false;

	return true;
}
Ejemplo n.º 29
0
static void test_utility_fromString()
{
    bool b;
    ASSERT(fromString(b, "false") && !b);
    ASSERT(fromString(b, "true") && b);
    ASSERT(fromString(b, "fd") && !b);  // 也就是说, 对于bool永成功, 且只有"true"的时候读取true

    String s;
    ASSERT(fromString(s, "false") && s == "false");

    char c;
    ASSERT(fromString(c, "A") && c == 'A');
    ASSERT(!fromString(c, "sdf"));  // 长度过长

    int i;
    ASSERT(fromString(i, "564") && i == 564);
    ASSERT(!fromString(i, "f564"));
    // ASSERT(!fromString(i, "564f"));
}   
Ejemplo n.º 30
0
PVariable Variable::fromString(std::string& value, DeviceDescription::IPhysical::Type::Enum type)
{
	VariableType variableType = VariableType::tVoid;
	switch(type)
	{
	case DeviceDescription::IPhysical::Type::Enum::none:
		break;
	case DeviceDescription::IPhysical::Type::Enum::tBoolean:
		variableType = VariableType::tBoolean;
		break;
	case DeviceDescription::IPhysical::Type::Enum::tInteger:
		variableType = VariableType::tInteger;
		break;
	case DeviceDescription::IPhysical::Type::Enum::tString:
		variableType = VariableType::tString;
		break;
	}
	return fromString(value, variableType);
}