支持特定于实现的对象元数据的最佳方法是什么? (虽然希望仍然是强类型)

发布于 2024-10-25 06:07:37 字数 2318 浏览 0 评论 0原文

为了保持简短(并且切中要点),我将列出三个简短的对象构造,然后解释我在这里想要完成的任务。

tree_object class-

class tree_object
{
protected:
    std::string    name_;
    tree_object*   root_;
    uint32_t       type_;

    // tree_objec::tree_object();
    tree_object(enum OBJECT_TYPE type);

    // tree_objec::tree_object();
    tree_object(std::string name, enum OBJECT_TYPE type = ENTITY);

    // tree_objec::tree_object();
    tree_object(std::string name, enum OBJECT_TYPE type, tree_object& parent);

public:
    // default constructor.
    tree_object();

   // Attach me to some parent node.
   virtual bool attach(tree_object& parent);

   // Detach me from my current parent.
   virtual bool detach(bool forced = false);

   // Get object name
   virtual operator std::string();

   // Set object name
   void operator=(std::string value);

   // Get object type
   virtual operator uint32_t();
};

Directory_object-

class directory_object: public tree_object
{   
    // List of children
    std::vector<tree_object> children;

public:
    // Attach me to some parent node.
    bool attach(tree_object& parent);

    // Detach me from my current parent.
    bool detach(bool forced = false);

    directory_object(std::string element_name = "");
    directory_object(std::string element_name, tree_object& parent);
    directory_object(std::string element_name, directory_object& parent);
};

filesystem_object-

class filesystem_object: public tree_object
{   
public:
    // Attach me to some parent node.
    bool attach(tree_object& parent);

    // Detach me from my current parent.
    bool detach(bool forced = false);

    filesystem_object(std::string element_name = "");
    filesystem_object(std::string element_name, tree_object& parent);
    filesystem_object(std::string element_name, directory_object& parent);
};

鉴于上述对象定义,我想要做的是将以下概念添加到 directory_objectfilesystem_object 中:

  1. 特定于实现的 ACL directory_objectfilesystem_object
  2. 实现特定的用户标签数据的条目(即对迭代树的特定实例的代码有意义的结构。)

给定上述信息,我怎样才能最好地实现这些目标?

PS这可能是未来的实现细节,但我最终将“远程”访问我的树实现(即这将在线程服务器中结束,因此此处提供的任何帮助都应该能够在那里实现< em>和这里。)

谢谢。

In the interests of keeping this short (and on-point), I'm going to lay out three short object constructs and then explain what it is that I'm trying to accomplish here.

tree_object class-

class tree_object
{
protected:
    std::string    name_;
    tree_object*   root_;
    uint32_t       type_;

    // tree_objec::tree_object();
    tree_object(enum OBJECT_TYPE type);

    // tree_objec::tree_object();
    tree_object(std::string name, enum OBJECT_TYPE type = ENTITY);

    // tree_objec::tree_object();
    tree_object(std::string name, enum OBJECT_TYPE type, tree_object& parent);

public:
    // default constructor.
    tree_object();

   // Attach me to some parent node.
   virtual bool attach(tree_object& parent);

   // Detach me from my current parent.
   virtual bool detach(bool forced = false);

   // Get object name
   virtual operator std::string();

   // Set object name
   void operator=(std::string value);

   // Get object type
   virtual operator uint32_t();
};

directory_object-

class directory_object: public tree_object
{   
    // List of children
    std::vector<tree_object> children;

public:
    // Attach me to some parent node.
    bool attach(tree_object& parent);

    // Detach me from my current parent.
    bool detach(bool forced = false);

    directory_object(std::string element_name = "");
    directory_object(std::string element_name, tree_object& parent);
    directory_object(std::string element_name, directory_object& parent);
};

filesystem_object-

class filesystem_object: public tree_object
{   
public:
    // Attach me to some parent node.
    bool attach(tree_object& parent);

    // Detach me from my current parent.
    bool detach(bool forced = false);

    filesystem_object(std::string element_name = "");
    filesystem_object(std::string element_name, tree_object& parent);
    filesystem_object(std::string element_name, directory_object& parent);
};

Given the above object definitions, what I'm looking to do is add support for the following concepts to directory_object and filesystem_object:

  1. implementation-specific ACL entries for both directory_object and filesystem_object
  2. implementation-specific user tag-data (i.e. a struct that means something to the code iterating a specific instance of the tree.)

Given the information above, how best would I be able to accomplish these goals?

P.S. This might be a future implementation detail, but I am eventually going to be accessing my tree implementation "remotely" (i.e. this is going to wind up in a threaded server, so any assistance provided here should be able to be implemented both there and here.)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文