本文整理汇总了C++中fstream类的典型用法代码示例。如果您正苦于以下问题:C++ fstream类的具体用法?C++ fstream怎么用?C++ fstream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fstream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: loadModelFromFile
bool KMeansQuantizer::loadModelFromFile(fstream &file){
initialized = false;
numClusters = 0;
clusters.clear();
quantizationDistances.clear();
if( !file.is_open() ){
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
return false;
}
string word;
//First, you should read and validate the header
file >> word;
if( word != "KMEANS_QUANTIZER_FILE_V1.0" ){
errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << endl;
return false;
}
//Second, you should load the base feature extraction settings to the file
if( !loadFeatureExtractionSettingsFromFile( file ) ){
errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
return false;
}
file >> word;
if( word != "QuantizerTrained:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to load QuantizerTrained!" << endl;
return false;
}
file >> trained;
file >> word;
if( word != "NumClusters:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to load NumClusters!" << endl;
return false;
}
file >> numClusters;
if( trained ){
clusters.resize(numClusters, numInputDimensions);
file >> word;
if( word != "Clusters:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to load Clusters!" << endl;
return false;
}
for(UINT k=0; k<numClusters; k++){
for(UINT j=0; j<numInputDimensions; j++){
file >> clusters[k][j];
}
}
initialized = true;
featureDataReady = false;
quantizationDistances.resize(numClusters,0);
}
return true;
}
开发者ID:KreativKode,项目名称:grt,代码行数:62,代码来源:KMeansQuantizer.cpp
示例2: clear
bool Classifier::loadBaseSettingsFromFile(fstream &file){
if( !file.is_open() ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - The file is not open!" << endl;
return false;
}
//Try and load the base settings from the file
if( !MLBase::loadBaseSettingsFromFile( file ) ){
return false;
}
string word;
//Load if the number of clusters
file >> word;
if( word != "UseNullRejection:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read UseNullRejection header!" << endl;
clear();
return false;
}
file >> useNullRejection;
//Load if the classifier mode
file >> word;
if( word != "ClassifierMode:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read ClassifierMode header!" << endl;
clear();
return false;
}
file >> classifierMode;
//Load if the null rejection coeff
file >> word;
if( word != "NullRejectionCoeff:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read NullRejectionCoeff header!" << endl;
clear();
return false;
}
file >> nullRejectionCoeff;
//If the model is trained then load the model settings
if( trained ){
//Load the number of classes
file >> word;
if( word != "NumClasses:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read NumClasses header!" << endl;
clear();
return false;
}
file >> numClasses;
//Load the null rejection thresholds
file >> word;
if( word != "NullRejectionThresholds:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read NullRejectionThresholds header!" << endl;
clear();
return false;
}
nullRejectionThresholds.resize(numClasses);
for(UINT i=0; i<nullRejectionThresholds.size(); i++){
file >> nullRejectionThresholds[i];
}
//Load the class labels
file >> word;
if( word != "ClassLabels:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read ClassLabels header!" << endl;
clear();
return false;
}
classLabels.resize( numClasses );
for(UINT i=0; i<classLabels.size(); i++){
file >> classLabels[i];
}
if( useScaling ){
//Load if the Ranges
file >> word;
if( word != "Ranges:" ){
errorLog << "loadBaseSettingsFromFile(fstream &file) - Failed to read Ranges header!" << endl;
clear();
return false;
}
ranges.resize(numInputDimensions);
for(UINT i=0; i<ranges.size(); i++){
file >> ranges[i].minValue;
file >> ranges[i].maxValue;
}
}
}
return true;
}
开发者ID:kodojong,项目名称:SignLanguage-Recognition,代码行数:96,代码来源:Classifier.cpp
示例3: loadModelFromFile
bool DecisionStump::loadModelFromFile(fstream &file){
if(!file.is_open())
{
errorLog <<"loadModelFromFile(fstream &file) - The file is not open!" << endl;
return false;
}
string word;
file >> word;
if( word != "WeakClassifierType:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read WeakClassifierType header!" << endl;
return false;
}
file >> word;
if( word != weakClassifierType ){
errorLog <<"loadModelFromFile(fstream &file) - The weakClassifierType:" << word << " does not match: " << weakClassifierType << endl;
return false;
}
file >> word;
if( word != "Trained:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Trained header!" << endl;
return false;
}
file >> trained;
file >> word;
if( word != "NumInputDimensions:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << endl;
return false;
}
file >> numInputDimensions;
file >> word;
if( word != "DecisionFeatureIndex:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read DecisionFeatureIndex header!" << endl;
return false;
}
file >> decisionFeatureIndex;
file >> word;
if( word != "Direction:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Direction header!" << endl;
return false;
}
file >> direction;
file >> word;
if( word != "NumSteps:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumSteps header!" << endl;
return false;
}
file >> numSteps;
file >> word;
if( word != "DecisionValue:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read DecisionValue header!" << endl;
return false;
}
file >> decisionValue;
//We don't need to close the file as the function that called this function should handle that
return true;
}
开发者ID:Mr07,项目名称:MA-Gesture-Recognition,代码行数:67,代码来源:DecisionStump.cpp
示例4: OpenInputFile
//*********************************************************************
// FUNCTION: OpenInputFile
// DESCRIPTION: Open the input text file.
// INPUT:
// Parameters:
// std::string filename - Path to the input file.
// std::fstream file - The file object to use when opening the
// input file.
// OUTPUT:
// Return Val: Boolean indicating success of the file open
// operation.
// Parameters:
// std::fstream file - Initialized with the input file open on
// success.
// PERFORMANCE: f(n) = k
//**********************************************************************
bool OpenInputFile(string filename, fstream& file) {
file.open(filename.c_str(), fstream::in);
return(file.good());
} // OpenInputFile
开发者ID:jdantonio,项目名称:polyglot,代码行数:22,代码来源:WordSec-Optimized.cpp
示例5: loadLegacyModelFromFile
bool LogisticRegression::loadLegacyModelFromFile( fstream &file ){
string word;
file >> word;
if(word != "NumFeatures:"){
errorLog << "loadLegacyModelFromFile( fstream &file ) - Could not find NumFeatures!" << endl;
return false;
}
file >> numInputDimensions;
file >> word;
if(word != "NumOutputDimensions:"){
errorLog << "loadLegacyModelFromFile( fstream &file ) - Could not find NumOutputDimensions!" << endl;
return false;
}
file >> numOutputDimensions;
file >> word;
if(word != "UseScaling:"){
errorLog << "loadLegacyModelFromFile( fstream &file ) - Could not find UseScaling!" << endl;
return false;
}
file >> useScaling;
///Read the ranges if needed
if( useScaling ){
//Resize the ranges buffer
inputVectorRanges.resize(numInputDimensions);
targetVectorRanges.resize(numOutputDimensions);
//Load the ranges
file >> word;
if(word != "InputVectorRanges:"){
file.close();
errorLog << "loadLegacyModelFromFile( fstream &file ) - Failed to find InputVectorRanges!" << endl;
return false;
}
for(UINT j=0; j<inputVectorRanges.size(); j++){
file >> inputVectorRanges[j].minValue;
file >> inputVectorRanges[j].maxValue;
}
file >> word;
if(word != "OutputVectorRanges:"){
file.close();
errorLog << "loadLegacyModelFromFile( fstream &file ) - Failed to find OutputVectorRanges!" << endl;
return false;
}
for(UINT j=0; j<targetVectorRanges.size(); j++){
file >> targetVectorRanges[j].minValue;
file >> targetVectorRanges[j].maxValue;
}
}
//Resize the weights
w.resize(numInputDimensions);
//Load the weights
file >> word;
if(word != "Weights:"){
errorLog << "loadLegacyModelFromFile( fstream &file ) - Could not find the Weights!" << endl;
return false;
}
file >> w0;
for(UINT j=0; j<numInputDimensions; j++){
file >> w[j];
}
//Resize the regression data vector
regressionData.resize(1,0);
//Flag that the model has been trained
trained = true;
return true;
}
开发者ID:Amos-zq,项目名称:grt,代码行数:79,代码来源:LogisticRegression.cpp
示例6: init
void init() {
if (ifstream ("Pontuacao.bin")) {
arquivoPontuacao.open ("Pontuacao.bin", ios::in | ios::binary);
arquivoPontuacao >> pontuacaoMaisAlta;
arquivoPontuacao.close();
}
开发者ID:fabianin,项目名称:As-aventuras-de-Lekinho,代码行数:6,代码来源:jogo.cpp
示例7: readFile
void readFile(fstream &file, bool isSequential) {
int fd;
uint64_t start, end;
double average, total = 0, totalAverage = 0;
const char* fileName;
warmup();
double overhead = getReadOverhead();
void* buffer = malloc(BLOCK_SIZE);
pid_t pids[TEST_FILE_NUMBER];
// using TEST_FILE_NUMBER as thread number
for(int i = 1; i < TEST_FILE_NUMBER; i++) {
file << "Company process number=" << i << "\n";
for(int j = 0; j < i; j++) {
// fork new process
pids[j] = fork();
if(pids[j] < 0) {
cout << "Can't fork a new process" << endl;
abort();
}
else if(pids[j] == 0) {
// enter the child process, do pure read process without any fetching data
pureRead(1 + j, isSequential);
exit(0);
}
}
totalAverage = 0;
// parent process finishing fetching performance data
for (int j = 0; j < TEST_TIMES; j++) {
fileName = (TEST_FILE_PREFIX + to_string(1)).c_str();
fd = open(fileName, O_SYNC | O_RDONLY);
if(fd < 0) {
cout << "Can't open the test file, please create a test file first: "<< fileName << endl;
return;
}
// http://stackoverflow.com/questions/2299402/how-does-one-do-raw-io-on-mac-os-x-ie-equivalent-to-linuxs-o-direct-flag
if(fcntl(fd, F_NOCACHE, 1) < 0) {
cout << "Can't close cache of the test file" << endl;
return;
}
// call purge to clear cache
// system("purge");
total = 0;
if(isSequential) {
for(int k = 0; k < BLOCK_NUMBER; k++) {
start = rdtscStart();
read(fd, buffer, BLOCK_SIZE);
end = rdtscEnd();
total += (double) end - (double) start - overhead;
}
}
else {
off_t offset;
for(int k = 0; k < BLOCK_NUMBER; k++) {
start = rdtscStart();
offset = rand() % BLOCK_NUMBER;
// using lseek to set offset
lseek(fd, offset, SEEK_SET);
read(fd, buffer, BLOCK_SIZE);
end = rdtscEnd();
total += (double) end - (double) start - overhead;
}
}
average = (total / BLOCK_NUMBER) * 0.37 / 1000000;
file << average << "\n";
file.flush();
totalAverage += average;
close(fd);
}
cout << "Company thread count = " << i << " average cycles = " << totalAverage / TEST_TIMES << endl;
wait(NULL);
}
// close file and free memory
free(buffer);
}
开发者ID:joseph5wu,项目名称:System-Measurement,代码行数:81,代码来源:contention.cpp
示例8: clear
bool AdaBoost::loadModelFromFile(fstream &file){
clear();
if(!file.is_open())
{
errorLog << "loadModelFromFile(string filename) - Could not open file to load model!" << endl;
return false;
}
std::string word;
file >> word;
//Check to see if we should load a legacy file
if( word == "GRT_ADABOOST_MODEL_FILE_V1.0" ){
return loadLegacyModelFromFile( file );
}
if( word != "GRT_ADABOOST_MODEL_FILE_V2.0" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read file header!" << endl;
errorLog << word << endl;
return false;
}
//Load the base settings from the file
if( !Classifier::loadBaseSettingsFromFile(file) ){
errorLog << "loadModelFromFile(string filename) - Failed to load base settings from file!" << endl;
return false;
}
file >> word;
if( word != "PredictionMethod:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read PredictionMethod header!" << endl;
return false;
}
file >> predictionMethod;
if( trained ){
file >> word;
if( word != "Models:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Models header!" << endl;
return false;
}
//Load the models
models.resize( numClasses );
for(UINT i=0; i<models.size(); i++){
if( !models[i].loadModelFromFile( file ) ){
errorLog << "loadModelFromFile(fstream &file) - Failed to load model " << i << " from file!" << endl;
file.close();
return false;
}
}
//Recompute the null rejection thresholds
recomputeNullRejectionThresholds();
//Resize the prediction results to make sure it is setup for realtime prediction
maxLikelihood = DEFAULT_NULL_LIKELIHOOD_VALUE;
bestDistance = DEFAULT_NULL_DISTANCE_VALUE;
classLikelihoods.resize(numClasses,DEFAULT_NULL_LIKELIHOOD_VALUE);
classDistances.resize(numClasses,DEFAULT_NULL_DISTANCE_VALUE);
}
return true;
}
开发者ID:Amos-zq,项目名称:grt,代码行数:66,代码来源:AdaBoost.cpp
示例9: parseCNFString
//void LMParser::parseCNFString(string formula,vector<PredicateSymbol*> predicateList)
void LMParser::parseCNFString(string formula,fstream& filestr)
{
//apend multiple lines
char* buf = new char[1024];
size_t pos;
while(1)
{
pos = formula.find(WEIGHTSEPARATOR);
if(pos!=string::npos)
break;
else
{
filestr.getline(buf,1024);
string s(buf);
s.erase( remove(s.begin(), s.end(), ' '), s.end() );
formula.append(s);
}
}
delete[] buf;
//extract the weight
string weight = formula.substr(pos+2);
stringstream convert(weight);
double wt;
convert >> wt;
formula = formula.substr(0,pos);
//cout<<wt<<endl;
vector<string> clauseStrings;
LStringConversionUtils::tokenize(formula,clauseStrings,ANDOPERATOR);
vector<WClause*> CNF;
for(int i=0;i<clauseStrings.size();i++)
{
//If clause starts with a paranthesis
if(clauseStrings[i].find(LEFTPRNTH)==0)
{
//eliminate the first and last paranthesis
clauseStrings[i] = clauseStrings[i].substr(1,clauseStrings[i].size()-2);
}
vector<string> atomStrings;
LStringConversionUtils::tokenize(clauseStrings[i],atomStrings,OROPERATOR);
vector<vector<string> > sTermsList(atomStrings.size());
//sign of an atom
vector<bool> sign(atomStrings.size());
//index into the predicate symbols
vector<int> predicateSymbolIndex(atomStrings.size());
for(int j=0;j<atomStrings.size();j++)
{
//find opening and closing braces
int startpos=atomStrings[j].find(LEFTPRNTH);
string predicateName = atomStrings[j].substr(0,startpos);
if(predicateName.find(NOTOPERATOR)==0)
{
//negation
predicateName = predicateName.substr(1,predicateName.size());
sign[j]=true;
}
for(int k=0;k<mln.symbols.size();k++)
{
//found the predicate
if(mln.symbols[k]->symbol.compare(predicateName)==0)
{
predicateSymbolIndex[j] = k;
break;
}
}
int endpos=atomStrings[j].find(RIGHTPRNTH);
string termsString = atomStrings[j].substr(startpos+1,endpos-startpos-1);
vector<string> terms;
LStringConversionUtils::tokenize(termsString,terms,COMMASEPARATOR);
sTermsList[j]=terms;
//check if the number of terms is equal to the declared predicate
if(terms.size()!=mln.symbols[predicateSymbolIndex[j]]->variable_types.size())
{
cout<<"Error! Number/domain of terms in the predicate delcaration does not match in formula::"<<predicateName.c_str()<<endl;
exit(-1);
}
}
//create required terms
vector<vector<LvrTerm*> > iTermsList(atomStrings.size());
for(int j=0;j<atomStrings.size();j++)
{
//for each term of atom i, check if it has already appeared in previous atoms of clause
vector<LvrTerm*> iTerms(sTermsList[j].size());
for(int k=0;k<sTermsList[j].size();k++)
{
int domainIndex = predicateDomainMap[predicateSymbolIndex[j]].at(k);
//if term is a constant must be a unique term
if(isTermConstant(sTermsList[j].at(k)))
{
//find the id of the term
int id=-1;
for(int m=0;m<domainList[domainIndex]->values.size();m++)
{
if(domainList[domainIndex]->values[m].compare(sTermsList[j].at(k))==0)
{
id=m;
break;
//.........这里部分代码省略.........
开发者ID:Artemid,项目名称:alchemy-2,代码行数:101,代码来源:parser.cpp
示例10: loadLegacyModelFromFile
bool AdaBoost::loadLegacyModelFromFile( fstream &file ){
string word;
file >> word;
if( word != "NumFeatures:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumFeatures header!" << endl;
return false;
}
file >> numInputDimensions;
file >> word;
if( word != "NumClasses:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read NumClasses header!" << endl;
return false;
}
file >> numClasses;
file >> word;
if( word != "UseScaling:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read UseScaling header!" << endl;
return false;
}
file >> useScaling;
file >> word;
if( word != "UseNullRejection:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read UseNullRejection header!" << endl;
return false;
}
file >> useNullRejection;
if( useScaling ){
file >> word;
if( word != "Ranges:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Ranges header!" << endl;
return false;
}
ranges.resize( numInputDimensions );
for(UINT n=0; n<ranges.size(); n++){
file >> ranges[n].minValue;
file >> ranges[n].maxValue;
}
}
file >> word;
if( word != "Trained:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Trained header!" << endl;
return false;
}
file >> trained;
file >> word;
if( word != "PredictionMethod:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read PredictionMethod header!" << endl;
return false;
}
file >> predictionMethod;
if( trained ){
file >> word;
if( word != "Models:" ){
errorLog <<"loadModelFromFile(fstream &file) - Failed to read Models header!" << endl;
return false;
}
//Load the models
models.resize( numClasses );
classLabels.resize( numClasses );
for(UINT i=0; i<models.size(); i++){
if( !models[i].loadModelFromFile( file ) ){
errorLog << "loadModelFromFile(fstream &file) - Failed to load model " << i << " from file!" << endl;
file.close();
return false;
}
//Set the class label
classLabels[i] = models[i].getClassLabel();
}
}
//Recompute the null rejection thresholds
recomputeNullRejectionThresholds();
//Resize the prediction results to make sure it is setup for realtime prediction
maxLikelihood = DEFAULT_NULL_LIKELIHOOD_VALUE;
bestDistance = DEFAULT_NULL_DISTANCE_VALUE;
classLikelihoods.resize(numClasses,DEFAULT_NULL_LIKELIHOOD_VALUE);
classDistances.resize(numClasses,DEFAULT_NULL_DISTANCE_VALUE);
return true;
}
开发者ID:Amos-zq,项目名称:grt,代码行数:93,代码来源:AdaBoost.cpp
示例11: sizeof
void disk_list<T>::disk(fstream& f, long int k, long int m)
{
long int i,j,kk;
T w, u, t;
i=k; j=m; kk=(long)(i+j)/2;
f.seekg(kk*sizeof(T));
f.read((char *)&w, sizeof(T));
t = w;
do
{
f.seekg(i*sizeof(T));
f.read((char *)&w, sizeof(T));
while ((strcmp(w.SORT_KEY,t.SORT_KEY)<0)&&(i<=j))
{
i=i+1;
f.seekg(i*sizeof(T));
f.read((char *)&w, sizeof(T));
}
f.seekg(j*sizeof(T));
f.read((char *)&w, sizeof(T));
while ((strcmp(w.SORT_KEY,t.SORT_KEY)>0)&&(i<=j))
{
j=j-1;
f.seekg(j*sizeof(T));
f.read((char *)&w, sizeof(T));
}
if (i<=j)
{
f.seekg(i*sizeof(T));
f.read((char *)&w, sizeof(T));
f.seekg(j*sizeof(T));
f.read((char *)&u, sizeof(T));
f.seekg(i*sizeof(T));
f.write((char *)&u, sizeof(T));
f.seekg(j*sizeof(T));
f.write((char *)&w, sizeof(T));
i=i+1; j=j-1;
}
}while (i<=j);
if (k<j) disk(f,k,j);
if (i<m) disk(f,i,m);
return;
}
开发者ID:panzhengguang,项目名称:OpenSourceCode,代码行数:45,代码来源:11DISK_LIST.CPP
示例12: write
void BLOCK::write(fstream &fp){
fp.write((char*)&bytesUsed, sizeof(bytesUsed));
for(int i = 0; i < bytesUsed; i++)
fp.write((char*)&data[i], sizeof(char));
fp.write((char*)&next, sizeof(next));
}
开发者ID:prasanthxyz,项目名称:PPFS,代码行数:6,代码来源:ppfs_datastructures.cpp
示例13: Write
void Chunk::Write(fstream &OutputFile)
{
OutputFile.write(ChunkID, sizeof(ChunkID));
OutputFile.write((const char *)&ChunkSize, sizeof(ChunkSize));
}
开发者ID:AuditoryBiophysicsLab,项目名称:EarLab,代码行数:5,代码来源:WaveFile.cpp
示例14: GenerateMessageList
/**
* \brief Generates the message list
*
* This function will parse the input file and line by line
* and generates a list of message,signal,value table,comments,etc
*/
void CDBFConverter::GenerateMessageList(fstream& fileInput)
{
char acLine[defCON_MAX_LINE_LEN]; // I don't expect one line to be more than this
string local_copy;
char* pcTok;
int flag=0;
int _flag_BS_= 0; //possible values 0,1,2// this flag is used to check if parsing is done in between NS_: and BS_: #git issue 174
// parsing the input file
while(fileInput.getline(acLine, defCON_MAX_LINE_LEN))
{
char* pcToken=0, *pcLine=0;
for (;;)
{
pcLine = acLine;
pcLine += strlen(pcLine); // go to last position
pcLine --;
if (*pcLine == '\r')
{
fileInput.getline(pcLine, defCON_MAX_LINE_LEN);
}
else
{
break;
}
}
// avoid leading <spaces> before tokenising, so passing the
// starting point will be correct in each case, when calling
// msg.Format, sig.Format etc.
local_copy = acLine;
pcLine = acLine;
while(*pcLine && *pcLine == ' ')
{
*pcLine++;
}
pcToken = strtok_s(pcLine, " :", &pcTok);
if(pcToken)
{
//compare token to known types to interpret the line further
if(strstr(pcToken, "BS_") != NULL) // git issue #174
{
if (_flag_BS_ == 1 )
{
_flag_BS_ = 2; // this means just NS_ and BS_ are done.
}
}
if(strstr(pcToken, "NS_") != NULL)
{
if (_flag_BS_ == 0 )
{
_flag_BS_ = 1; // this means just NS_ is hit and BS_ is still due.
}
}
// new line - skip
else if(strcmp(pcToken, "\n") == 0)
{
continue;
}
// message
else if(strcmp(pcToken, "BO_") == 0)
{
CMessage msg;
msg.Format(pcLine + strlen(pcToken)+1);
// add the new message to the list
if((msg.m_acName != "VECTOR__INDEPENDENT_SIG_MSG") && !(msg.m_uiMsgID == 3221225472) )
{
if( CAN == m_eBus )
{
if( msg.m_ucLength <= 8 )
{
CDBFConverter::valid_msg = true;
m_listMessages.push_back(msg);
}
else
{
CDBFConverter::valid_msg = false;
m_unsupList.push_back(msg);
}
}
else
{
CDBFConverter::valid_msg = true;
m_listMessages.push_back(msg);
}
}
else
//.........这里部分代码省略.........
开发者ID:ETAS-Nithin,项目名称:busmaster,代码行数:101,代码来源:DBFConverter.cpp
示例15: output
void Decryptor::output(char* outFileName) {
outFile.open(outFileName,fstream::out | ios::binary);
outFile << cylines;
outFile.close();
}
开发者ID:pmsosa,项目名称:CasualKrypt,代码行数:5,代码来源:DecryptClass.cpp
示例16: inits
void inits() {
errno = 0;
logfile.open(LOGFILEPATH, std::fstream::out | std::fstream::app);
logger << "RasPiProg logging started." << endl;
sa.sa_handler = &sighandler;
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
if(sigaction(SIGTERM, &sa, NULL) == -1) {
logger << "Error: cannot handle SIGTERM" << endl;
}
if(sigaction(SIGHUP, &sa, NULL) == -1) {
logger << "Error: cannot handle SIGHUP" << endl;
}
if(sigaction(SIGUSR1, &sa, NULL) == -1) {
logger << "Error: cannot handle SIGUSR1" << endl;
}
if(sigaction(SIGINT, &sa, NULL) == -1) {
logger << "Error: cannot handle SIGINT" << endl;
}
if(wiringPiSetup() == -1) {
logger << "WiringPi initialization failed!" << endl;
exit(1);
}
lcdHandle = lcdInit(lcdSettings[0],lcdSettings[1],lcdSettings[2],lcdSettings[3],lcdSettings[4],lcdSettings[5],lcdSettings[6]
,lcdSettings[7],lcdSettings[8],lcdSettings[9],lcdSettings[10],lcdSettings[11],lcdSettings[12]);
if(lcdHandle < 0) {
logger << "LCD-display initialization failed!" << endl;
exit(2);
}
lcdClear(lcdHandle);
lcdPosition(lcdHandle, 0, 0) ; lcdPuts(lcdHandle, "RasPiProg By PTapioK");
sleep(1);
lcdClear(lcdHandle);
/*
int lirc = lirc_init(sqlDBname, 1);
if(lirc == -1) {
logger << "Lirc initialization failed!" << endl;
exit(3);
}
if(lirc_readconfig(NULL, &config, NULL) == -1) {
logger << "Lirc initialization failed!" << endl;
exit(4);
}
// Don't wait IR signals
fcntl(lirc, F_SETOWN, getpid());
int flags = fcntl(lirc, F_GETFL, 0);
if (flags == -1)
deinits();
fcntl(lirc, F_SETFL, flags | O_NONBLOCK);
*/
sqlCon = mysql_init(NULL);
if(sqlCon == NULL) {
logger << "MySQL initialization failed!" << endl;
exit(5);
}
if(mysql_real_connect(sqlCon, sqlHost.c_str(), sqlUsername.c_str(), sqlPassword.c_str(), sqlDBname.c_str(), 0, NULL, 0) == NULL) {
// Try again
if(mysql_real_connect(sqlCon, sqlHost.c_str(), sqlUsername.c_str(), sqlPassword.c_str(), sqlDBname.c_str(), 0, NULL, 0) == NULL) {
logger << "MySQL connection initialization failed!" << endl;
mysql_close(sqlCon);
exit(6);
}
}
if(!TableExists(sqlDBname, "temps")) {
if(mysql_query(sqlCon, "CREATE TABLE temps(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name TEXT, st TIMESTAMP DEFAULT CURRENT_TIMESTAMP, temp FLOAT)")) {
logger << "MySQL error! Errno: " << mysql_errno(sqlCon) << endl;
mysql_close(sqlCon);
exit(8);
}
}
if(!TableExists(sqlDBname, "humis")) {
if(mysql_query(sqlCon, "CREATE TABLE humis(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name TEXT, st TIMESTAMP DEFAULT CURRENT_TIMESTAMP, humi FLOAT)")) {
logger << "MySQL error! Errno: " << mysql_errno(sqlCon) << endl;
mysql_close(sqlCon);
exit(8);
}
}
//.........这里部分代码省略.........
开发者ID:PTapioK,项目名称:RasPiProg,代码行数:101,代码来源:main.cpp
示例17: loadModelFromFile
bool ANBC::loadModelFromFile(fstream &file) {
trained = false;
numFeatures = 0;
numClasses = 0;
models.clear();
classLabels.clear();
if(!file.is_open())
{
errorLog << "loadANBCModelFromFile(string filename) - Could not open file to load model" << endl;
return false;
}
std::string word;
//Find the file type header
file >> word;
if(word != "GRT_ANBC_MODEL_FILE_V1.0") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find Model File Header" << endl;
return false;
}
file >> word;
if(word != "NumFeatures:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find NumFeatures " << endl;
return false;
}
file >> numFeatures;
file >> word;
if(word != "NumClasses:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find NumClasses" << endl;
return false;
}
file >> numClasses;
file >> word;
if(word != "UseScaling:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find UseScaling" << endl;
return false;
}
file >> useScaling;
file >> word;
if(word != "UseNullRejection:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find UseNullRejection" << endl;
return false;
}
file >> useNullRejection;
///Read the ranges if needed
if( useScaling ) {
//Resize the ranges buffer
ranges.resize(numFeatures);
file >> word;
if(word != "Ranges:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find the Ranges" << endl;
return false;
}
for(UINT n=0; n<ranges.size(); n++) {
file >> ranges[n].minValue;
file >> ranges[n].maxValue;
}
}
//Resize the buffer
models.resize(numClasses);
classLabels.resize(numClasses);
//Load each of the K models
for(UINT k=0; k<numClasses; k++) {
UINT modelID;
file >> word;
if(word != "*************_MODEL_*************") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find header for the "<<k+1<<"th model" << endl;
return false;
}
file >> word;
if(word != "Model_ID:") {
errorLog << "loadANBCModelFromFile(string filename) - Could not find model ID for the "<<k+1<<"th model" << endl;
return false;
}
file >> modelID;
if(modelID-1!=k) {
cout<<"ANBC: Model ID does not match the current class ID for the "<<k+1<<"th model" << endl;
return false;
}
file >> word;
if(word != "N:") {
cout<<"ANBC: Could not find N for the "<<k+1<<"th model" << endl;
return false;
}
file >> models[k].N;
file >> word;
//.........这里部分代码省略.........
开发者ID:pixelmaid,项目名称:shape-recog,代码行数:101,代码来源:ANBC.cpp
示例18: loadModelFromFile
bool LDA::loadModelFromFile(fstream &file){
trained = false;
numInputDimensions = 0;
numClasses = 0;
models.clear();
classLabels.clear();
if(!file.is_open())
{
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << endl;
return false;
}
std::string word;
//Find the file type header
file >> word;
if(word != "GRT_LDA_MODEL_FILE_V1.0"){
errorLog << "loadModelFromFile(fstream &file) - Could not find Model File Header" << endl;
return false;
}
file >> word;
if(word != "NumFeatures:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find NumFeatures " << endl;
return false;
}
file >> numInputDimensions;
file >> word;
if(word != "NumClasses:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find NumClasses" << endl;
return false;
}
file >> numClasses;
file >> word;
if(word != "UseScaling:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find UseScaling" << endl;
return false;
}
file >> useScaling;
file >> word;
if(word != "UseNullRejection:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find UseNullRejection" << endl;
return false;
}
file >> useNullRejection;
///Read the ranges if needed
if( useScaling ){
//Resize the ranges buffer
ranges.resize(numInputDimensions);
file >> word;
if(word != "Ranges:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find the Ranges" << endl;
return false;
}
for(UINT n=0; n<ranges.size(); n++){
file >> ranges[n].minValue;
file >> ranges[n].maxValue;
}
}
//Resize the buffer
models.resize(numClasses);
classLabels.resize(numClasses);
//Load each of the K models
for(UINT k=0; k<numClasses; k++){
file >> word;
if(word != "ClassLabel:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find ClassLabel for the "<<k+1<<"th model" << endl;
return false;
}
file >> models[k].classLabel;
classLabels[k] = models[k].classLabel;
file >> word;
if(word != "PriorProbability:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find the PriorProbability for the "<<k+1<<"th model" << endl;
return false;
}
file >> models[k].priorProb;
models[k].weights.resize(numInputDimensions+1);
//Load the weights
file >> word;
if(word != "Weights:"){
errorLog << "loadModelFromFile(fstream &file) - Could not find the Weights vector for the "<<k+1<<"th model" << endl;
return false;
}
//Load Weights
for(UINT j=0; j<numInputDimensions+1; j++){
double value;
//.........这里部分代码省略.........
开发者ID:eboix,项目名称:Myo-Gesture,代码行数:101,代码来源:LDA.cpp
|
请发表评论