diff --git a/_test/test_object_containers/unique_only_obj_container_tester.m b/_test/test_object_containers/unique_only_obj_container_tester.m index d46ae64f3f..a6793b5a40 100644 --- a/_test/test_object_containers/unique_only_obj_container_tester.m +++ b/_test/test_object_containers/unique_only_obj_container_tester.m @@ -26,4 +26,4 @@ gid = obj.idx_(1:obj.max_obj_idx_); end end -end \ No newline at end of file +end diff --git a/herbert_core/utilities/classes/@unique_objects_container/private/add_if_new_single_.m b/herbert_core/utilities/classes/@unique_objects_container/private/add_if_new_single_.m deleted file mode 100644 index 3db8b22f37..0000000000 --- a/herbert_core/utilities/classes/@unique_objects_container/private/add_if_new_single_.m +++ /dev/null @@ -1,43 +0,0 @@ -function [self,lidx] = add_if_new_single_(self,obj) -%ADD_IF_NEW_SINGLE_ Add single object to the unique objects container -% if it is not already there. If it is, increase number of object references -% -% -% Input -% ----- -% self - the unique_objects_container in question -% obj - the object to be added to the container -% -% Output -% ------ -% self - the modified container (modified by adding obj) -% nuix - the insertion index at which obj is added in the container - -% check that obj is of the appropriate base class -if ~isempty(self.baseclass_) && ~isa(obj, self.baseclass_) - error('HERBERT:unique_objects_container:invalid_argument', ... - 'Adding object of class: "%s" to reference container of class "%s" is not allowed', ... - class(obj),self.baseclass_); -end - -% if ix and hash are not specified, call find_in_container to get them - -[lidx,hash,obj] = self.find_in_container(obj); - -% If the object is not in the container add it to the container. -if isempty(lidx) % means obj not in container and should be added - - [self,lidx] = self.check_and_expand_memory_if_necessary(); - - p_free = self.lidx_(lidx); - - self.stored_hashes_{p_free} = hash; - self.unique_objects_{p_free} = obj; - self.n_duplicates_(p_free) = 1; - self.idx_(p_free) = p_free; - self.n_unique_ = self.n_unique_+1; - -else - self.n_duplicates_(lidx) = self.n_duplicates_(lidx)+1; -end - diff --git a/herbert_core/utilities/classes/@unique_objects_container/private/add_single_.m b/herbert_core/utilities/classes/@unique_objects_container/private/add_single_.m index 070008c3ae..cb77532aea 100644 --- a/herbert_core/utilities/classes/@unique_objects_container/private/add_single_.m +++ b/herbert_core/utilities/classes/@unique_objects_container/private/add_single_.m @@ -23,7 +23,7 @@ 'not correct base class; object was not added'); end -% call find_in_container to get ix and hash +% call find_in_container to get ix and hash [ix,hash,obj] = self.find_in_container(obj); @@ -32,7 +32,7 @@ % store the object in the stored objects % take the index of the last stored object as the object index if isempty(ix) % means obj not in container and should be added - self.stored_hashes_ = [self.stored_hashes_(:);hash]'; + self.stored_hashes_ = [self.stored_hashes_(:);hash]'; self.unique_objects_ = [self.unique_objects_(:); {obj}]'; ix = numel(self.unique_objects_); diff --git a/herbert_core/utilities/classes/@unique_references_container/private/set_container_from_saved_objects_.m b/herbert_core/utilities/classes/@unique_references_container/private/set_container_from_saved_objects_.m index fd431d0b80..166c3f32da 100644 --- a/herbert_core/utilities/classes/@unique_references_container/private/set_container_from_saved_objects_.m +++ b/herbert_core/utilities/classes/@unique_references_container/private/set_container_from_saved_objects_.m @@ -18,8 +18,7 @@ end end storage = unique_obj_store.instance().get_objects(self.baseclass); -self.idx_ = zeros(1,val.n_objects); -for i=1:val.n_objects - [storage,gidx] = storage.add(val(i)); - self.idx_(i) = gidx; -end +[storage,gidx] = storage.add(val); +self.idx_ = gidx; +% this code is part of more general method, which sends changes in storage +% to global store. No need to do it here. set_objecs will be done later. diff --git a/herbert_core/utilities/classes/ObjContainersBase.m b/herbert_core/utilities/classes/ObjContainersBase.m index bd3b79a860..040c9c794d 100644 --- a/herbert_core/utilities/classes/ObjContainersBase.m +++ b/herbert_core/utilities/classes/ObjContainersBase.m @@ -277,19 +277,20 @@ function list(self,field) [self,nuix] = self.add_single(obj); end % add() % - function obj = get(self,nuix) + function obj = get(self,nguix) % given the non-unique global index nuix that you know about % for your object (it was returned when you added it to the % container with add or replace) get the unique object % associated with this index. % % Input: - % - nuix : non-unique index that has been stored somewhere for - % this object + % - nguix : non-unique index that has been stored somewhere for + % this object and identifies the location of the + % object in unique_obj_store.container. % Output: - % - obj : the unique object store for this index + % - obj : the unique object located at this index % - obj = self.get_unique_objects(nuix); + obj = self.get_unique_objects(nguix); end end % Setter/getters for common interface with class-specific