コード例 #1
0
    def generate_object_factory(self, objects, max_class_no):
        # print "Output of implementation for:",
        outfile = self.outdir + '/Factories_generated.cpp'
        # print outfile
        self.out = open(outfile + ".tmp", "w")
        self.write(copyright_template % ("Aloril", "Alistair Riddoch"))
        self.write('\n#include <Atlas/Objects/Entity.h>\n')
        self.write('#include <Atlas/Objects/Anonymous.h>\n')
        self.write('#include <Atlas/Objects/Operation.h>\n\n')
        self.write('#include <Atlas/Objects/Generic.h>\n\n')
        self.ns_open(self.base_list)
        self.write('\nint Factories::enumMax = ')
        self.write(str(max_class_no))
        self.write(';\n')
        self.write("""
void Factories::installStandardTypes()
{
""")  # "for xemacs syntax highlighting
        for (obj, namespace) in objects:
            id = obj.id
            idc = classize(id)
            idu = typesx.upper(id)
            self.write("""
    addFactory<%(namespace)s%(idc)sData>("%(id)s", %(namespace)s%(idu)s_NO);
""" % vars())  # "for xemacs syntax highlighting
        self.write("""}
""")  # "for xemacs syntax highlighting

        self.ns_close(self.base_list)
        self.out.close()
        self.update_outfile(outfile)
コード例 #2
0
    def instanceof_im(self, obj):
        classname_base = self.get_cpp_parent(obj)
        classname = self.classname
        serialno_name = typesx.upper(obj.id) + "_NO"
        self.write("""bool %(classname)s::instanceOf(int classNo) const
{
    if(%(serialno_name)s == classNo) return true;
    return %(classname_base)s::instanceOf(classNo);
}
""" % vars())  # "for xemacs syntax highlighting
コード例 #3
0
    def constructors_if(self, obj, static_attrs):
        self.doc(4, "Construct a " + self.classname + " class definition.")
        classname_base = self.get_cpp_parent(obj)
        classname = self.classname
        serialno_name = typesx.upper(obj.id) + "_NO"
        self.write("""    explicit %(classname)s(%(classname)s *defaults = nullptr) : 
        %(classname_base)s((%(classname_base)s*)defaults)
    {
        m_class_no = %(serialno_name)s;
    }
""" % vars())  # "for xemacs syntax highlighting
コード例 #4
0
    def getattrclass_im(self, obj, statics):
        classname = classize(obj.id, data=1)
        serialno_name = typesx.upper(obj.id) + "_NO"
        self.write("int %s::getAttrClass(const std::string& name) const\n"
                   % classname)
        self.write("{\n")
        # for attr in statics:
        #     self.write('    if (name == "%s")' % attr.name)
        #     self.write(' return %s;\n' % serialno_name)
        self.write("""    if (allocator.attr_flags_Data.find(name) != allocator.attr_flags_Data.end()) {
        return %s;
    }
""" % (serialno_name))
        parent = self.get_cpp_parent(obj)
        self.write("    return %s::getAttrClass(name);\n" % parent)
        self.write("}\n\n")
コード例 #5
0
    def instance_if(self, obj):
        self.smart_ptr_if("Instance")
        classname_base = self.classname
        classname = classname_base + "Instance"
        serialno_name = typesx.upper(obj.id) + "_INSTANCE_NO"
        global class_serial_no
        cs_no = class_serial_no
        self.write("""
const int %(serialno_name)s = %(cs_no)s;

class %(classname)s : public %(classname_base)s
{
public:
    %(classname)s(%(classname)s *defaults = nullptr) : 
        %(classname_base)s((%(classname_base)s*)defaults)
    {
        m_class_no = %(serialno_name)s;
    }
""" % vars())  # "for xemacs syntax highlighting
        class_serial_no = class_serial_no + 1
        self.freelist_if("Instance")
        self.write("};\n\n")
        self.free_im()
コード例 #6
0
    def interface(self, obj, static_attrs=[], default_attrs=[]):
        self.write("\n")
        self.write("/** " + obj.description + "\n")
        self.write("\n")
        self.write(obj.long_description + "\n\n")
        self.write("*/\n")
        self.smart_ptr_if()
        global class_serial_no
        self.write("static const int %s_NO = %i;\n\n" % (
            typesx.upper(obj.id), class_serial_no))
        class_serial_no = class_serial_no + 1
        self.write("/// \\brief " + obj.description + ".\n")
        if hasattr(obj, 'long_description'):
            self.write("///\n/** " + obj.long_description + "\n */\n")
        self.write("class " + self.classname)
        self.write(" : ")
        if obj.parent is None:
            self.write("public BaseObjectData")
        else:
            self.write("public %s" % classize(obj.parent, data=1))

        self.write("\n{\n")

        self.write("protected:\n")
        self.constructors_if(obj, static_attrs)
        self.doc(4, "Default destructor.")
        self.write("    ~" + self.classname + "() override = default;\n")
        self.write("\n")
        self.write("public:\n")
        if obj.parent:
            self.write("    // The parent type for this object's superclass\n")
            self.write("    static constexpr const char* super_parent = \"%s\";\n" % obj.parent.id)
        self.write("    // The default parent type for this object\n")
        self.write("    static constexpr const char* default_parent = \"%s\";\n" % obj.id)
        self.write("    // The default objtype for this object\n")
        if obj.objtype == 'op_definition':
            obj_type = 'op'
        else:
            obj_type = 'obj'
        self.write("    static constexpr const char* default_objtype = \"%s\";\n" % obj_type)
        if obj.id in ['anonymous', 'generic']:
            self.doc(4, 'Set the type of this object.')
            self.write("    void setType(const std::string &, int);\n\n")
        self.doc(4, 'Copy this object.')
        self.write("    %s * copy() const override;\n" % (self.classname))
        self.write("\n")
        self.doc(4, 'Is this instance of some class?')
        self.write("    bool instanceOf(int classNo) const override;\n")
        self.write("\n")

        if len(static_attrs) > 0:
            # generic access/etc.. methods
            # self.doc(4, 'Retrieve the attribute "name". Throws ' \
            #          + 'NoSuchAttrException if it does')
            # self.doc(4, 'not exist.')
            # self.write("    virtual const Atlas::Message::Element getAttr(")
            # self.write("const std::string& name)\n")
            self.doc(4, 'Retrieve the attribute "name". Return ' \
                     + 'non-zero if it does')
            self.doc(4, 'not exist.')
            self.write("    int copyAttr(")
            self.write("const std::string& name, ")
            self.write("Atlas::Message::Element & attr) const override;\n")
            self.doc(4, 'Set the attribute "name" to the value given by' \
                     + '"attr"')

            self.write("    void setAttr(std::string name,\n")
            self.write("                         ")
            self.write("Atlas::Message::Element attr, const Atlas::Objects::Factories* factories = nullptr) override;\n")
            self.doc(4, 'Remove the attribute "name". This will not work for ' \
                     + 'static attributes.')
            self.write("    void removeAttr(")
            self.write("const std::string& name) override;\n")
            self.write("\n")
            self.doc(4, 'Send the contents of this object to a Bridge.')
            self.write("    void sendContents(Atlas::Bridge & b) const override;\n")
            self.write("\n")
            # self.doc(4, 'Convert this object to a Element.')
            # self.write("    virtual const Atlas::Message::MapType asMessage() const;\n")
            # self.write("\n")
            self.doc(4, 'Write this object to an existing Element.')
            self.write("    void addToMessage(Atlas::Message::MapType &) const override;\n")
            self.write("\n")
            for attr in static_attrs:
                self.write(attr.set_if())
            self.write('\n')
            for attr in static_attrs:
                self.write(attr.get_if())
            self.write('\n')
            for attr in static_attrs:
                self.write(attr.is_default_if())
            self.write('\n')

            self.write("protected:\n")

            self.doc(4, 'Find the class which contains the attribute "name".')
            self.write("    int getAttrClass(const std::string& name)" \
                       + "const override;\n")

            self.doc(4, 'Find the flag for the attribute "name".')
            self.write("    bool getAttrFlag(const std::string& name, uint32_t& flag)" \
                       + "const override;\n")

            for attr in static_attrs:
                if attr.name in self.objects:
                    attr_object = self.objects[attr.name]
                    if hasattr(attr_object, 'description'):
                        self.doc(4, attr_object.description)
                self.write('    %s attr_%s;\n' %
                           (cpp_type[attr.type], attr.name))
            self.write('\n')
            for attr in static_attrs:
                self.doc(4, 'Send the "%s" attribute to an Atlas::Bridge.' %
                         (attr.name))
                self.write("    void send" + attr.cname)
                self.write('(Atlas::Bridge&) const;\n')

        self.freelist_if()
        self.write("};\n\n")

        # inst# self.instance_if(obj)

        if len(static_attrs) > 0:
            self.write('//\n// Attribute name strings follow.\n//\n\n')
            self.attribute_names_if(obj, static_attrs)
            self.write('//\n// Inlined member functions follow.\n//\n\n')
            self.static_inline_sets(obj, static_attrs)
            self.static_inline_gets(obj, static_attrs)
            self.static_inline_is_defaults(obj, static_attrs)
            # self.static_inline_sends(obj, static_attrs)
            self.write('\n')
コード例 #7
0
def capitalize_only(str):
    return typesx.upper(str[:1]) + str[1:]