const QString FieldInformation::moduleName() { QString module_name; if (isValid()) { if (headerInfo().parent == -1) { module_name = fi_->hfinfo->abbrev; } else { module_name = proto_registrar_get_abbrev(headerInfo().parent); } } return module_name; }
bool BaseClassWriter::needsGeneration(const QString &className) { QFileInfo headerInfo(mTargetDir.absoluteFilePath(className + ".h")); QFileInfo sourceInfo(mTargetDir.absoluteFilePath(className + ".cpp")); bool noUpdateNeeded = headerInfo.exists() && headerInfo.lastModified() > mParser.lastConfigUpdate(); noUpdateNeeded &= sourceInfo.exists() && sourceInfo.lastModified() > mParser.lastConfigUpdate(); return !noUpdateNeeded; }
QString FieldInformation::url() { QString url; if (flag(FI_URL) && headerInfo().isValid && IS_FT_STRING(fi_->hfinfo->type)) { gchar *url_str; url_str = fvalue_to_string_repr(NULL, &fi_->value, FTREPR_DISPLAY, fi_->hfinfo->display); if (url_str) { url = url_str; } wmem_free(NULL, url_str); } return url; }
int main(int argc, char *argv[]) { WaveHeader header; //holds the header //if there is an error reading the header or if the header ID is not "RIFF" exit if( !readHeader(&header) || strncmp((char*)header.ID, "RIFF", 4)) { fprintf(stderr, "File is not a RIFF file\n"); return 3; } //check the formatChunk.ID, if not "fmt " exit if(strncmp((char*)header.formatChunk.ID, "fmt ", 4)) { fprintf(stderr, "Format chunk is corrupted\n"); return 4; } //check the header.dataChunk.ID, if not "data" exit if(strncmp((char*)header.dataChunk.ID, "data", 4)) { fprintf(stderr, "Error: Data chunk is corrupted\n"); return 5; } //check if the number of channels is 2, if not exit if(header.formatChunk.channels != 2) { fprintf(stderr, "File is not stereo\n"); return 6; } //check the sampling rate, if its not 44100 exit if(header.formatChunk.sampleRate != 44100) { fprintf(stderr, "File does not use 44,100Hz sample rate\n"); return 7; } //check the bits per sample, if not 16 bit (short) exit if(header.formatChunk.bitsPerSample != 16) { fprintf(stderr, "File does not have 16-bit samples\n"); return 8; } //channelLenth is the size of the dataChunk divided by two for two channels //and again by two because one sample has two bytes int channelLength = header.dataChunk.size/4; //allocate two arrays for the two channels short* left = (short*) malloc(sizeof(short)*channelLength); short* right = (short*) malloc(sizeof(short)*channelLength); //if malloc fails (returns NULL pointer) exit if(! (left && right)) { fprintf(stderr, "Program out of memory\n"); return 2; } //read the data Chunk //if its size does not match the expected length exit if(! readData(left, right, channelLength)) { fprintf(stderr, "File size does not match size in header\n"); return 9; } //get formatted header info char* info = headerInfo(&header); //printout input header information to stderr fprintf(stderr, "\nInput Wave Header Information\n\n%s\n", info); free(info); //loops throuh the commandline arguments and executes the right action on the data stored in left and right int i; for(i = 1; i < argc; ++i) { //case "-r" reverse if(strcmp(argv[i], "-r") == 0) { //reverse both the left and right channel reverse(&left, channelLength); reverse(&right, channelLength); } //case "-s" speed else if(strcmp(argv[i], "-s") == 0) { //check if there is a positive number in the argument after "-s" and read it into factor, //if not exit double factor; if(i < argc - 1 && sscanf(argv[++i], "%lf", &factor) != EOF && factor > 0) { //speed up left and right channel left = speed(left, channelLength, factor); right = speed(right, channelLength, factor); //update the channelLength channelLength /= factor; //update the header data header.dataChunk.size = 4*channelLength; header.size = 4 * channelLength + 36; } else { fprintf(stderr, "Error: A positive number must be supplied for the speed change\n"); return 10; } } //case "-f" flip channels else if(strcmp(argv[i], "-f") == 0) //flip channels left and right flip(&left, &right); //case "-o" fade out else if(strcmp(argv[i], "-o") == 0) { //check if there is a positive number in the argument after "-s" and read it into seconds, //if not exit double seconds; if(i < argc - 1 && sscanf(argv[++i], "%lf", &seconds) != EOF && seconds > 0) { //fade out left and right channel fadeOut(left, channelLength, seconds); fadeOut(right, channelLength, seconds); } else { fprintf(stderr, "Error: A positive number must be supplied for the fade in and fade out time\n"); return 11; } } //case "-i" fade in else if(strcmp(argv[i], "-i") == 0) { //check if there is a positive number in the argument after "-s" and read it into seconds, //if not exit double seconds; if(i < argc - 1 && sscanf(argv[++i], "%lf", &seconds) != EOF && seconds > 0) { //fade in left and right channel fadeIn(left, channelLength, seconds); fadeIn(right, channelLength, seconds); } else { fprintf(stderr, "Error: A positive number must be supplied for the fade in and fade out time\n"); return 11; } } //case "-v" volume else if(strcmp(argv[i], "-v") == 0) { //check if there is a positive number in the argument after "-s" and read it into scale, //if not exit double scale; if(i < argc - 1 && sscanf(argv[++i], "%lf", &scale) != EOF && scale > 0) { //change the volume of left and right volume(left, channelLength, scale); volume(right, channelLength, scale); } else { fprintf(stderr, "Error: A positive number must be supplied for the volume scale\n"); return 12; } } //case "-e" echo else if(strcmp(argv[i], "-e") == 0) { //check if there are two positve numbers in the arguments after "-e" and read them into delay and factor, //if not exit double delay, factor; if(i < argc - 2 && sscanf(argv[++i], "%lf", &delay) != EOF && sscanf(argv[++i], "%lf", &factor) != EOF && delay > 0 && factor > 0) { //ad the echo to the left and right channel left = echo(left, channelLength, delay, factor); right = echo(right, channelLength, delay, factor); //update channelLength channelLength += (int)(44100 * delay); //update header data header.dataChunk.size = 4*channelLength; header.size = 4 * channelLength + 36; } else { fprintf(stderr, "Error: A positive number must be supplied for the fade in and fade out time\n"); return 13; } } //if the argument is anything else then the known commands print a help else { fprintf(stderr, "Usage: wave [[-r][-s factor][-f][-o delay][-i delay][-v scale][-e delay scale] < input > output\n"); return 1; } } //get formatted header info info = headerInfo(&header); //print output header info the stderr fprintf(stderr, "\nOutput Wave Header Information\n\n%s\n", info); free(info); //write the header to stdout writeHeader(&header); //wrinte the data to stdout printData(left, right, channelLength); //free the two arrays holding the channels free(left); free(right); return 0; }
void AnnualIlluminanceMap::init(const openstudio::path& path) { // file must exist if (!exists( path )){ LOG(Fatal, "File does not exist: '" << toString(path) << "'" ); return; } // open file boost::filesystem::ifstream file(path); // keep track of line number unsigned lineNum = 0; // keep track of matrix size unsigned M=0; unsigned N=0; // temp string to read file string line; // lines 1 and 2 are the header lines string line1, line2; // this will contain matches to regular expressions smatch matches; // matches a single number followed by either tabs or spaces const regex singleNumber("([-+]?[0-9]*\\.?[0-9]+)[\\s\\t]*"); // conversion from footcandles to lux const double footcandlesToLux(10.76); // read the rest of the file line by line while(getline(file, line)){ ++lineNum; if (lineNum == 1){ // save line 1 line1 = line; }else if (lineNum == 2){ // save line 2 line2 = line; // create the header info HeaderInfo headerInfo(line1, line2); // we can now initialize x and y vectors m_xVector = headerInfo.xVector(); m_yVector = headerInfo.yVector(); M = m_xVector.size(); N = m_yVector.size(); }else{ // each line contains the month, day, time (in hours), // Solar Azimuth(degrees from south), Solar Altitude(degrees), Global Horizontal Illuminance (fc) // followed by M*N illuminance points // break the line up by spaces vector<string> lineVector; tokenizer<char_separator<char>, std::string::const_iterator, std::string > tk(line, char_separator<char>(" ")); for (tokenizer<char_separator<char>, std::string::const_iterator, std::string >::iterator it(tk.begin()); it!=tk.end(); ++it) { lineVector.push_back(*it); } // total number minus 6 standard header items unsigned numValues = lineVector.size() - 6; if (numValues != M*N){ LOG(Fatal, "Incorrect number of illuminance values read " << numValues << ", expecting " << M*N << "."); return; }else{ MonthOfYear month = monthOfYear(lexical_cast<unsigned>(lineVector[0])); unsigned day = lexical_cast<unsigned>(lineVector[1]); double fracDays = lexical_cast<double>(lineVector[2]) / 24.0; // ignore solar angles and global horizontal for now // make the date time DateTime dateTime(Date(month, day), Time(fracDays)); // matrix we are going to read in Matrix illuminanceMap(M,N); // read in the values unsigned index = 6; for (unsigned j = 0; j < N; ++j){ for (unsigned i = 0; i < M; ++i){ illuminanceMap(i,j) = footcandlesToLux*lexical_cast<double>(lineVector[index]); ++index; } } m_dateTimes.push_back(dateTime); m_dateTimeIlluminanceMap[dateTime] = illuminanceMap; } } } // close file file.close(); }