Ejemplo n.º 1
0
bool triSurface::readAC(const fileName& ACfileName)
{
    IFstream ACfile(ACfileName);

    if (!ACfile.good())
    {
        FatalErrorIn("triSurface::readAC(const fileName&)")
            << "Cannot read file " << ACfileName
            << exit(FatalError);
    }

    string line;
    ACfile.getLine(line);

    string version = line.substr(4);

    if (version != "b")
    {
        WarningIn("bool triSurface::readAC(const fileName& ACfileName)")
            << "When reading AC3D file " << ACfileName
            << " read header " << line << " with version " << version
            << endl << "Only tested reading with version 'b'."
            << " This might give problems" << endl;
    }

    string cmd;

    string args;

    if (!readUpto("OBJECT", ACfile, args) || (args != "world"))
    {
        FatalErrorIn("bool triSurface::readAC(const fileName& ACfileName)")
            << "Cannot find \"OBJECT world\" in file " << ACfileName
            << exit(FatalError);
    }

    // Number of kids = patches

    readUpto("kids", ACfile, args, "");

    label nPatches = parseInt(args);

    // Storage for patches and unmerged points and faces

    DynamicList<point> points;
    DynamicList<labelledTri> faces;
    geometricSurfacePatchList patches(nPatches);


    // Start of vertices for object/patch
    label patchStartVert = 0;

    for (label patchI = 0; patchI < nPatches; patchI++)
    {
        readUpto("OBJECT", ACfile, args, " while reading patch " + patchI);

        // Object global values
        string patchName = string("patch") + name(patchI);
        label nVerts = 0;
        tensor rot(I);
        vector loc(0, 0, 0);

        // Read all info for current patch
        while (ACfile.good())
        {
            // Read line and get first word. If end of file break since
            // patch should always end with 'kids' command ?not sure.
            if (!readCmd(ACfile, cmd, args))
            {
                FatalErrorIn("triSurface::readAC(const fileName&)")
                    << "Did not read up to \"kids 0\" while reading patch "
                    << patchI << " from file " << ACfileName
                    << exit(FatalError);
            }

            if (cmd == "name")
            {
                IStringStream nameStream(args);

                nameStream >> patchName;
            }
            else if (cmd == "rot")
            {
                // rot %f %f %f  %f %f %f  %f %f %f
                IStringStream lineStream(args);

                lineStream
                    >> rot.xx() >> rot.xy() >> rot.xz()
                    >> rot.yx() >> rot.yy() >> rot.yz()
                    >> rot.zx() >> rot.zy() >> rot.zz();

                WarningIn("triSurface::readAC(const fileName&)")
                    << "rot (rotation tensor) command not implemented"
                    << "Line:" << cmd << ' ' << args << endl
                    << "while reading patch " << patchI << endl;
            }
Ejemplo n.º 2
0
ConcFileArchive::ConcFileArchive(std::vector<std::string> inFileNames)
{
	std::vector<std::string>::iterator fn,pp;
	std::vector<std::string> allConcNames;
	std::vector<double> allWdirs, allWspeeds;
	std::string pathRoot, dirNamePart, fileNamePart;
	for(fn=inFileNames.begin();fn!=inFileNames.end();fn++)
	{
	  pathRoot="";
	  std::vector<std::string> pathParts,fileNameParts;
	  std::string separator("/");
	  pathParts=split(*fn,separator);
	  dirNamePart=pathParts[pathParts.size()-2];
	  fileNamePart=pathParts[pathParts.size()-1];
	  fileNameParts=split(fileNamePart,".");
	 	  
	  for( pp=pathParts.begin();pp!=pathParts.end()-2;pp++)
	    pathRoot+="/"+*pp;    
  
	  for(int i=0;i<int(dirNamePart.size());i++)
	    {
	      std::string oldSeparator="_";
	      std::string newSeparator=" ";
	      if(dirNamePart.substr(i,1)==oldSeparator)
		dirNamePart.replace(i,1,newSeparator);
	    }
	  
	  std::stringstream nameStream(dirNamePart);
	  double wdir,wspeed;
	  std::string concName,dummy;

	  nameStream>>dummy;//gets rid of the wspeed prefix
	  nameStream>>wspeed;
	  nameStream>>dummy;//gets rid of the wdir prefix
	  nameStream>>wdir;
	  
	  allWdirs.push_back(wdir);
	  allWspeeds.push_back(wspeed);
	  allConcNames.push_back(fileNamePart);
	}
		
	wdirs=unique(allWdirs);
	wdirs=sort(wdirs);
	wspeeds=unique(allWspeeds);
	wspeeds=sort(wspeeds);
	concNames=unique(allConcNames);
	nWdirs=int(wdirs.size());
	nWspeeds=int(wspeeds.size());
	nConcNames=int(concNames.size());

	for(int concInd=0;concInd<nConcNames;concInd++)
	{
		for(int speedInd=0;speedInd<nWspeeds;speedInd++)
		{
			for(int dirInd=0;dirInd<nWdirs;dirInd++)
			{
				std::stringstream fnStream;
				fnStream<<pathRoot<<"/"<<"wspeed_";
				fnStream<<std::setiosflags(std::ios::fixed)<<std::setprecision(1)<<wspeeds[speedInd];
				fnStream<<"_wdir_";
				fnStream<<std::setiosflags(std::ios::fixed)<<std::setprecision(1)<<wdirs[dirInd];
				fnStream<<"/"<<concNames[concInd];
				std::string fileName;
				fnStream >> fileName;
				ScalarFoamFile foamFile(fileName);
				fileVec.push_back(foamFile);
				concs.push_back(-9999.0);
				fileNames.push_back(fileName);
			}
		}
	}
}
Ejemplo n.º 3
0
bool QSslCertificatePrivate::parse(const QByteArray &data)
{
    QAsn1Element root;

    QDataStream dataStream(data);
    if (!root.read(dataStream) || root.type() != QAsn1Element::SequenceType)
        return false;

    QDataStream rootStream(root.value());
    QAsn1Element cert;
    if (!cert.read(rootStream) || cert.type() != QAsn1Element::SequenceType)
        return false;

    // version or serial number
    QAsn1Element elem;
    QDataStream certStream(cert.value());
    if (!elem.read(certStream))
        return false;

    if (elem.type() == QAsn1Element::Context0Type) {
        QDataStream versionStream(elem.value());
        if (!elem.read(versionStream) || elem.type() != QAsn1Element::IntegerType)
            return false;

        versionString = QByteArray::number(elem.value()[0] + 1);
        if (!elem.read(certStream))
            return false;
    } else {
        versionString = QByteArray::number(1);
    }

    // serial number
    if (elem.type() != QAsn1Element::IntegerType)
        return false;
    serialNumberString = colonSeparatedHex(elem.value());

    // algorithm ID
    if (!elem.read(certStream) || elem.type() != QAsn1Element::SequenceType)
        return false;

    // issuer info
    if (!elem.read(certStream) || elem.type() != QAsn1Element::SequenceType)
        return false;

    QByteArray issuerDer = data.mid(dataStream.device()->pos() - elem.value().length(), elem.value().length());
    issuerInfo = elem.toInfo();

    // validity period
    if (!elem.read(certStream) || elem.type() != QAsn1Element::SequenceType)
        return false;

    QDataStream validityStream(elem.value());
    if (!elem.read(validityStream) || (elem.type() != QAsn1Element::UtcTimeType && elem.type() != QAsn1Element::GeneralizedTimeType))
        return false;

    notValidBefore = elem.toDateTime();
    if (!elem.read(validityStream) || (elem.type() != QAsn1Element::UtcTimeType && elem.type() != QAsn1Element::GeneralizedTimeType))
        return false;

    notValidAfter = elem.toDateTime();

    // subject name
    if (!elem.read(certStream) || elem.type() != QAsn1Element::SequenceType)
        return false;

    QByteArray subjectDer = data.mid(dataStream.device()->pos() - elem.value().length(), elem.value().length());
    subjectInfo = elem.toInfo();
    subjectMatchesIssuer = issuerDer == subjectDer;

    // public key
    qint64 keyStart = certStream.device()->pos();
    if (!elem.read(certStream) || elem.type() != QAsn1Element::SequenceType)
        return false;

    publicKeyDerData.resize(certStream.device()->pos() - keyStart);
    QDataStream keyStream(elem.value());
    if (!elem.read(keyStream) || elem.type() != QAsn1Element::SequenceType)
        return false;


    // key algorithm
    if (!elem.read(elem.value()) || elem.type() != QAsn1Element::ObjectIdentifierType)
        return false;

    const QByteArray oid = elem.toObjectId();
    if (oid == RSA_ENCRYPTION_OID)
        publicKeyAlgorithm = QSsl::Rsa;
    else if (oid == DSA_ENCRYPTION_OID)
        publicKeyAlgorithm = QSsl::Dsa;
    else if (oid == EC_ENCRYPTION_OID)
        publicKeyAlgorithm = QSsl::Ec;
    else
        publicKeyAlgorithm = QSsl::Opaque;

    certStream.device()->seek(keyStart);
    certStream.readRawData(publicKeyDerData.data(), publicKeyDerData.size());

    // extensions
    while (elem.read(certStream)) {
        if (elem.type() == QAsn1Element::Context3Type) {
            if (elem.read(elem.value()) && elem.type() == QAsn1Element::SequenceType) {
                QDataStream extStream(elem.value());
                while (elem.read(extStream) && elem.type() == QAsn1Element::SequenceType) {
                    QSslCertificateExtension extension;
                    if (!parseExtension(elem.value(), &extension))
                        return false;
                    extensions << extension;

                    if (extension.oid() == QLatin1String("2.5.29.17")) {
                        // subjectAltName
                        QAsn1Element sanElem;
                        if (sanElem.read(extension.value().toByteArray()) && sanElem.type() == QAsn1Element::SequenceType) {
                            QDataStream nameStream(sanElem.value());
                            QAsn1Element nameElem;
                            while (nameElem.read(nameStream)) {
                                if (nameElem.type() == QAsn1Element::Rfc822NameType) {
                                    subjectAlternativeNames.insert(QSsl::EmailEntry, nameElem.toString());
                                } else if (nameElem.type() == QAsn1Element::DnsNameType) {
                                    subjectAlternativeNames.insert(QSsl::DnsEntry, nameElem.toString());
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    derData = data.left(dataStream.device()->pos());
    null = false;
    return true;
}