binary_expression_sentence_t(name_t verb, const array_t& subject_expression, const array_t& dirobj_expression) : verb_m(verb), subject_expression_m(subject_expression), dirobj_expression_m(dirobj_expression) { if (subject_expression_m == array_t()) throw std::runtime_error("Subject expression cannot be empty"); if (dirobj_expression_m == array_t()) throw std::runtime_error("Direct object expression cannot be empty"); }
member_of& member_of::operator[](std::size_t offset) { if(v_ptr_) { if( 0 == v_ptr_->which() ) *v_ptr_ = array_t(); if(ARRAY_WHICH == v_ptr_->which()) { v_ptr_ = &(boost::get<array_t>(*v_ptr_)[offset]); } else { v_ptr_ = 0; } } return *this; }
member_of& member_of::operator()(std::size_t offset) { JSON_ACCESS_TRACKING(offset); if(v_ptr_) { if( 0 == v_ptr_->which() ) *v_ptr_ = array_t(); if(ARRAY_WHICH == v_ptr_->which()) { array_t &a = boost::get<array_t>(*v_ptr_); if(a.size() <= offset) a.resize(offset+1); v_ptr_ = &(a[offset]); } else { v_ptr_ = 0; } } return *this; }
int drake_init(task_t *task, void* aux) { link_t *link; array_t(int) *tmp; size_t input_buffer_size, input_size, i; // The following makes tasks having no predecessor to load input data // and make a new input link that links to no task but that holds the // data to be sorted and merged // Fetch arguments and only load data if an input filename is given args_t *args = (args_t*)aux; if(args->argc > 0) { input_filename = ((args_t*)aux)->argv[0]; // Read only the number of elements in input tmp = pelib_array_preloadfilenamebinary(int)(input_filename); if(tmp != NULL) { // Read the number of elements to be sorted input_size = pelib_array_length(int)(tmp); // No need of this array anymore pelib_free_struct(array_t(int))(tmp); // If the task has no predecessor (is a leaf) // then we should build input links that hold // input data. if(pelib_array_length(link_tp)(task->pred) == 0) { // Destroy the input link array for this task // It will be replaced with an array of two link // each holding the data subset to be sorted and // merged pelib_free(array_t(link_tp))(task->pred); // Initialize a new input link array that can hold two input links task->pred = pelib_alloc_collection(array_t(link_tp))(2); // Calculate the number of elements each input links of this task will load, that is: // The total number of elements divided by the number of leaves. Here, we assume a // balanced binary tree. input_buffer_size = input_size / ((drake_task_number() + 1) / 2) / 2; // Let's build two new input links and make them load data for(i = 0; i < 2; i++) { // Allocation link = (link_t*)malloc(sizeof(link_t)); // The new input link doesn't have any producer task link->prod = NULL; // The task being initialized is the consumer end of the link link->cons = task; // Load the portion of input file that corresponds to the leaf task. Since fifos have no implementation // for I/Os, we load an array and then turn it to a fifo link->buffer = (cfifo_t(int)*)pelib_array_loadfilenamewindowbinary(int)(input_filename, 2 * input_buffer_size * (task->id - ((drake_task_number() + 1) / 2)) + input_buffer_size * i, input_buffer_size); // Turn array to fifo link->buffer = pelib_cfifo_from_array(int)((array_t(int)*)link->buffer); // Finally, add the new link to the input links array pelib_array_append(link_tp)(task->pred, link); } }