-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type of elements in a data set cannot be modified #37
Comments
This could be solved with the following API change.
/// Clear the contents of the element (element.get_value().get_type() will be Empty)
void Element::clear();
/// Clear the contents of an element (data_set.empty(tag) will be true)
void DataSet::clear(Tag const & tag);
Value value; // empty
value.as_integers() = {1,2,3,4}; // empty -> integers
value.as_strings() = {"foo", "bar"}; // integers -> strings, integers value is lost @cguebert: does this address your remarks? |
I wrote a response but I didn't read correctly the second part of your message. Do you propose to change the type of the value depending on the accessor used? Example: I would prefer keeping with the current API, in the spirit that it prevents mistakes. |
Slowly getting to the end of my backlog... We seem to have three different cases:
Case 1 is solved by the Case 2 requires a slight modification of the non- void f(Value & v) // f does not modify v, but v is passed by non-const reference
{
// This calls the non-const as_int (cf. standard 13.3.3.2/3, rule beginning with
// "S1 and S2 are reference bindings)
std::cout << v.as_int().size();
}
void g()
{
Value v; // v.empty() is true
f(v); // v now holds an empty array of integers
} Case 3 is the one you mention. I tried to find a real-life use-case for it, but failed. Case 1 will be implemented, case 3 won't, and, unless I missed an easy way to remove the aforementioned side-effect, case 2 won't be implemented either. |
I think the discussion is going way off course of the original comment. I do not want to change the type of a Value (if I wanted, I know of remove + add). The commit 19cb2a8 changed how we access the elements in a data set. The safe way to access a value is now similar to this: if ( dataSet.has(odil::registry::PatientName) && !dataSet.empty(odil::registry::PatientName) )
myValue = dataSet.as_string(odil::registry::PatientName, 0); I find it cumbersome and quite inefficient as it looks into the map 3 times now. (This pushed me to create a DataSet wrapper to use boost::optional in order to limit this type of access). |
I indeed misunderstood your initial report. The last two commits (c9cc057 and 225ddc3) restore the behavior of the For more technical details, the commits remove the
Tell me if this solves the issue. |
The type of elements in data set, once added, cannot be modified: they must be deleted and re-added. See the comments in 19cb2a8
The text was updated successfully, but these errors were encountered: