Private attributes in a CTModule

by Bill, 2017/03/02

I am trying to add a private attribute to a CTModule, to be saved to disk, but I think it's being stripped out. Using the provided example code, I constructed a valid CTModule object ("ct"), and used the code at the bottom of this post to test the insertion. I have verified the attribute gets added to the AttributeManager, and I can set the attributes of the CTModule using this AttributeManager, but when I subsequently query the CTModule for attributes at the end, my custom attribute is missing. Is this intended?

 

    // Construct a valid CTModule object (not shown)

    SDICOS::Tag tag;
    tag.Set(0x0909, 0x0909);

    SDICOS::AttributeManager manager;
    SDICOS::ErrorLog errorlog;
    ct.GetAttributesAndValidate(manager, errorlog);

    SDICOS::AttributeManager::AttributePointer<SDICOS::AttributeString> attptr1;
    
    manager.FindAttribute(tag, attptr1, true);
    attptr1->SetSize(1, SDICOS::AttributeString::enumLongString);
    (*attptr1)[0] = "ASDASD";
    
    SDICOS::AttributeManager manager2;
    SDICOS::AttributeManager::AttributePointer<SDICOS::AttributeString> attrptr2;

    ct.GetAttributesAndValidate(manager2, errorlog);
    bool found = manager2.FindAttribute(tag, attrptr2);
    
    std::cout << "Was value found?: " << found << std::endl;  // Always displays 0
    std::cout << "Value: " << (*attrptr2)[0] << std::endl;  // Segfaults because attribute is not found

 

2 answers
1
0
-1

The attribute manager returned by CTModule::GetAttributesAndValidate() is not a reference to an internal member variable, it is strictly a copy of the attributes stored within the CTModule.  The call to GetAttributesAndValidate() clears the passed in attribute manager of any data before copying the CTModule's data. Adding or removing attributes from this attribute manager will not add or remove them from the CTModule.

Private tags are only supported by the attribute manager.  To add private tags when using CTModule, retrieve the attribute manager from the GetAttributesAndValidate(), then add the custom attribute, which is what you already did.  The custom attribute will only exist in that attribute manager.

While distilling the enclosed code, I left out the most important line (after adding the private attribute to the manager), which probably was confusing: ct.SetAttributes(manager, errorlog); The goal was to have a CTModule that contained private tags, but if "Private tags are only supported by the attribute manager", then I have my answer. Thanks~
answered Thursday, March 2, 2017 - 12:02
1
0
-1

(Reposting the code portion to see if the formatting can be fixed)

// Construct a valid CTModule object (not shown)

SDICOS::Tag tag;
tag.Set(0x0909, 0x0909);

SDICOS::AttributeManager manager;
SDICOS::ErrorLog errorlog;
ct.GetAttributesAndValidate(manager, errorlog);

SDICOS::AttributeManager::AttributePointer attptr1;

manager.FindAttribute(tag, attptr1, true);
attptr1->SetSize(1, SDICOS::AttributeString::enumLongString);
(*attptr1)[0] = "ASDASD";

SDICOS::AttributeManager manager2;
SDICOS::AttributeManager::AttributePointer attrptr2;

ct.GetAttributesAndValidate(manager2, errorlog);
bool found = manager2.FindAttribute(tag, attrptr2);

std::cout << "Was value found?: " << found << std::endl; // Always displays 0
std::cout << "Value: " << (*attrptr2)[0] << std::endl; // Segfaults because attribute is not found