Metall  v0.29
A persistent memory allocator for data-centric analytics
object_attribute.cpp

This is an example of how to access object attributes.

// Copyright 2020 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
#include <iostream>
#include <string>
int main() {
// Set and get object attributes via metall::manager object
{
metall::manager manager(metall::create_only, "/tmp/dir");
auto *obj = manager.construct<int>("obj")();
std::string description;
manager.get_instance_description(obj, &description);
std::cout << "Name: " << manager.get_instance_name(obj)
<< ", Length: " << manager.get_instance_length(obj)
<< ", Description: " << description << std::endl;
manager.set_instance_description(obj, "description example 1");
}
// Set and get object attributes via object attribute accessor object
// Using object attribute accessor, one can access object attribute without
// allocating a metall::manager object (i.e., w/o memory mapping files).
{
for (const auto &object : accessor) {
std::cout << "Name: " << object.name() << ", Length: " << object.length()
<< ", Description: " << object.description() << std::endl;
}
auto itr = accessor.find("obj");
accessor.set_description(itr, "description example 2");
std::cout << "Name: " << itr->name() << ", Length: " << itr->length()
<< ", Description: " << itr->description() << std::endl;
}
return 0;
}
A generalized Metall manager class.
Definition: basic_manager.hpp:40
static named_object_attribute_accessor_type access_named_object_attribute(const path_type &path) noexcept
Returns an instance that provides access to the attribute of named objects.
Definition: basic_manager.hpp:1274
int main()
Definition: jgraph.cpp:24
basic_string< char > string
A string container that uses char as its character type and Metall as its default allocator.
Definition: string.hpp:23
basic_manager<> manager
Default Metall manager class which is an alias of basic_manager with the default template parameters.
Definition: metall.hpp:34