void GamFileType::_initialize()
{
    if (_initialized) return;
    DatFileItem::_initialize();
    DatFileItem::setPosition(0);


    unsigned int i = 0;
    unsigned char ch;
    std::string line;
    while (i != this->size())
    {
        *this >> ch; i++;
        if (ch != 0x0D) // \r
        {
            line += ch;
        }
        else
        {
            this->skipBytes(1); i++;// 0x0A \n
            _parseLine(line);
            line.clear();
        }
    }
    if (line.length() != 0)
    {
        _parseLine(line);
    }

}
long ClusterGeoIpService::_load(const char *pathToCsv,int ipStartColumn,int ipEndColumn,int latitudeColumn,int longitudeColumn)
{
	// assumes _lock is locked

	FILE *f = fopen(pathToCsv,"rb");
	if (!f)
		return -1;

	std::vector<_V4E> v4db;
	std::vector<_V6E> v6db;
	v4db.reserve(16777216);
	v6db.reserve(16777216);

	char buf[4096];
	char linebuf[1024];
	unsigned int lineptr = 0;
	for(;;) {
		int n = (int)fread(buf,1,sizeof(buf),f);
		if (n <= 0)
			break;
		for(int i=0;i<n;++i) {
			if ((buf[i] == '\r')||(buf[i] == '\n')||(buf[i] == (char)0)) {
				if (lineptr) {
					linebuf[lineptr] = (char)0;
					_parseLine(linebuf,v4db,v6db,ipStartColumn,ipEndColumn,latitudeColumn,longitudeColumn);
				}
				lineptr = 0;
			} else if (lineptr < (unsigned int)sizeof(linebuf))
				linebuf[lineptr++] = buf[i];
		}
	}
	if (lineptr) {
		linebuf[lineptr] = (char)0;
		_parseLine(linebuf,v4db,v6db,ipStartColumn,ipEndColumn,latitudeColumn,longitudeColumn);
	}

	fclose(f);

	if ((v4db.size() > 0)||(v6db.size() > 0)) {
		std::sort(v4db.begin(),v4db.end());
		std::sort(v6db.begin(),v6db.end());

		_pathToCsv = pathToCsv;
		_ipStartColumn = ipStartColumn;
		_ipEndColumn = ipEndColumn;
		_latitudeColumn = latitudeColumn;
		_longitudeColumn = longitudeColumn;

		_lastFileCheckTime = OSUtils::now();
		_csvModificationTime = OSUtils::getLastModified(pathToCsv);
		_csvFileSize = OSUtils::getFileSize(pathToCsv);

		_v4db.swap(v4db);
		_v6db.swap(v6db);

		return (long)(_v4db.size() + _v6db.size());
	} else {
		return 0;
	}
}
Beispiel #3
0
// ---------------------------------------------------------------------
// get_vm_peak
// ---------------------------------------------------------------------
int get_vm_peak() {

    int result = -1;
    char line[128];

    FILE* file = fopen("/proc/self/status", "r");
    if (file == NULL) return -2;
    
    while (fgets(line, 128, file) != NULL)
        if (strncmp(line, "VmPeak:", 7) == 0) {
            result = _parseLine(line);
            break;
        }
 
    fclose(file);
 
    return result;
}
Beispiel #4
0
void ModuleNetwork::refresh()
{
    if (!_stream.is_open() || !_display)
        return;
    _stream.clear();
    _stream.seekg(0, std::ios::beg);
    std::string value = "";
    while (_stream.good())
    {
        std::string line = "";
        std::getline(_stream, line);
        if ((line.find(_intf)) != std::string::npos)
        {
            value = _parseLine(line);
            break;
        }
    }
    _display->addValue(value);
    _display->setMax("");
}
Beispiel #5
0
/**
 * This parses an OBJ file for the first polygon available in it.
 */
Polygon::Polygon(string objfile) {
    // Leave this as it is.
    std::cout << "Parsing OBJ file " << objfile << std::endl;

    vector<Vertex> tempVerts;
    ifstream inFile(objfile.c_str(), ifstream::in);
    if (!inFile) {
        std::cout << "Could not open given obj file " << objfile << std::endl;
    }
    while (inFile.good()) {
        string line;
        getline(inFile, line);
        if (!_parseLine(line, tempVerts)) {
            std::cout << "Failed to parse OBJ file." << std::endl;
            break;
        }
        if (_vertices.size() > 0) // take the first face in the file.
            break;
    }
    inFile.close();

    std::cout << "Parsed an OBJ file with " << _vertices.size() << " vertices."
            << endl;
}