Пример #1
0
 internal CppMap(JMap _enclosing, JType.CppType key, JType.CppType value)
     : base(_enclosing)
 {
     this._enclosing = _enclosing;
     this.key        = key;
     this.value      = value;
 }
Пример #2
0
 internal CppVector(JVector _enclosing, JType.CppType t)
     : base(_enclosing)
 {
     this._enclosing = _enclosing;
     this.element    = t;
 }
Пример #3
0
            /// <exception cref="System.IO.IOException"/>
            internal virtual void GenCode(FileWriter hh, FileWriter cc, AList <string> options
                                          )
            {
                CodeBuffer hb = new CodeBuffer();

                string[] ns = this.module.Split("::");
                for (int i = 0; i < ns.Length; i++)
                {
                    hb.Append("namespace " + ns[i] + " {\n");
                }
                hb.Append("class " + this.name + " : public ::hadoop::Record {\n");
                hb.Append("private:\n");
                for (IEnumerator <JField <JType.CppType> > i_1 = this.fields.GetEnumerator(); i_1.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_1.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    type.GenDecl(hb, name);
                }
                // type info vars
                hb.Append("static ::hadoop::RecordTypeInfo* p" + Consts.RtiVar + ";\n");
                hb.Append("static ::hadoop::RecordTypeInfo* p" + Consts.RtiFilter + ";\n");
                hb.Append("static int* p" + Consts.RtiFilterFields + ";\n");
                hb.Append("static ::hadoop::RecordTypeInfo* setupTypeInfo();\n");
                hb.Append("static void setupRtiFields();\n");
                hb.Append("virtual void deserializeWithoutFilter(::hadoop::IArchive& " + Consts.RecordInput
                          + ", const char* " + Consts.Tag + ");\n");
                hb.Append("public:\n");
                hb.Append("static const ::hadoop::RecordTypeInfo& getTypeInfo() " + "{return *p"
                          + Consts.RtiVar + ";}\n");
                hb.Append("static void setTypeFilter(const ::hadoop::RecordTypeInfo& rti);\n");
                hb.Append("static void setTypeFilter(const ::hadoop::RecordTypeInfo* prti);\n");
                hb.Append("virtual void serialize(::hadoop::OArchive& " + Consts.RecordOutput + ", const char* "
                          + Consts.Tag + ") const;\n");
                hb.Append("virtual void deserialize(::hadoop::IArchive& " + Consts.RecordInput +
                          ", const char* " + Consts.Tag + ");\n");
                hb.Append("virtual const ::std::string& type() const;\n");
                hb.Append("virtual const ::std::string& signature() const;\n");
                hb.Append("virtual bool operator<(const " + this.name + "& peer_) const;\n");
                hb.Append("virtual bool operator==(const " + this.name + "& peer_) const;\n");
                hb.Append("virtual ~" + this.name + "() {};\n");
                for (IEnumerator <JField <JType.CppType> > i_2 = this.fields.GetEnumerator(); i_2.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_2.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    type.GenGetSet(hb, name);
                }
                hb.Append("}; // end record " + this.name + "\n");
                for (int i_3 = ns.Length - 1; i_3 >= 0; i_3--)
                {
                    hb.Append("} // end namespace " + ns[i_3] + "\n");
                }
                hh.Write(hb.ToString());
                CodeBuffer cb = new CodeBuffer();

                // initialize type info vars
                cb.Append("::hadoop::RecordTypeInfo* " + this.fullName + "::p" + Consts.RtiVar +
                          " = " + this.fullName + "::setupTypeInfo();\n");
                cb.Append("::hadoop::RecordTypeInfo* " + this.fullName + "::p" + Consts.RtiFilter
                          + " = NULL;\n");
                cb.Append("int* " + this.fullName + "::p" + Consts.RtiFilterFields + " = NULL;\n\n"
                          );
                // setupTypeInfo()
                cb.Append("::hadoop::RecordTypeInfo* " + this.fullName + "::setupTypeInfo() {\n");
                cb.Append("::hadoop::RecordTypeInfo* p = new ::hadoop::RecordTypeInfo(\"" + this.
                          name + "\");\n");
                for (IEnumerator <JField <JType.CppType> > i_4 = this.fields.GetEnumerator(); i_4.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_4.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    type.GenStaticTypeInfo(cb, name);
                }
                cb.Append("return p;\n");
                cb.Append("}\n");
                // setTypeFilter()
                cb.Append("void " + this.fullName + "::setTypeFilter(const " + "::hadoop::RecordTypeInfo& rti) {\n"
                          );
                cb.Append("if (NULL != p" + Consts.RtiFilter + ") {\n");
                cb.Append("delete p" + Consts.RtiFilter + ";\n");
                cb.Append("}\n");
                cb.Append("p" + Consts.RtiFilter + " = new ::hadoop::RecordTypeInfo(rti);\n");
                cb.Append("if (NULL != p" + Consts.RtiFilterFields + ") {\n");
                cb.Append("delete p" + Consts.RtiFilterFields + ";\n");
                cb.Append("}\n");
                cb.Append("p" + Consts.RtiFilterFields + " = NULL;\n");
                // set RTIFilter for nested structs. We may end up with multiple lines that
                // do the same thing, if the same struct is nested in more than one field,
                // but that's OK.
                for (IEnumerator <JField <JType.CppType> > i_5 = this.fields.GetEnumerator(); i_5.HasNext
                         ();)
                {
                    JField <JType.CppType> jf   = i_5.Next();
                    JType.CppType          type = jf.GetType();
                    type.GenSetRTIFilter(cb);
                }
                cb.Append("}\n");
                // setTypeFilter()
                cb.Append("void " + this.fullName + "::setTypeFilter(const " + "::hadoop::RecordTypeInfo* prti) {\n"
                          );
                cb.Append("if (NULL != prti) {\n");
                cb.Append("setTypeFilter(*prti);\n");
                cb.Append("}\n");
                cb.Append("}\n");
                // setupRtiFields()
                this.GenSetupRTIFields(cb);
                // serialize()
                cb.Append("void " + this.fullName + "::serialize(::hadoop::OArchive& " + Consts.RecordOutput
                          + ", const char* " + Consts.Tag + ") const {\n");
                cb.Append(Consts.RecordOutput + ".startRecord(*this," + Consts.Tag + ");\n");
                for (IEnumerator <JField <JType.CppType> > i_6 = this.fields.GetEnumerator(); i_6.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_6.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    if (type is JBuffer.CppBuffer)
                    {
                        cb.Append(Consts.RecordOutput + ".serialize(" + name + "," + name + ".length(),\""
                                  + name + "\");\n");
                    }
                    else
                    {
                        cb.Append(Consts.RecordOutput + ".serialize(" + name + ",\"" + name + "\");\n");
                    }
                }
                cb.Append(Consts.RecordOutput + ".endRecord(*this," + Consts.Tag + ");\n");
                cb.Append("return;\n");
                cb.Append("}\n");
                // deserializeWithoutFilter()
                cb.Append("void " + this.fullName + "::deserializeWithoutFilter(::hadoop::IArchive& "
                          + Consts.RecordInput + ", const char* " + Consts.Tag + ") {\n");
                cb.Append(Consts.RecordInput + ".startRecord(*this," + Consts.Tag + ");\n");
                for (IEnumerator <JField <JType.CppType> > i_7 = this.fields.GetEnumerator(); i_7.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_7.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    if (type is JBuffer.CppBuffer)
                    {
                        cb.Append("{\nsize_t len=0; " + Consts.RecordInput + ".deserialize(" + name + ",len,\""
                                  + name + "\");\n}\n");
                    }
                    else
                    {
                        cb.Append(Consts.RecordInput + ".deserialize(" + name + ",\"" + name + "\");\n");
                    }
                }
                cb.Append(Consts.RecordInput + ".endRecord(*this," + Consts.Tag + ");\n");
                cb.Append("return;\n");
                cb.Append("}\n");
                // deserialize()
                cb.Append("void " + this.fullName + "::deserialize(::hadoop::IArchive& " + Consts
                          .RecordInput + ", const char* " + Consts.Tag + ") {\n");
                cb.Append("if (NULL == p" + Consts.RtiFilter + ") {\n");
                cb.Append("deserializeWithoutFilter(" + Consts.RecordInput + ", " + Consts.Tag +
                          ");\n");
                cb.Append("return;\n");
                cb.Append("}\n");
                cb.Append("// if we're here, we need to read based on version info\n");
                cb.Append(Consts.RecordInput + ".startRecord(*this," + Consts.Tag + ");\n");
                cb.Append("setupRtiFields();\n");
                cb.Append("for (unsigned int " + Consts.RioPrefix + "i=0; " + Consts.RioPrefix +
                          "i<p" + Consts.RtiFilter + "->getFieldTypeInfos().size(); " + Consts.RioPrefix +
                          "i++) {\n");
                int ct = 0;

                for (IEnumerator <JField <JType.CppType> > i_8 = this.fields.GetEnumerator(); i_8.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_8.Next();
                    string        name        = jf.GetName();
                    JType.CppType type        = jf.GetType();
                    ct++;
                    if (1 != ct)
                    {
                        cb.Append("else ");
                    }
                    cb.Append("if (" + ct + " == p" + Consts.RtiFilterFields + "[" + Consts.RioPrefix
                              + "i]) {\n");
                    if (type is JBuffer.CppBuffer)
                    {
                        cb.Append("{\nsize_t len=0; " + Consts.RecordInput + ".deserialize(" + name + ",len,\""
                                  + name + "\");\n}\n");
                    }
                    else
                    {
                        cb.Append(Consts.RecordInput + ".deserialize(" + name + ",\"" + name + "\");\n");
                    }
                    cb.Append("}\n");
                }
                if (0 != ct)
                {
                    cb.Append("else {\n");
                    cb.Append("const std::vector< ::hadoop::FieldTypeInfo* >& typeInfos = p" + Consts
                              .RtiFilter + "->getFieldTypeInfos();\n");
                    cb.Append("::hadoop::Utils::skip(" + Consts.RecordInput + ", typeInfos[" + Consts
                              .RioPrefix + "i]->getFieldID()->c_str()" + ", *(typeInfos[" + Consts.RioPrefix +
                              "i]->getTypeID()));\n");
                    cb.Append("}\n");
                }
                cb.Append("}\n");
                cb.Append(Consts.RecordInput + ".endRecord(*this, " + Consts.Tag + ");\n");
                cb.Append("}\n");
                // operator <
                cb.Append("bool " + this.fullName + "::operator< (const " + this.fullName + "& peer_) const {\n"
                          );
                cb.Append("return (1\n");
                for (IEnumerator <JField <JType.CppType> > i_9 = this.fields.GetEnumerator(); i_9.HasNext
                         ();)
                {
                    JField <JType.CppType> jf = i_9.Next();
                    string name = jf.GetName();
                    cb.Append("&& (" + name + " < peer_." + name + ")\n");
                }
                cb.Append(");\n");
                cb.Append("}\n");
                cb.Append("bool " + this.fullName + "::operator== (const " + this.fullName + "& peer_) const {\n"
                          );
                cb.Append("return (1\n");
                for (IEnumerator <JField <JType.CppType> > i_10 = this.fields.GetEnumerator(); i_10.
                     HasNext();)
                {
                    JField <JType.CppType> jf = i_10.Next();
                    string name = jf.GetName();
                    cb.Append("&& (" + name + " == peer_." + name + ")\n");
                }
                cb.Append(");\n");
                cb.Append("}\n");
                cb.Append("const ::std::string&" + this.fullName + "::type() const {\n");
                cb.Append("static const ::std::string type_(\"" + this.name + "\");\n");
                cb.Append("return type_;\n");
                cb.Append("}\n");
                cb.Append("const ::std::string&" + this.fullName + "::signature() const {\n");
                cb.Append("static const ::std::string sig_(\"" + this._enclosing.GetSignature() +
                          "\");\n");
                cb.Append("return sig_;\n");
                cb.Append("}\n");
                cc.Write(cb.ToString());
            }
Пример #4
0
 internal virtual void SetCppType(JType.CppType cppType)
 {
     this.cppType = cppType;
 }