/***************************************************************************** * * Copyright (c) 2000 - 2015, Lawrence Livermore National Security, LLC * Produced at the Lawrence Livermore National Laboratory * LLNL-CODE-442911 * All rights reserved. * * This file is part of VisIt. For details, see https://visit.llnl.gov/. The * full copyright notice is contained in the file COPYRIGHT located at the root * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the disclaimer below. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the disclaimer (as noted below) in the * documentation and/or other materials provided with the distribution. * - Neither the name of the LLNS/LLNL nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * *****************************************************************************/ #ifndef GENERATE_JAVA_H #define GENERATE_JAVA_H #include #include #include #include #include #include #include #include "Field.h" #define GENERATOR_NAME "xml2java" // **************************************************************************** // File: GenerateAtts // // Purpose: // Contains a set of classes which override the default implementation // to create an attribute subject. // // Note: This file overrides -- // FieldFactory // Field // Attribute // Enum // Plugin // // Programmer: Brad Whitlock // Creation: Thu Aug 8 17:55:57 PST 2002 // // Modifications: // Jeremy Meredith, Tue Aug 27 14:32:50 PDT 2002 // Added mfiles, dbtype, and libs. Allowed NULL atts. // // Jeremy Meredith, Thu Oct 17 15:58:29 PDT 2002 // Added some enhancements for the XML editor. // // Jeremy Meredith, Tue Sep 23 17:08:53 PDT 2003 // Made haswriter be a bool. // // Jeremy Meredith, Wed Nov 5 13:28:03 PST 2003 // Added ability to disable plugins by default. // // Brad Whitlock, Tue Jun 29 12:01:39 PDT 2004 // Improved how constants are written out. // // Jeremy Meredith, Wed Jul 7 17:08:03 PDT 2004 // Allow for mdserver-specific code in a plugin's source files. // // Jeremy Meredith, Mon Sep 6 16:29:41 PDT 2004 // Check if a value's initializer is set before trying to // write the initialization code. // // Brad Whitlock, Wed Dec 8 15:52:36 PST 2004 // Added support for variable names. // // Hank Childs, Tue May 24 10:19:40 PDT 2005 // Add hasoptions. // // Hank Childs, Fri Jun 9 09:46:13 PDT 2006 // Added copyright string. // // Cyrus Harrison, Wed Mar 7 09:49:20 PST 2007 // Allow for engine-specific code in a plugin's source files. // // Brad Whitlock, Wed Mar 14 17:50:07 PST 2007 // Change the names of the attVector access functions. // // Brad Whitlock, Mon Feb 25 14:04:48 PST 2008 // Added methods to create toString methods in Java. // // Brad Whitlock, Thu Feb 28 16:06:19 PST 2008 // Made use of base classes for easier maintenance. // // Jeremy Meredith, Thu Aug 7 14:34:01 EDT 2008 // Reorder constructor initializers to be the correct order. // // Brad Whitlock, Thu Aug 20 11:35:21 PDT 2009 // Added support for state object inheritance. // // Brad Whitlock, Thu Feb 2 11:55:54 PST 2012 // Add support for MapNode. // // **************************************************************************** class JavaGeneratorField : public virtual Field { protected: QString generatorName; public: bool generatePlugin; bool custombase; JavaGeneratorField(const QString &t, const QString &n, const QString &l) : Field(t,n,l), generatorName(GENERATOR_NAME) { generatePlugin = false; custombase = false; } QString GetCPPNameW(int w, bool subtypename=false, const QString &classname="") { QString s = GetCPPName(subtypename,classname); for (size_t i = w - s.length(); i > 0; --i) s += " "; return s; } QString OffsetPlus(const QString &classname) const { return custombase ? (QString("(new ") + classname + QString("()).Offset() + ")) : QString(); } virtual void WriteSourceWriteAtts(QTextStream &h, const QString &indent) = 0; virtual bool WriteSourceReadAtts(QTextStream &h, const QString &indent) = 0; virtual void WriteSourceSetDefault(QTextStream &c) = 0; virtual void AddImports(UniqueStringList &sl) { } virtual void WriteSourceAttribute(QTextStream &h, int w) { h << " private " << GetCPPNameW(w) << " " << name << ";" << endl; } // ------------------------------------------------------------------------ virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname) { } virtual void WriteSourceSetFunction(QTextStream &c, const QString &classname) { // Write prototype. c << " public void Set" << Name << "("; c << GetCPPName(true,classname) << " "; c << name << "_)" << endl; c << " {" << endl; if (!isArray) { c << " " << name << " = " << name << "_;" << endl; c << " Select(" << OffsetPlus(classname) << index << ");" << endl; } else { if (length < 5) { for(int i = 0; i < length; ++i) c << " " << name << "[" << i << "] = " << name << "_[" << i << "];"<< endl; } else { c << " for(int i = 0; i < " << length << "; ++i)" << endl; c << " " << name << "[i] = " << name << "_[i];"<< endl; } c << " Select(" << OffsetPlus(classname) << index << ");" << endl; } c << " }" << endl; c << endl; // If it is an array with a size less than 6, write another set method. WriteAuxiliarySetFunction(c, classname); } virtual void WriteSourceGetFunction(QTextStream &c, int w) { c << " public " << GetCPPNameW(w) << " Get" << Name << "() { return " << name << "; }" << endl; } virtual void WriteSourceAGVectorFunctions(QTextStream &c, const QString &classname) { } virtual void WriteSourceCopyCode(QTextStream &c) { c << " " << name << " = obj." << name << ";" << endl; } virtual void WriteSourceComparisonPrecalc(QTextStream &c) { if (isArray) { c << " // Compare the " << name << " arrays." << endl; c << " boolean " << name << "_equal = true;" << endl; c << " for(i = 0; i < " << length << " && " << name << "_equal; ++i)" << endl; c << " " << name << "_equal = (" << name << "[i] == obj." << name << "[i]);" << endl << endl; } else if (isVector) { c << " // Compare the elements in the " << name << " vector." << endl; c << " boolean " << name << "_equal = (obj." << name << ".size() == " << name << ".size());" << endl; c << " for(i = 0; (i < " << name << ".size()) && " << name << "_equal; ++i)" << endl; c << " {" << endl; c << " // Make references to " << GetVectorStorageName() << " from Object." << endl; c << " " << GetVectorStorageName() << " " << name << "1 = (" << GetVectorStorageName() << ")" << name << ".elementAt(i);" << endl; c << " " << GetVectorStorageName() << " " << name << "2 = (" << GetVectorStorageName() << ")obj." << name << ".elementAt(i);" << endl; c << " " << name << "_equal = " << name << "1.equals(" << name << "2);" << endl; c << " }" << endl; } } virtual QString GetVectorStorageName() const { return ""; } virtual void WriteSourceComparison(QTextStream &c) { if (isArray || isVector) c << name << "_equal"; else { c << "(" << name << " == obj." << name << ")"; } } virtual void WriteToString(QTextStream &c, const QString &indent) { } }; // // ------------------------------------ Int ----------------------------------- // class JavaGeneratorInt : public virtual Int , public virtual JavaGeneratorField { public: JavaGeneratorInt(const QString &n, const QString &l) : Field("int",n,l), Int(n,l), JavaGeneratorField("int",n,l) { } virtual void WriteSourceSetDefault(QTextStream &c) { if(valueSet) c << " " << name << " = " << val << ";" << endl; else c << " " << name << " = 0;" << endl; } virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent) { c << indent << " buf.WriteInt(" << name << ");" << endl; } virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent) { c << indent << "Set" << Name << "(buf.ReadInt());" << endl; return true; } virtual void WriteToString(QTextStream &c, const QString &indent) { c << indent << "str = str + intToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl; } }; // // -------------------------------- IntArray -------------------------------- // class JavaGeneratorIntArray : public virtual IntArray , public virtual JavaGeneratorField { public: JavaGeneratorIntArray(const QString &s, const QString &n, const QString &l) : Field("intArray",n,l), IntArray(s,n,l), JavaGeneratorField("intArray",n,l) { } virtual QString GetCPPName(bool, const QString &) { return "int[]"; } virtual void WriteSourceSetDefault(QTextStream &c) { c << " " << name << " = new int[" << length << "];" << endl; if(valueSet) { for (int i = 0; i < length; ++i) c << " " << name << "["<= 0 && index < " << name << ".size())" << endl; c << " {" << endl; c << " " << name << ".remove(index);" << endl; c << " Select(" << OffsetPlus(classname) << index << ");" << endl; c << " }" << endl; c << " }" << endl << endl; // Write the GetNum method c << " public int GetNum" << Name << plural << "()" << endl; c << " {" << endl; c << " return " << name << ".size();" << endl; c << " }" << endl << endl; // Write the Get method c << " public " << s << " Get" << Name << "(int i)" << endl; c << " {" << endl; c << " " << s << " tmp = (" << s << ")" << name << ".elementAt(i);" << endl; c << " return tmp;" << endl; c << " }" << endl << endl; } virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent) { c << indent << "{" << endl; c << indent << " buf.WriteInt(" << name << ".size());" << endl; c << indent << " for(int i = 0; i < " << name << ".size(); ++i)" << endl; c << indent << " {" << endl; c << indent << " " << attType << " tmp = (" << attType << ")" << name << ".elementAt(i);" << endl; c << indent << " tmp.Write(buf);" << endl; c << indent << " }" << endl; c << indent << "}" << endl; } virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent) { c << indent << "{" << endl; c << indent << " int len = buf.ReadInt();" << endl; c << indent << " " << name << ".clear();" << endl; c << indent << " for(int j = 0; j < len; ++j)" << endl; c << indent << " {" << endl; c << indent << " " << attType << " tmp = new " << attType << "();" << endl; c << indent << " tmp.Read(buf);" << endl; c << indent << " " << name << ".addElement(tmp);" << endl; c << indent << " }" << endl; c << indent << "}" << endl; return false; } virtual void WriteToString(QTextStream &c, const QString &indent) { c << indent << "str = str + indent + \""<type + QString("_") + enumType->values[val]); c << " " << name << " = " << constName.toUpper() << ";" << endl; } } virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent) { c << indent << " buf.WriteInt(" << name << ");" << endl; } virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent) { c << indent << "Set" << Name << "(buf.ReadInt());" << endl; return true; } virtual void WriteToString(QTextStream &c, const QString &indent) { c << indent << "str = str + indent + \"" << name <<" = \";" << endl; for(size_t i = 0; i < enumType->values.size(); ++i) { QString constName(enumType->type + QString("_") + enumType->values[i]); c << indent << "if(" << name << " == " << constName.toUpper() << ")" << endl; c << indent << " str = str + \"" << constName.toUpper() << "\";" << endl; } c << indent << "str = str + \"\\n\";" << endl; } }; // // --------------------------------- ScaleMode -------------------------------- // class JavaGeneratorScaleMode : public virtual ScaleMode , public virtual JavaGeneratorField { public: JavaGeneratorScaleMode(const QString &n, const QString &l) : Field("scalemode",n,l), ScaleMode(n,l), JavaGeneratorField("scalemode",n,l) { } virtual void WriteSourceSetDefault(QTextStream &c) { c << " " << name << " = " << val << ";" << endl; } virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent) { c << indent << " buf.WriteInt(" << name << ");" << endl; } virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent) { c << indent << "Set" << Name << "(buf.ReadInt());" << endl; return true; } virtual void WriteToString(QTextStream &c, const QString &indent) { c << indent << "str = str + intToString(\"" << name << "\", " << name << ", indent);" << endl; } }; // ---------------------------------------------------------------------------- // Modifications: // Brad Whitlock, Wed Dec 8 15:52:11 PST 2004 // Added support for variable names. // // Kathleen Bonnell, Thu Mar 22 16:58:23 PDT 2007 // Added scalemode. // // Brad Whitlock, Thu Feb 2 12:09:43 PST 2012 // Added MapNode. // ---------------------------------------------------------------------------- class JavaFieldFactory { public: static JavaGeneratorField *createField(const QString &name, const QString &type, const QString &subtype, const QString &length, const QString &label) { JavaGeneratorField *f = NULL; if (type.isNull()) throw QString("Field %1 was specified with no type.").arg(name); else if (type == "int") f = new JavaGeneratorInt(name,label); else if (type == "intArray") f = new JavaGeneratorIntArray(length,name,label); else if (type == "intVector") f = new JavaGeneratorIntVector(name,label); else if (type == "bool") f = new JavaGeneratorBool(name,label); else if (type == "float") f = new JavaGeneratorFloat(name,label); else if (type == "floatArray") f = new JavaGeneratorFloatArray(length,name,label); else if (type == "floatVector") f = new JavaGeneratorFloatVector(name,label); else if (type == "double") f = new JavaGeneratorDouble(name,label); else if (type == "doubleArray") f = new JavaGeneratorDoubleArray(length,name,label); else if (type == "doubleVector") f = new JavaGeneratorDoubleVector(name,label); else if (type == "uchar") f = new JavaGeneratorUChar(name,label); else if (type == "ucharArray") f = new JavaGeneratorUCharArray(length,name,label); else if (type == "ucharVector") f = new JavaGeneratorUCharVector(name,label); else if (type == "string") f = new JavaGeneratorString(name,label); else if (type == "stringVector") f = new JavaGeneratorStringVector(name,label); else if (type == "colortable") f = new JavaGeneratorColorTable(name,label); else if (type == "color") f = new JavaGeneratorColor(name,label); else if (type == "opacity") f = new JavaGeneratorOpacity(name,label); else if (type == "linestyle") f = new JavaGeneratorLineStyle(name,label); else if (type == "linewidth") f = new JavaGeneratorLineWidth(name,label); else if (type == "variablename") f = new JavaGeneratorVariableName(name,label); else if (type == "att") f = new JavaGeneratorAtt(subtype,name,label); else if (type == "attVector") f = new JavaGeneratorAttVector(subtype,name,label); else if (type == "enum") f = new JavaGeneratorEnum(subtype, name, label); else if (type == "scalemode") f = new JavaGeneratorScaleMode(name,label); else if (type == "MapNode") f = new JavaGeneratorMapNode(name,label); // Special built-in AVT enums -- but they don't really need to be treated like enums for this program. else if (type == "avtCentering") f = new JavaGeneratorInt(name, label); else if (type == "avtVarType") f = new JavaGeneratorInt(name, label); else if (type == "avtSubsetType") f = new JavaGeneratorInt(name, label); else if (type == "avtExtentType") f = new JavaGeneratorInt(name, label); else if (type == "avtMeshType") f = new JavaGeneratorInt(name, label); else if (type == "avtGhostType") f = new JavaGeneratorInt(name, label); else if (type == "avtMeshCoordType") f = new JavaGeneratorInt(name, label); else if (type == "LoadBalanceScheme") f = new JavaGeneratorInt(name, label); if (!f) throw QString("JavaFieldFactory: unknown type for field %1: %2").arg(name).arg(type); return f; } }; // ---------------------------------------------------------------------------- // Modifications: // Brad Whitlock, Thu Feb 28 16:29:20 PST 2008 // Made it use a base class. // // Brad Whitlock, Thu Aug 20 12:22:36 PDT 2009 // Added support for state object inheritance. // // ---------------------------------------------------------------------------- #include class JavaGeneratorAttribute : public GeneratorBase { public: std::vector fields; QString pluginVersion; QString pluginName; QString pluginType; public: JavaGeneratorAttribute(const QString &n, const QString &p, const QString &f, const QString &e, const QString &ei, const QString &bc) : GeneratorBase(n,p,f,e,ei, GENERATOR_NAME, bc), fields(), pluginVersion("1.0"), pluginName(), pluginType() { } virtual ~JavaGeneratorAttribute() { for (size_t i = 0; i < fields.size(); ++i) delete fields[i]; fields.clear(); } void Print(QTextStream &out) const { out << " Attribute: " << name << " (" << purpose << ")" << endl; out << " exportAPI=" << exportAPI << endl; out << " exportInclude=" << exportInclude << endl; size_t i; for (i = 0; i < fields.size(); ++i) fields[i]->Print(out); for (i=0; iPrint(out, generatorName); for (i=0; iPrint(out, generatorName); for (i=0; iPrint(out, generatorName); } // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ void WriteSource(QTextStream &h) { bool generatePlugin = (pluginType == "plot" || pluginType == "operator"); h << java_copyright_str << endl; if(pluginType == "plot") h << "package llnl.visit.plots;" << endl; else if(pluginType == "operator") h << "package llnl.visit.operators;" << endl; else h << "package llnl.visit;" << endl; h << endl; // Give a little information to the fields. size_t i; for (i = 0; i < fields.size(); ++i) { fields[i]->generatePlugin = generatePlugin; fields[i]->custombase = custombase; } // // Write the list of imported classes // WriteSourceImports(h); // // Write the class header comment // WriteClassComment(h, purpose); if(generatePlugin) h << "public class " << name << " extends " << baseClass <<" implements Plugin" << endl; else h << "public class " << name << " extends " << baseClass << endl; h << "{" << endl; // // Write the source code representation of any enums that have been specified. // WriteSourceEnumsAndConstants(h); // // Write the no argument constructor. // WriteSourceConstructor(h); // // Write the constructor that classes can use to inherit from this class. // WriteSourceIntConstructor(h); // // Write the copy constructor. // WriteSourceCopyConstructor(h); // // Write offset related methods. // WriteOffsetRelated(h); // // Write the comparison method. // WriteSourceComparison(h); // // Write Plugin interface methods. // if(generatePlugin) { h << " public String GetName() { return \"" << pluginName << "\"; }" << endl; h << " public String GetVersion() { return \"" << pluginVersion << "\"; }" << endl; h << endl; } // // Write out all the set prototypes // h << " // Property setting methods" << endl; for (i = 0; i < fields.size(); ++i) fields[i]->WriteSourceSetFunction(h, name); // // Write out all the get prototypes // int totalWidth = CalculateTotalWidth(); h << " // Property getting methods" << endl; for (i = 0; i < fields.size(); ++i) { fields[i]->WriteSourceGetFunction(h, totalWidth); } h << endl; // // Write the WriteAtts method. // WriteSourceWriteAtts(h); // // Write the ReadAtts method // WriteSourceReadAtts(h); // // Write the toString method // WriteToString(h); // // Write out AttributeGroupVector convenience methods. // WriteSourceAGVectorFunctions(h, name); // // Write user-defined functions // WriteUserDefinedFunctions(h); // // Write out all the private attributes // h << " // Attributes" << endl; for (i = 0; i < fields.size(); ++i) { fields[i]->WriteSourceAttribute(h, totalWidth); } h << "}" << endl; h << endl; } private: void WriteSourceImports(QTextStream &h) { UniqueStringList sysincludes; if(pluginType == "plot" || pluginType == "operator") { sysincludes.AddString(QString("import llnl.visit.") + (baseClass + ";\n")); sysincludes.AddString("import llnl.visit.CommunicationBuffer;\n"); sysincludes.AddString("import llnl.visit.Plugin;\n"); } for (size_t i = 0; i < fields.size(); ++i) fields[i]->AddImports(sysincludes); // Add some includes based on the includes from the XML file for(size_t i = 0; i < includes.size(); ++i) { if(includes[i]->target == generatorName) { QString importLine(QString("import %1;\n").arg(includes[i]->include)); sysincludes.AddString(importLine); } } sysincludes.Write(h); h << endl; } int CalculateTotalWidth() { int retval = 0; // Iterate through the list of attibutes and find the one with // the longest name. for (size_t i = 0; i < fields.size(); ++i) { int len = fields[i]->GetCPPName().length(); if (len > retval) retval = len; } return retval; } bool HaveAGVectors() { for (size_t i = 0; i < fields.size(); ++i) if (fields[i]->type=="attVector") return true; return false; } bool HaveArrays() { for (size_t i = 0; i < fields.size(); ++i) if (fields[i]->isArray) return true; return false; } bool HaveVectors() { for (size_t i = 0; i < fields.size(); ++i) if (fields[i]->isVector) return true; return false; } // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ void WriteSourceConstructor(QTextStream &c) { c << " public " << name << "()" << endl; c << " {" << endl; c << " super("<< name<<"_numAdditionalAtts);" << endl; c << endl; if(HasCode(name, 0)) PrintCode(c, name, 0); size_t i; for (i = 0; i < fields.size(); ++i) { c << " "; if(!fields[i]->PrintInit(c, generatorName)) fields[i]->WriteSourceSetDefault(c); } if(HasCode(name, 1)) PrintCode(c, name, 1); c << " }" << endl << endl; } void WriteSourceIntConstructor(QTextStream &c) { c << " public " << name << "(int nMoreFields)" << endl; c << " {" << endl; c << " super(" << name << "_numAdditionalAtts + nMoreFields);" << endl; c << endl; if(HasCode(name, 0)) PrintCode(c, name, 0); size_t i; for (i = 0; i < fields.size(); ++i) { c << " "; if(!fields[i]->PrintInit(c, generatorName)) fields[i]->WriteSourceSetDefault(c); } if(HasCode(name, 1)) PrintCode(c, name, 1); c << " }" << endl << endl; } void WriteSourceCopyConstructor(QTextStream &c) { c << " public " << name << "(" << name << " obj)" << endl; c << " {" << endl; c << " super(" << name << "_numAdditionalAtts);" << endl; c << endl; bool skipLine = false; if (HaveArrays() || HaveVectors()) { c << " int i;" << endl; skipLine = true; } if(skipLine) c << endl; for (size_t i = 0; i < fields.size(); ++i) { fields[i]->WriteSourceCopyCode(c); } c << endl << " SelectAll();" << endl; c << " }" << endl << endl; } void WriteOffsetRelated(QTextStream &c) { c << " public int Offset()" << endl; c << " {" << endl; c << " return super.Offset() + super.GetNumAdditionalAttributes();" << endl; c << " }" << endl; c << endl; c << " public int GetNumAdditionalAttributes()" << endl; c << " {" << endl; c << " return " << name << "_numAdditionalAtts;" << endl; c << " }" << endl; c << endl; } void WriteSourceComparison(QTextStream &c) { if(HasFunction("equals")) { PrintFunction(c, "equals"); c << endl; return; } c << " public boolean equals(" << name << " obj)" << endl; c << " {" << endl; if(HaveArrays() || HaveVectors()) { c << " int i;" << endl << endl; } // Create bool values to evaluate the arrays. QString prevValue("true"); for (size_t i = 0; i < fields.size(); ++i) { if (!fields[i]->ignoreEquality) fields[i]->WriteSourceComparisonPrecalc(c); } c << " // Create the return value" << endl; c << " return ("; if(custombase) c << "super.equals(obj) && "; // Create a big boolean return statement. if (fields.size() == 0) { c << "true"; } else { for (size_t i = 0; i < fields.size(); ++i) { if (i > 0) c << " "; if (!fields[i]->ignoreEquality) fields[i]->WriteSourceComparison(c); else c << "true /* can ignore " << fields[i]->name << " */"; if (i < fields.size() - 1) c << " &&" << endl; } } c << ");" << endl; c << " }" << endl << endl; } void WriteSourceEnumsAndConstants(QTextStream &h) { h << " private static int " << name << "_numAdditionalAtts = " << fields.size() << ";" << endl << endl; // Write the enums out as groups of static int constants. if(EnumType::enums.size() > 0) h << " // Enum values" << endl; size_t i; for (i = 0; i < EnumType::enums.size(); ++i) { for (size_t j = 0; j < EnumType::enums[i]->values.size(); ++j) { QString constName(EnumType::enums[i]->type + QString("_") + EnumType::enums[i]->values[j]); h << " public final static int " << constName.toUpper() << " = " << j << ";" << endl; } h << endl; } // // Write any constants that have been specified. // bool haveConstants = false; for (i = 0; i < constants.size(); ++i) { if(constants[i]->target == generatorName) haveConstants = true; } if(haveConstants) h << " // Constants" << endl; for (i = 0; i < constants.size(); ++i) { if(constants[i]->target != generatorName) continue; QString def(constants[i]->def); if (def.simplified().isEmpty()) continue; h << def << endl; } if (EnumType::enums.size() || constants.size()) h << endl; } void WriteSourceWriteAtts(QTextStream &h) { h << " // Write and read methods." << endl; if(HasFunction("WriteAtts")) { PrintFunction(h, "WriteAtts"); h << endl; return; } h << " public void WriteAtts(CommunicationBuffer buf)" << endl; h << " {" << endl; QString oplus; if(custombase) { h << " super.WriteAtts(buf);" << endl; h << endl; h << " int offset = (new " << name << "()).Offset();" << endl; oplus = "offset + "; } for (size_t i = 0; i < fields.size(); ++i) { h << " if(WriteSelect(" << oplus << i << ", buf))" << endl; fields[i]->WriteSourceWriteAtts(h, " "); } h << " }" << endl; h << endl; } void WriteSourceReadAtts(QTextStream &h) { if(HasFunction("ReadAtts")) { PrintFunction(h, "ReadAtts"); h << endl; return; } if(custombase) { h << " public void ReadAtts(int id, CommunicationBuffer buf)" << endl; h << " {" << endl; h << " int offset = (new " << name << "()).Offset();" << endl; if(fields.size() > 1) { h << " int index = id - offset;" << endl; h << " switch(index)" << endl; h << " {" << endl; for (size_t i = 0; i < fields.size(); ++i) { h << " case " << i << ":" << endl; if(!fields[i]->WriteSourceReadAtts(h, " ")) h << " Select(offset + " << i << ");" << endl; h << " break;" << endl; } h << " default:" << endl; h << " super.ReadAtts(id, buf);" << endl; h << " break;" << endl; h << " }" << endl; } else if(fields.size() == 1) { h << " if(id == offset)" << endl; if(!fields[0]->WriteSourceReadAtts(h, " ")) h << " Select(offset + 0);" << endl; h << " else" << endl; h << " super.ReadAtts(id, buf);" << endl; } } else { h << " public void ReadAtts(int index, CommunicationBuffer buf)" << endl; h << " {" << endl; if(fields.size() > 1) { h << " switch(index)" << endl; h << " {" << endl; for (size_t i = 0; i < fields.size(); ++i) { h << " case " << i << ":" << endl; if(!fields[i]->WriteSourceReadAtts(h, " ")) h << " Select(" << i << ");" << endl; h << " break;" << endl; } h << " }" << endl; } else if(fields.size() == 1) { if(!fields[0]->WriteSourceReadAtts(h, " ")) h << " Select(0);" << endl; } } h << " }" << endl; h << endl; } void WriteSourceAGVectorFunctions(QTextStream &h, const QString &classname) { if (HaveAGVectors()) { h << " // Attributegroup convenience methods" << endl; for (size_t i = 0; i < fields.size(); ++i) fields[i]->WriteSourceAGVectorFunctions(h, classname); } h << endl; } void WriteToString(QTextStream &h) { h << " public String toString(String indent)" << endl; h << " {" << endl; if(HasCode("toString", 0)) PrintCode(h, "toString", 0); h << " String str = new String();" << endl; for (size_t i = 0; i < fields.size(); ++i) { fields[i]->WriteToString(h, " "); } if(HasCode("toString", 1)) PrintCode(h, "toString", 1); if(custombase) h << " return super.toString(indent) + str;" << endl; else h << " return str;" << endl; h << " }" << endl; h << endl; // h << " public String toString()" << endl; // h << " {" << endl; // h << " return toString(new String());" << endl; // h << " }" << endl; // h << endl; } void WriteUserDefinedFunctions(QTextStream &h) { for (size_t i=0; itarget == generatorName) { h << functions[i]->def << endl; } } }; // ---------------------------------------------------------------------------- // Modifications: // // Hank Childs, Thu Jan 10 14:33:30 PST 2008 // Added filenames, specifiedFilenames. // // Brad Whitlock, Thu Feb 28 16:26:46 PST 2008 // Made it use a base class. // // ---------------------------------------------------------------------------- #include class JavaGeneratorPlugin : public PluginBase { public: JavaGeneratorAttribute *atts; public: JavaGeneratorPlugin(const QString &n,const QString &l,const QString &t, const QString &vt,const QString &dt, const QString &v, const QString &ifile, bool hw, bool ho, bool onlyengine, bool noengine) : PluginBase(n,l,t,vt,dt,v,ifile,hw,ho,onlyengine,noengine), atts(NULL) { } void Print(QTextStream &out) { out << "Plugin: "<Print(out); } }; // ---------------------------------------------------------------------------- // Override default types // ---------------------------------------------------------------------------- #define FieldFactory JavaFieldFactory #define Field JavaGeneratorField #define Attribute JavaGeneratorAttribute #define Enum JavaGeneratorEnum #define Plugin JavaGeneratorPlugin #endif