bool playturn_network_adapter::read(config& dst) { assert(dst.empty()); if(is_at_end()) { read_from_network(); } if(is_at_end()) { //that means we couldn't read anything from the network. return false; } //skip empty data. while(next_ == data_.begin()->ordered_end()) { data_.pop_front(); next_ = data_.front().ordered_begin(); assert(!is_at_end()); } config& child = dst.add_child(next_->key); //TODO: implement a non const version of ordered children config& child_old = const_cast<config&>(next_->cfg); if(next_->key == "turn") { //split [turn] indo different [turn] for each child. assert(next_->cfg.all_children_count() > next_command_num_); config::all_children_iterator itor = child_old.ordered_begin(); //TODO: implement operator + (all_children_iterator, int ) properly std::advance(itor, next_command_num_); //TODO: implement a non const version of ordered children config& childchild_old = const_cast<config&>(itor->cfg); config& childchild = child.add_child(itor->key); childchild.swap(childchild_old); ++next_command_num_; if(next_->cfg.all_children_count() == next_command_num_) { next_command_num_ = 0; ++next_; } return true; } else { child.swap(child_old); ++next_; return true; } }
void test_insert(list_t *list) { result_t insert_result; insert_result = insert_at_begin(list, 10); assert(insert_result == SUCCESS && is_at_begining(list, 10) == TRUE); insert_result = insert_at_end(list, 40); assert(insert_result == SUCCESS && is_at_end(list, 40) == TRUE); insert_result = insert_before_data(list, 40, 30); assert(insert_result == SUCCESS && is_before(list, 30, 40) == TRUE); insert_result = insert_before_data(list, 10, 5); assert(insert_result == SUCCESS && is_before(list, 5, 10) == TRUE); insert_result = insert_before_data(list, 100, 50); assert(insert_result == ERROR && is_before(list, 50, 100) == FALSE); insert_result = insert_after_data(list, 40, 50); assert(insert_result == SUCCESS && is_after(list, 50, 40) == TRUE); insert_result = insert_after_data(list, 5, 8); assert(insert_result == SUCCESS && is_after(list, 8, 5) == TRUE); insert_result = insert_after_data(list, 35, 45); assert(insert_result == ERROR && is_after(list, 45, 35) == FALSE); }
playturn_network_adapter::~playturn_network_adapter() { if(!is_at_end()) { ERR_NW << "Destroing playturn_network_adapter with an non empty buffer, this means loss of network data\n"; } }
playturn_network_adapter::~playturn_network_adapter() { try { if(!is_at_end()) { LOG_NW << "Destroying playturn_network_adapter with an non empty buffer, this means loss of network data" << std::endl; } } catch (...) {} }
void test_reverse_lists() { list_t *list = create_list(); insert_at_end(list, 10); insert_at_end(list, 20); insert_at_end(list, 30); insert_at_end(list, 40); result_t reverse_result = reverse_list(list); assert(reverse_result == SUCCESS && is_at_begining(list, 40) && insert_before_data(list, 40, 30) && is_after(list, 10, 20) && is_at_end(list, 10)); distroy(&list); }
void test_merge_lists() { list_t *list_1 = create_list(); list_t *list_2 = create_list(); insert_at_end(list_1, 100); insert_at_end(list_1, 54); insert_at_end(list_1, 65); insert_at_end(list_2, 87); insert_at_end(list_2, 120); insert_at_end(list_2, 45); list_t *merged_list = merge(list_1, list_2); assert(merged_list != NULL && is_at_begining(merged_list, 45) && is_at_end(merged_list, 120)); distroy(&merged_list); }
void test_concat_lists() { list_t *list_1 = create_list(); list_t *list_2 = create_list(); insert_at_end(list_1, 10); insert_at_end(list_1, 20); insert_at_end(list_1, 30); insert_at_end(list_2, 40); insert_at_end(list_2, 50); insert_at_end(list_2, 60); list_t *new_list = concat(list_1, list_2); assert(is_at_begining(new_list, 10) && is_at_end(new_list, 60)); distroy(&new_list); }
void test_delete(list_t *list) { result_t delete_result; delete_result = delete_begin(list); assert(delete_result == SUCCESS && is_at_begining(list, 5) == FALSE); delete_result = delete_data(list, 50); assert(delete_result == SUCCESS && find(list, 50) == FALSE); delete_result = delete_data(list, 8); assert(delete_result == SUCCESS && find(list, 8) == FALSE); delete_result = delete_data(list, 80); assert(delete_result == ERROR); delete_result = delete_end(list); assert(delete_result == SUCCESS && is_at_end(list, 40) == FALSE); }