Пример #1
0
void dcMatrix::WriteToFileCSV(string fileName, vector<string> headers)
{
	ofstream thefile (fileName.c_str());
	
	string err_msg = "Headers size (" + to_string(headers.size()) + ") does not match dcMatrix columns size (" + to_string(nbCols) + ")!\n";
	err_msg = err_msg + "Cannot write matrix to this file: " + fileName;
	stopif(nbCols!=headers.size(), err_msg);
	
//	if (nbCols!=headers.size())
//	{
//		cout << "ERROR -- WriteToFileCSV: Headers size ("<<headers.size()<<") does not match dcMatrix columns size ("<<nbCols<<")!"<<endl;
//		cout << "Cannot write matrix to this file: "<<fileName<<endl;
//		exit(1);
//	}
	
	// Write headers on the first line
	for (unsigned int j=0; j<nbCols; j++) 
	{
		thefile << headers[j];
		if (j<nbCols-1) thefile<< ",";
	}
	thefile << endl;
	
	// Then write data
	for(unsigned int i=0;i<nbRows;i++)
    {
		for(unsigned int j=0;j<nbCols;j++)
		{
			thefile << val[nbCols*i+j] ;
			if (j<nbCols-1) thefile<< ",";
		}
        thefile << endl;
    }
}
Пример #2
0
void vectorFromFile(vector<long>& res, const char * theFileName)
{
	
	ifstream thefile (theFileName); // declare file stream
	
	//assert(thefile.is_open());
	
	if (!thefile)
	{
		cout<<endl<<" ERROR [vectorFromFile]: This file is not found: "<<theFileName<<endl;
		exit(1);
	}
	
	vector<long> x;
	
	long line;
	
	x.clear();
	
	while (!thefile.eof())   
	{
        
		thefile >> line;
		if (thefile.eof()) break;
		
		x.push_back (line);	
		
	}
	
	thefile.close();
	res = x;
}
Пример #3
0
void vectorFromFile(vector<int>& res, string theFileName)
{
	ifstream thefile (theFileName.c_str()); // declare file stream
	
	if (!thefile)
	{
		cout<<endl<<" ERROR [vectorFromFile]: This file is not found: "<<theFileName<<endl;
		exit(1);
	}
	
	
	vector<int> x;	
	int line;
	
	x.clear();
	
	while (!thefile.eof())   
	{
		thefile >> line;
		if (thefile.eof()) break;
		x.push_back (line);	
		//cout<<"DEBUG adding : " << line<<endl;
	}
	
	thefile.close();
	res = x;
}
Пример #4
0
void dcMatrix::FromFile(const char* fileName)
{
	ifstream thefile (fileName);
	
	for(unsigned int i=0;i<nbRows;i++)		
		for(unsigned int j=0;j<nbCols;j++)
		{
			thefile >> val[nbCols*i+j];
		}
	
}
Пример #5
0
dcMatrix::dcMatrix(string fileName)
{
    ifstream thefile (fileName.c_str());
	
	for(unsigned int i=0;i<nbRows;i++)		
		for(unsigned int j=0;j<nbCols;j++)
		{
			thefile >> val[nbCols*i+j];
		}
	
}
Пример #6
0
void dcMatrix::FromFile(string fileName)
{
	/// READ A FILE AND FILL THE
	/// ELEMENT VALUES TO THE MATRIX
	/// *** WARNING *** MUST BE SAME SIZE!!!
	
	ifstream thefile (fileName.c_str());
	
	for(unsigned int i=0;i<nbRows;i++)		
		for(unsigned int j=0;j<nbCols;j++)
			thefile >> val[nbCols*i+j];
}
Пример #7
0
void dcMatrix::WriteToFile(string fileName)
{
	ofstream thefile (fileName.c_str());
	
	for(unsigned int i=0;i<nbRows;i++)
    {
		for(unsigned int j=0;j<nbCols;j++)
		{
			thefile << val[nbCols*i+j] << "\t";
		}
        thefile << endl;
    }
}
Пример #8
0
void dcMatrix::FromFile_Rows(string fileName, unsigned int nrow)
{
	/// READ A FILE AND FILL THE
	/// ELEMENT VALUES TO THE MATRIX

	/// NUMBER OF ROWS PRE-SPECIFIED
	
	ifstream thefile (fileName.c_str());
	
	if (!thefile)
	{
		cout<<endl<<" ERROR [FromFile_Rows]: This file is not found: "<<fileName<<endl;
		exit(1);
	}
	
	vector<double> x;	
	double file_value;
	
	x.clear();
	
	while (!thefile.eof())   
	{
		thefile >> file_value;
		if (thefile.eof()) break;
		x.push_back (file_value);	
	}
	
	thefile.close();
	
	unsigned int n = x.size();
	
	if (n%nrow != 0 )
	{
		cout << endl << "ERROR [FromFile_Rows]: number of rows ("<< nrow<<") does not divide number of data("<<n<<")!"<<endl;
		exit(1);
	}

	this->resize(nrow, n/nrow);
	
	unsigned int cnt=0;
	
	for(unsigned int i=0;i<nbRows;i++)		
		for(unsigned int j=0;j<nbCols;j++)
		{
			val[nbCols*i+j] = x[cnt];
			cnt++;
		}	
	
}
Пример #9
0
/*
  Constructor
  Reads in a file, creates a 2D char array from file contents
  Throws FileNotFoundException if the file does not exist
*/
Grid::Grid(std::string& filename) : f_name(filename) {
    std::stringstream tempmap;	//temporary hold map
	char receive[256];	//get lines from file
	num_rows = 0;
	num_cols = 0;
	std::ifstream thefile(filename.c_str(), std::ios::in);


	//make sure the file exists
	if(!thefile)
		throw FileNotFoundException();


	//go through file and get map
	while(thefile.getline(receive, 256)) {
		num_rows++;	//add a row
		//std::cout<<receive<<std::endl;
		tempmap<<receive<<std::endl;	//pass line into tempmap
		//set column dimension
		num_cols = strlen(receive);
	}	//end while


	//make 2d char array
	map = new char*[num_rows];
	for(int i=0;i<num_rows;i++)
		map[i] = new char[num_cols];


	//initialize char array
	for(int r=0;r<num_rows;r++)
		for(int c=0;c<num_cols;c++) {
			//if newline char, consume that
			if((char)tempmap.peek() == '\n')
				tempmap.get();
			map[r][c] = (char)tempmap.get();
		}   //end inner for
}	//END CONSTRUCTOR
Пример #10
0
void SearchThread::DoSearchFile(const wxString& fileName, const SearchData* data)
{
    // Process single lines
    int lineNumber = 1;
    if(!wxFileName::FileExists(fileName)) {
        return;
    }

    wxFFile thefile(fileName, wxT("rb"));
    if(!thefile.IsOpened()) {
        // failed to open the file, probably because of permissions
        m_summary.GetFailedFiles().Add(fileName);
        return;
    }

    wxFileOffset size = thefile.Length();
    wxString fileData;
    fileData.Alloc(size);

    // support for other encoding
    wxFontEncoding enc = wxFontMapper::GetEncodingFromName(data->GetEncoding().c_str());
    wxCSConv fontEncConv(enc);
    if(!thefile.ReadAll(&fileData, fontEncConv)) {
        m_summary.GetFailedFiles().Add(fileName);
        return;
    }

    // take a wild guess and see if we really need to construct
    // a TextStatesPtr object (it is quite an expensive operation)
    bool shouldCreateStates(true);
    if(data->IsMatchCase() && !data->IsRegularExpression()) {
        shouldCreateStates = (fileData.Find(data->GetFindString()) != wxNOT_FOUND);

    } else if(!data->IsMatchCase() && !data->IsRegularExpression()) {
        // !data->IsMatchCase()
        wxString tmpData = fileData;
        shouldCreateStates = (tmpData.MakeLower().Find(data->GetFindString()) != wxNOT_FOUND);
    }

    wxStringTokenizer tkz(fileData, wxT("\n"), wxTOKEN_RET_EMPTY_ALL);

    // Incase one of the C++ options is enabled,
    // create a text states object
    TextStatesPtr states(NULL);
    if(data->HasCppOptions() && shouldCreateStates && false) {
        CppWordScanner scanner("", fileData.mb_str().data(), 0);
        states = scanner.states();
    }

    int lineOffset = 0;
    if(data->IsRegularExpression()) {
        // regular expression search
        while(tkz.HasMoreTokens()) {
            // Read the next line
            wxString line = tkz.NextToken();
            DoSearchLineRE(line, lineNumber, lineOffset, fileName, data, states);
            lineOffset += line.Length() + 1;
            lineNumber++;
        }
    } else {
        // simple search
        wxString findString;
        wxArrayString filters;
        findString = data->GetFindString();
        if(data->IsEnablePipeSupport()) {
            if(data->GetFindString().Find('|') != wxNOT_FOUND) {
                findString = data->GetFindString().BeforeFirst('|');

                wxString filtersString = data->GetFindString().AfterFirst('|');
                filters = ::wxStringTokenize(filtersString, "|", wxTOKEN_STRTOK);
                if(!data->IsMatchCase()) {
                    for(size_t i = 0; i < filters.size(); ++i) {
                        filters.Item(i).MakeLower();
                    }
                }
            }
        }

        if(!data->IsMatchCase()) {
            findString.MakeLower();
        }

        while(tkz.HasMoreTokens()) {

            // Read the next line
            wxString line = tkz.NextToken();
            DoSearchLine(line, lineNumber, lineOffset, fileName, data, findString, filters, states);
            lineOffset += line.Length() + 1;
            lineNumber++;
        }
    }

    if(m_results.empty() == false) SendEvent(wxEVT_SEARCH_THREAD_MATCHFOUND, data->GetOwner());
}
Пример #11
0
font font::open_font(std::string filename, int ptsize,long index) {
    ifstream thefile(filename.c_str(),ios::in|ios::binary);
    font thefont = open_font(thefile,ptsize,index);
    thefile.close();
    return thefont;
}
Пример #12
0
void FindUsageTab::ShowUsage(const std::list<CppToken>& matches, const wxString& searchWhat)
{
    Clear();
    int lineNumber(0);
    wxString text;
    wxString curfile;
    wxString curfileContent;
    wxArrayString lines;

    text = wxString::Format(_("===== Finding references of '%s' =====\n"), searchWhat.c_str());
    lineNumber++;

    std::list<CppToken>::const_iterator iter = matches.begin();
    for(; iter != matches.end(); iter++) {

        // Print the line number
        wxString file_name(iter->getFilename());
        if(curfile != file_name) {
            curfile = file_name;
            wxFileName fn(file_name);
            fn.MakeRelativeTo();

            text << fn.GetFullPath() << wxT("\n");
            lineNumber++;

            // Load the file content
            wxLogNull nolog;
            wxFFile thefile(file_name, wxT("rb"));
            if(thefile.IsOpened()) {

                wxFileOffset size = thefile.Length();
                wxString fileData;
                fileData.Alloc(size);
                curfileContent.Clear();

                wxCSConv fontEncConv(wxFONTENCODING_ISO8859_1);
                thefile.ReadAll(&curfileContent, fontEncConv);

                // break the current file into lines, a line can be an empty string
                lines = wxStringTokenize(curfileContent, wxT("\n"), wxTOKEN_RET_EMPTY_ALL);
            }
        }

        // Keep the match
        m_matches[lineNumber] = *iter;

        // Format the message
        wxString linenum = wxString::Format(wxT(" %5u "), (unsigned int)iter->getLineNumber() + 1);
        wxString scopeName(wxT("<global>"));
        TagEntryPtr tag = TagsManagerST::Get()->FunctionFromFileLine(iter->getFilename(), iter->getLineNumber());
        if(tag) {
            scopeName = tag->GetPath();
        }

        text << linenum << wxT("[ ") << scopeName << wxT(" ] ");
        if(lines.GetCount() > iter->getLineNumber()) {
            text << lines.Item(iter->getLineNumber()).Trim().Trim(false);
        }

        text << wxT("\n");
        lineNumber++;
    }
    text << wxString::Format(_("===== Found total of %u matches =====\n"), (unsigned int)m_matches.size());
    AppendText(text);
}