def __init__(self, schema, data):
     self._data = data
     validator = typeconverter.to_type_converter(schema)
     self._sync_data = {}
     for key in data:
         self._sync_data[key] = collections._to_hoomd_data(
             root=self,
             schema=validator[key],
             parent=None,
             identity=key,
             data=data[key],
         )
Beispiel #2
0
    def _single_setitem(self, key, item):
        """Set parameter by key.

        Assumes value to be validated already.
        """
        if isinstance(self._dict.get(key), _HOOMDSyncedCollection):
            self._dict[key]._isolate()
        self._dict[key] = _to_hoomd_data(root=self,
                                         schema=self._type_converter,
                                         data=item,
                                         parent=None,
                                         identity=key)
        if not self._attached:
            return
        # We don't need to set the _dict yet since we will query C++ when
        # retreiving the key the next time.
        getattr(self._cpp_obj, self._setter)(key, item)
Beispiel #3
0
    def _single_getitem(self, key):
        """Access parameter by key.

        __getitem__ expects an exception to indicate the key is not there.
        """
        if not self._attached:
            return self._dict[key]
        # We always attempt to keep the _dict up to date with the C++ values,
        # and isolate existing components otherwise.
        validated_cpp_value = self._validate_values(
            getattr(self._cpp_obj, self._getter)(key))
        if isinstance(self._dict[key], _HOOMDSyncedCollection):
            if self._dict[key]._update(validated_cpp_value):
                return self._dict[key]
            else:
                self._dict[key]._isolate()
        self._dict[key] = _to_hoomd_data(root=self,
                                         schema=self._type_converter,
                                         data=validated_cpp_value,
                                         parent=None,
                                         identity=key)
        return self._dict[key]
Beispiel #4
0
 def _to_hoomd_data(self, key, value):
     return _to_hoomd_data(root=self,
                           schema=self._type_converter[key],
                           parent=None,
                           identity=key,
                           data=value)