SynBioDex / libSBOL

C++ implementation of SBOL 2.3.2
Apache License 2.0
15 stars 7 forks source link

ComponentDefinition in ModuleDefinition and toplevel --> duplicate error #41

Closed jakebeal closed 7 years ago

jakebeal commented 8 years ago

If you include a ComponentDefinition into a ModuleDefinition, libSBOL inlines it into the ModuleDefinition and will not allow it to exist at the top level. This prevents use of a ComponentDefinition in more than one module.

An example of this failure:

#include "sbol.h"
#include <iostream>

using namespace sbol;
using namespace std;

int main() {
    Document& doc = *new Document();

    cout << "Making CRISPR bits\n";
    setHomespace("http://sys-bio.org");
    ModuleDefinition& CRPa = *new ModuleDefinition("CRISPRTemplate");
    ComponentDefinition& Cas9 = *new ComponentDefinition("Cas9", BIOPAX_PROTEIN);

    /******* Minimal failure model */
    doc.add<ModuleDefinition>(CRPa);
    CRPa.functionalComponents.add(Cas9);
    doc.add<ModuleDefinition>(CRPa);
    doc.add<ComponentDefinition>(Cas9);

    doc.write("test-sbol.xml");
    cout << "Should have failed already" << endl;
}
bbartley commented 8 years ago

The functionalComponents property should only accept FunctionalComponent objects...not ComponentDefinitions. Use FunctionalComponent& cas9_fc = CRPa.functionalComponents.create() to instantiate it.

jakebeal commented 8 years ago

Huh... my assumption is that this was overriding to create the right object type. Should have remembered that C++ doesn't support being that fancy...

jakebeal commented 8 years ago

Well, new bug then: this should have thrown a compile error, rather than blithely accepting my incorrect typing.