2 #ifndef _MADARA_NATIVE_DOUBLE_VECTOR_STAGED_INL_
3 #define _MADARA_NATIVE_DOUBLE_VECTOR_STAGED_INL_
13 "NativeDoubleVectorStaged::modify called\n");
19 "NativeDoubleVectorStaged::modify: context is valid. Marking %s.\n",
29 std::stringstream result;
31 result <<
"Native Double Vector Staged: ";
36 MADARA_GUARD_TYPE guard(mutex_);
38 result << this->name_;
39 result <<
" [" << size() <<
"]";
40 result <<
" = " <<
context_->get(vector_).to_string();
49 return get_debug_info();
57 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
60 "NativeDoubleVectorStaged::assignment: %s: copying from %s.\n",
61 this->name_.c_str(), rhs.
name_.c_str());
64 this->name_ = rhs.
name_;
68 this->has_changed_ =
true;
73 const std::vector<type>& rhs)
104 return value_.size();
115 MADARA_GUARD_TYPE guard(mutex_);
118 "NativeDoubleVectorStaged::set_name: setting name to %s\n",
123 vector_ =
knowledge.get_ref(var_name, settings_);
127 resize(
size_t(size));
131 std::vector<type> values =
knowledge.get(vector_).to_doubles();
132 value_.set_value(values);
145 MADARA_GUARD_TYPE guard(mutex_);
148 "NativeDoubleVectorStaged::set_name: setting name to %s\n",
153 vector_ =
knowledge.get_ref(var_name, settings_);
157 resize(
size_t(size));
161 std::vector<type> values =
knowledge.get(vector_).to_doubles();
162 value_.set_value(values);
176 MADARA_GUARD_TYPE guard(mutex_);
179 "NativeDoubleVectorStaged::set_name: setting name to %s\n",
184 vector_ =
knowledge.get_ref(var_name, settings_);
188 resize(
size_t(size));
192 std::vector<type> values =
knowledge.get(vector_).to_doubles();
193 value_.set_value(values);
217 size_t other_size = other.
size();
218 size_t this_size = this->size();
222 size_t size = other_size + this_size;
230 for (
size_t i = 0, j = other_size; i < this_size - 1; ++i, ++j)
248 target.resize(size());
250 for (
size_t i = 0; i < target.size(); ++i)
252 target[i] = value_.retrieve_index(i);
268 size_t index,
type value)
273 value_.set_index(index, value);
277 const std::vector<type>& value)
287 size_t , uint32_t quality,
293 MADARA_GUARD_TYPE guard(mutex_);
296 "NativeDoubleVectorStaged::set: %s: setting quality of knowledge\n",
297 this->name_.c_str());
299 context_->set_quality(name_, quality,
true, settings);
324 "NativeIntegerVectorStaged::is_true: checking for non-zero value\n");
326 result = value_.is_true();
329 "NativeIntegerVectorStaged::is_true: final result is %d\n", (
int)result);
342 has_changed_ =
false;
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
void set_index(size_t index, T value)
sets the value at the index to the specified value.
double to_double(void) const
converts the value to a float/double.
KnowledgeRecord retrieve_index(size_t index) const
retrieves the value at an array index.
void reset_value(void) noexcept
resets the variable to an integer
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
Provides an interface for external functions into the MADARA KaRL variable settings.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores a vector of doubles inside of KaRL.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
bool has_changed_
Tracks if value_ has changed since last read.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1, bool sync=true)
Sets the variable name that this refers to.
size_t size(void) const
Returns the size of the vector.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
void set(size_t index, type value)
Sets a knowledge variable to a specified value.
void resize(size_t size)
Resizes the vector.
double type
trait that describes the value type
void read(void)
Reads the value from the knowledge base.
void transfer_to(NativeDoubleVectorStaged &other)
Transfers elements from this vector to another.
void modify(void)
Mark the value as modified.
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
void exchange(NativeDoubleVectorStaged &other)
Exchanges the vector at this location with the vector at another location.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
void operator=(const NativeDoubleVectorStaged &rhs)
Assignment operator.
type operator[](size_t index) const
Retrieves a copy of the record from the map.
bool is_true(void) const
Determines if all values in the vector are true.
void set_quality(size_t index, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
ThreadSafeContext * context_
Variable context that we are modifying.
void write(void)
Writes the value to the knowledge base.
VariableReference vector_
Reference to the size field of the vector space.
bool is_false(void) const
Determines if the value of the vector is false.
KnowledgeRecord value_
The staged value of the vector.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger