OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-storage commits / fcbe493

Use a utility function for access
fcbe493657f8d0027990721e6ec1e3ecff09a977
by Linas Vepstas <linasvepstas@gmail.com> · 2026-01-18T19:04:32.000Z

Changed files (2) +39 -33

opencog/persist/api/StorageNode.cc +35 -32
……@@ -50,6 +50,32 @@ StorageNode::~StorageNode()
5050{
5151}
5252
53AtomSpace* StorageNode::get_target_as(const ValuePtr& value) const
54{
55 if (value->is_type(ATOM_SPACE))
56 return AtomSpaceCast(value).get();
57
58 if (nullptr == vp or 0 == vp->size())
59 return _target_as.get();
60
61 ValuePtr vp(value);
62 if (vp->is_type(ATOM))
63 {
64 Handle h(HandleCast(value));
65 if (h->is_executable())
66 vp = h->execute();
67 }
68
69 if (vp->is_type(ATOM_SPACE))
70 return AtomSpaceCast(vp).get();
71
72 if (nullptr == vp or 0 == vp->size())
73 return _target_as.get();
74
75 throw RuntimeException(TRACE_INFO,
76 "Expected AtomSpace; got %s", value->to_string().c_str());
77}
78
5379void StorageNode::setValue(const Handle& key, const ValuePtr& value)
5480{
5581 // The value must be stored only if it is not one of the values
……@@ -127,23 +153,9 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value)
127153 {
128154 case p_open: {
129155 COLL("*-open-*");
130 ValuePtr vp(value);
131 if (vp->is_type(ATOM))
132 {
133 Handle h(HandleCast(value));
134 if (h->is_executable())
135 vp = h->execute();
136 }
137
138 if (vp->is_type(ATOM_SPACE))
139 _target_as = AtomSpaceCast(value);
140 else if (nullptr == vp or 0 == vp->size())
141 _target_as = AtomSpaceCast(getAtomSpace()->shared_from_this());
142 else
143 throw RuntimeException(TRACE_INFO,
144 "Expected *-open-* message expects AtomSpace; got %s",
145 value->to_string().c_str());
146
156 AtomSpace* as = get_target_as(value);
157 if (nullptr == as) as = getAtomSpace();
158 __target_as = AtomSpaceCast(as->shared_from_this());
147159 open();
148160 return;
149161 }
……@@ -154,17 +166,11 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value)
154166 return;
155167 case p_load_atomspace:
156168 COLL("*-load-atomspace-*");
157 if (nullptr == value or 0 == value->size())
158 load_atomspace(_target_as.get());
159 else
160 load_atomspace(AtomSpaceCast(value).get());
169 load_atomspace(get_target_as(value));
161170 return;
162171 case p_store_atomspace:
163172 COLL("*-store-atomspace-*");
164 if (nullptr == value or 0 == value->size())
165 store_atomspace(_target_as.get());
166 else
167 store_atomspace(AtomSpaceCast(value).get());
173 store_atomspace(get_target_as(value));
168174 return;
169175 case p_load_atoms_of_type: {
170176 COLL("*-load-atoms-of-type-*");
……@@ -301,10 +307,7 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value)
301307 return;
302308 case p_barrier:
303309 COLL("*-barrier-*");
304 if (nullptr == value or 0 == value->size())
305 barrier(_target_as.get());
306 else
307 barrier(AtomSpaceCast(value).get());
310 barrier(get_target_as(value));
308311 return;
309312 case p_store_frames:
310313 COLL("*-store-frames-*");
……@@ -370,7 +373,7 @@ void StorageNode::barrier(AtomSpace* as)
370373
371374void StorageNode::store_atom(const Handle& h)
372375{
373 if (_atom_space->get_read_only())
376 if (_target_as->get_read_only())
374377 throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!");
375378
376379 storeAtom(h);
……@@ -378,7 +381,7 @@ void StorageNode::store_atom(const Handle& h)
378381
379382void StorageNode::store_value(const Handle& h, const Handle& key)
380383{
381 if (_atom_space->get_read_only())
384 if (_target_as->get_read_only())
382385 throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!");
383386
384387 storeValue(h, key);
……@@ -387,7 +390,7 @@ void StorageNode::store_value(const Handle& h, const Handle& key)
387390void StorageNode::update_value(const Handle& h, const Handle& key,
388391 const ValuePtr& delta)
389392{
390 if (_atom_space->get_read_only())
393 if (_target_as->get_read_only())
391394 throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!");
392395
393396 updateValue(h, key, delta);
opencog/persist/api/StorageNode.h +4 -1
……@@ -46,9 +46,12 @@ class StorageNode : public ObjectCRTP<StorageNode>, protected BackingStore
4646 friend class WriteThruProxy;
4747 friend class ReadWriteProxy;
4848 friend class ObjectCRTP<StorageNode>;
49protected:
49private:
5050 AtomSpacePtr _target_as;
5151
52protected:
53 AtomSpace* get_target_as(const ValuePtr&) const;
54
5255 // Friendship cannot be inherited in c++. So we pass through selected
5356 // functions to derived classes that will need them.
5457 static inline Handle add_nocheck(AtomSpace* as, const Handle& h)