void madara::knowledge::containers::NativeDoubleVector::copy_to ( KnowledgeVector & target) const { if (context_) { ContextGuard context_guard (*context_); MADARA_GUARD_TYPE guard (mutex_); madara_logger_ptr_log (logger::global_logger.get (), logger::LOG_MAJOR, "NativeDoubleVector::copy_to: %s: copying elements to vector\n", this->name_.c_str ()); target.resize (size ()); for (size_t i = 0; i < target.size (); ++i) { target[i].deep_copy ((*this)[i]); } } }
void madara::knowledge::containers::IntegerVector::copy_to ( KnowledgeVector & target) const { if (context_) { ContextGuard context_guard (*context_); MADARA_GUARD_TYPE guard (mutex_); target.resize (vector_.size ()); for (size_t i = 0; i < vector_.size (); ++i) { target[i].deep_copy ((*this)[i]); } } }
void test_vector (void) { std::cerr << "************* VECTOR: CREATING VECTOR*************\n"; knowledge::KnowledgeBase knowledge; containers::Vector vector ("test_vector", knowledge, 10); size_t size = vector.size (); vector.set (1, "value.at.1"); vector.set (7, 7.7); knowledge.clear_modifieds (); std::cerr << "Vector contents (modified) after clear\n"; vector.set (2, "value.at.2"); std::cerr << "Vector results:\n"; for (size_t i = 0; i < size; ++i) { std::cerr << " "; std::cerr << vector[i]; std::cerr << "\n"; } std::cerr << "\n"; if (size != 10) std::cerr << "FAIL. Vector.size != 10\n"; else std::cerr << "SUCCESS. Vector.size == 10\n"; if (vector[1] == "value.at.1" && vector[7] == 7.7) std::cerr << "SUCCESS. Vector[1] and [7] were set and retrieved.\n"; else std::cerr << "FAIL. Vector[1] and [7] were not set and retrieved.\n"; if (vector.get_name () == "test_vector") std::cerr << "SUCCESS. vector.name () returned test_vector.\n"; else std::cerr << "FAIL. vector.name () did not return test_vector.\n"; std::cerr << "Resizing to 7 elements.\n"; vector.resize (7); if (vector[1].to_string () == "value.at.1" && knowledge.get ("test_vector.7") != 7.7 && vector.size () == 7) std::cerr << "SUCCESS. Vector [7] no longer exists.\n"; else std::cerr << "FAIL. Vector [7] still exists after resize.\n"; vector.resize (12); vector.set (8, "value.at.8"); vector.set (9, "value.at.9"); if (vector[1] == "value.at.1" && vector[8] == "value.at.8" && vector[9] == "value.at.9" && vector.size () == 12) std::cerr << "SUCCESS. Resize to 12 was successful.\n"; else std::cerr << "FAIL. Resize to 12 was unsuccessful.\n"; std::cerr << "Copying records from vector to a knowledge vector.\n"; vector.set (11, "value.at.11"); std::cerr << "Printing results from knowledge base.\n"; knowledge.print (); KnowledgeVector records; vector.copy_to (records); std::cerr << "Printing resulting knowledge vector.\n"; for (size_t i = 0; i < records.size (); ++i) { std::cerr << " " << i << ": " << records[i] << "\n"; } std::cerr << "Printing results from knowledge base.\n"; knowledge.print (); std::cerr << "Resizing vector to zero elements.\n"; vector.resize (0); std::cerr << "Printing results from knowledge base.\n"; knowledge.print (); }