static void append_data (SortFlowState *state, int i, int index) { gchar *str, *header; GtkTreeIter iter; Sheet *sheet = state->sel->v_range.cell.a.sheet; gboolean sort_asc = gnm_conf_get_core_sort_default_ascending (); header = state->is_cols ? header_name (sheet, i, index) : header_name (sheet, index, i); str = state->is_cols ? col_row_name (sheet, i, index, FALSE, TRUE) : col_row_name (sheet, index, i, FALSE, FALSE); gtk_list_store_append (state->model, &iter); gtk_list_store_set (state->model, &iter, ITEM_HEADER, header, ITEM_NAME, str, ITEM_DESCENDING, !sort_asc, ITEM_DESCENDING_IMAGE, sort_asc ? state->image_ascending : state->image_descending, ITEM_CASE_SENSITIVE, gnm_conf_get_core_sort_default_by_case (), ITEM_SORT_BY_VALUE, TRUE, ITEM_MOVE_FORMAT, TRUE, ITEM_NUMBER, i, -1); state->sort_items++; g_free (str); g_free (header); }
static void dialog_cell_sort_load_sort_setup (SortFlowState *state, GnmSortData const *data) { int i; GnmSortClause *this = data->clauses; gint base, max, index; Sheet *sheet = state->sel->v_range.cell.a.sheet; if (sheet == NULL) sheet = state->sheet; go_locale_sel_set_locale (state->locale_selector, data->locale); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (state->retain_format_check), data->retain_formats); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (state->cell_sort_row_rb), !data->top); state->is_cols = data->top; index = (data->top ? state->sel->v_range.cell.a.row : state->sel->v_range.cell.a.col); base = (data->top ? state->sel->v_range.cell.a.col : state->sel->v_range.cell.a.row); max = (data->top ? state->sel->v_range.cell.b.col : state->sel->v_range.cell.b.row); gtk_list_store_clear (state->model); state->sort_items = 0; for (i = 0; i < data->num_clause; i++) { if (data->clauses[i].offset <= max ) { GtkTreeIter iter; gchar *str, *header; int id = data->clauses[i].offset + base; header = state->is_cols ? header_name (sheet, id, index) : header_name (sheet, index, id); str = col_row_name (sheet, id, id, FALSE, state->is_cols); gtk_list_store_append (state->model, &iter); gtk_list_store_set (state->model, &iter, ITEM_HEADER, header, ITEM_NAME, str, ITEM_DESCENDING, data->clauses[i].asc, ITEM_DESCENDING_IMAGE, !data->clauses[i].asc ? state->image_ascending : state->image_descending, ITEM_CASE_SENSITIVE, data->clauses[i].cs, ITEM_SORT_BY_VALUE, data->clauses[i].val, ITEM_MOVE_FORMAT, TRUE, ITEM_NUMBER, id, -1); state->sort_items++; } this++; } set_button_sensitivity (state); }
// -------------------------------------------------------------------------- // // Function // Name: HTTPRequest::ParseHeaders(IOStreamGetLine &, int) // Purpose: Private. Parse the headers of the request // Created: 26/3/04 // // -------------------------------------------------------------------------- void HTTPRequest::ParseHeaders(IOStreamGetLine &rGetLine, int Timeout) { std::string header; bool haveHeader = false; while(true) { if(rGetLine.IsEOF()) { // Header terminates unexpectedly THROW_EXCEPTION(HTTPException, BadRequest) } std::string currentLine; if(!rGetLine.GetLine(currentLine, false /* no preprocess */, Timeout)) { // Timeout THROW_EXCEPTION(HTTPException, RequestReadFailed) } // Is this a continuation of the previous line? bool processHeader = haveHeader; if(!currentLine.empty() && (currentLine[0] == ' ' || currentLine[0] == '\t')) { // A continuation, don't process anything yet processHeader = false; } //TRACE3("%d:%d:%s\n", processHeader, haveHeader, currentLine.c_str()); // Parse the header -- this will actually process the header // from the previous run around the loop. if(processHeader) { // Find where the : is in the line const char *h = header.c_str(); int p = 0; while(h[p] != '\0' && h[p] != ':') { ++p; } // Skip white space int dataStart = p + 1; while(h[dataStart] == ' ' || h[dataStart] == '\t') { ++dataStart; } std::string header_name(ToLowerCase(std::string(h, p))); if (header_name == "content-length") { // Decode number long len = ::strtol(h + dataStart, NULL, 10); // returns zero in error case, this is OK if(len < 0) len = 0; // Store mContentLength = len; } else if (header_name == "content-type") { // Store rest of string as content type mContentType = h + dataStart; } else if (header_name == "host") { // Store host header mHostName = h + dataStart; // Is there a port number to split off? std::string::size_type colon = mHostName.find_first_of(':'); if(colon != std::string::npos) { // There's a port in the string... attempt to turn it into an int mHostPort = ::strtol(mHostName.c_str() + colon + 1, 0, 10); // Truncate the string to just the hostname mHostName = mHostName.substr(0, colon); BOX_TRACE("Host: header, hostname = " << "'" << mHostName << "', host " "port = " << mHostPort); } } else if (header_name == "cookie") { // Parse cookies ParseCookies(header, dataStart); } else if (header_name == "connection") { // Connection header, what is required? const char *v = h + dataStart; if(::strcasecmp(v, "close") == 0) { mClientKeepAliveRequested = false; } else if(::strcasecmp(v, "keep-alive") == 0) { mClientKeepAliveRequested = true; } // else don't understand, just assume default for protocol version } else { mExtraHeaders.push_back(Header(header_name, h + dataStart)); } // Unset have header flag, as it's now been processed haveHeader = false; } // Store the chunk of header the for next time round if(haveHeader) { header += currentLine; } else { header = currentLine; haveHeader = true; } // End of headers? if(currentLine.empty()) { // All done! break; } } }
void createSourceFile(const char * dirname) { std::multimap<std::string, std::string> sorted_paths; //Step 1: Open source file std::string header_name(dirname); std::ofstream source_file(("@PROJECT_BINARY_DIR@/viennacl/linalg/kernels/" + header_name + "_source.h").c_str()); //Step 2: Write source header file preamble std::string dirname_uppercase(dirname); std::transform(dirname_uppercase.begin(), dirname_uppercase.end(), dirname_uppercase.begin(), toupper); source_file << "#ifndef VIENNACL_LINALG_KERNELS_" << dirname_uppercase << "_SOURCE_HPP_" << std::endl; source_file << "#define VIENNACL_LINALG_KERNELS_" << dirname_uppercase << "_SOURCE_HPP_" << std::endl; source_file << "//Automatically generated file from auxiliary-directory, do not edit manually!" << std::endl; source_file << "/** @file " << header_name << "_source.h" << std::endl; source_file << " * @brief OpenCL kernel source file, generated automatically from scripts in auxiliary/. */" << std::endl; source_file << "namespace viennacl" << std::endl; source_file << "{" << std::endl; source_file << " namespace linalg" << std::endl; source_file << " {" << std::endl; source_file << " namespace kernels" << std::endl; source_file << " {" << std::endl; //Step 3: Write all OpenCL kernel sources into header file fs::path filepath = fs::system_complete( fs::path( dirname ) ); if ( fs::is_directory( filepath ) ) { //std::cout << "\n In directory " << filepath.directory_string() << std::endl; fs::directory_iterator end_iter; //write and register single precision sources: for ( fs::directory_iterator alignment_itr( filepath ); alignment_itr != end_iter; ++alignment_itr ) { if (fs::is_directory( alignment_itr->path() )) { std::cout << "\nGenerating kernels from directory " << alignment_itr->path().string() << std::endl; //write and register single precision sources: for ( fs::directory_iterator cl_itr( alignment_itr->path() ); cl_itr != end_iter; ++cl_itr ) { #ifdef USE_OLD_BOOST_FILESYSTEM_VERSION std::string fname = cl_itr->path().filename(); std::string alignment = alignment_itr->path().filename(); #else std::string fname = cl_itr->path().filename().string(); std::string alignment = alignment_itr->path().filename().string(); #endif size_t pos = fname.find(".cl"); if ( pos == std::string::npos ) continue; if (fname.substr(fname.size()-3, 3) == ".cl") sorted_paths.insert(std::make_pair(fname,alignment)); //std::cout << alignment_itr->path().filename() << "/" << fname << std::endl; } //for } //if is_directory } //for alignment_iterator } //if is_directory else std::cerr << "Cannot access directory " << dirname << std::endl; for(std::multimap<std::string,std::string>::const_iterator it = sorted_paths.begin() ; it != sorted_paths.end() ; ++it){ writeSourceFile(source_file, it->first, dirname, it->second.c_str()); } //Final Step: Write file tail: source_file << " } //namespace kernels" << std::endl; source_file << " } //namespace linalg" << std::endl; source_file << "} //namespace viennacl" << std::endl; source_file << "#endif" << std::endl; source_file << std::endl; source_file.close(); }
void createKernelFile(const char * dirname) { //Step 1: Open kernel file std::string header_name(dirname); std::ofstream kernel_file(("@PROJECT_BINARY_DIR@/viennacl/linalg/kernels/" + header_name + "_kernels.h").c_str()); //Step 2: Write kernel header file preamble std::string dirname_uppercase(dirname); std::transform(dirname_uppercase.begin(), dirname_uppercase.end(), dirname_uppercase.begin(), toupper); kernel_file << "#ifndef VIENNACL_" << dirname_uppercase << "_KERNELS_HPP_" << std::endl; kernel_file << "#define VIENNACL_" << dirname_uppercase << "_KERNELS_HPP_" << std::endl; kernel_file << "#include \"viennacl/tools/tools.hpp\"" << std::endl; kernel_file << "#include \"viennacl/ocl/kernel.hpp\"" << std::endl; kernel_file << "#include \"viennacl/ocl/platform.hpp\"" << std::endl; kernel_file << "#include \"viennacl/ocl/utils.hpp\"" << std::endl; kernel_file << "#include \"viennacl/linalg/kernels/" << dirname << "_source.h\"" << std::endl; kernel_file << std::endl; kernel_file << "//Automatically generated file from aux-directory, do not edit manually!" << std::endl; kernel_file << "/** @file " << header_name << "_kernels.h" << std::endl; kernel_file << " * @brief OpenCL kernel file, generated automatically from scripts in auxiliary/. */" << std::endl; kernel_file << "namespace viennacl" << std::endl; kernel_file << "{" << std::endl; kernel_file << " namespace linalg" << std::endl; kernel_file << " {" << std::endl; kernel_file << " namespace kernels" << std::endl; kernel_file << " {" << std::endl; //Step 3: Write class information: kernel_file << " template<class TYPE, unsigned int alignment>" << std::endl; kernel_file << " struct " << dirname << ";" << std::endl << std::endl; //Step 4: Write single precision kernels std::string dir(dirname); kernel_file << std::endl << " /////////////// single precision kernels //////////////// " << std::endl; fs::path filepath = fs::system_complete( fs::path( dir ) ); if ( fs::is_directory( filepath ) ) { //std::cout << "\nIn directory: " << filepath.directory_string() << std::endl; fs::directory_iterator end_iter; //write and register single precision sources: for ( fs::directory_iterator alignment_itr( filepath ); alignment_itr != end_iter; ++alignment_itr ) { if (fs::is_directory( alignment_itr->path() )) { #ifdef USE_OLD_BOOST_FILESYSTEM_VERSION std::string subfolder = alignment_itr->path().filename(); #else std::string subfolder = alignment_itr->path().filename().string(); #endif if( subfolder.find("align") == std::string::npos ) continue; writeKernelInit(kernel_file, dirname, subfolder, true); } //if is_directory } //for alignment_iterator kernel_file << std::endl; } //if is_directory else std::cerr << "Cannot access directory " << dirname << std::endl; //Step 5: Write double precision kernels kernel_file << std::endl << " /////////////// double precision kernels //////////////// " << std::endl; filepath = fs::system_complete( fs::path( dir ) ); if ( fs::is_directory( filepath ) ) { //std::cout << "\nIn directory: " << filepath.directory_string() << std::endl; fs::directory_iterator end_iter; //write and register single precision sources: for ( fs::directory_iterator alignment_itr( filepath ); alignment_itr != end_iter; ++alignment_itr ) { if (fs::is_directory( alignment_itr->path() )) { #ifdef USE_OLD_BOOST_FILESYSTEM_VERSION std::string subfolder = alignment_itr->path().filename(); #else std::string subfolder = alignment_itr->path().filename().string(); #endif if( subfolder.find("align") == std::string::npos ) continue; writeKernelInit(kernel_file, dirname, subfolder, false); } //if is_directory } //for alignment_iterator kernel_file << std::endl; } //if is_directory else std::cerr << "Cannot access directory " << dirname << std::endl; //Final Step: Write file tail: kernel_file << " } //namespace kernels" << std::endl; kernel_file << " } //namespace linalg" << std::endl; kernel_file << "} //namespace viennacl" << std::endl; kernel_file << "#endif" << std::endl; kernel_file << std::endl; kernel_file.close(); }