GenerateJava.h 78.9 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
bonnell's avatar
bonnell committed
3
* Copyright (c) 2000 - 2015, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
brugger's avatar
 
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* 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
brugger's avatar
 
brugger committed
19 20 21
*    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
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    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
brugger's avatar
 
brugger committed
27 28 29
* 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
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37 38
* 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.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39 40
#ifndef GENERATE_JAVA_H
#define GENERATE_JAVA_H
whitlocb's avatar
whitlocb committed
41
#include <QTextStream>
hrchilds's avatar
hrchilds committed
42 43 44 45 46 47 48 49 50

#include <vector>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include "Field.h"

whitlocb's avatar
whitlocb committed
51 52
#define GENERATOR_NAME "xml2java"

hrchilds's avatar
hrchilds committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
// ****************************************************************************
//  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.
//
hrchilds's avatar
hrchilds committed
77 78 79
//    Jeremy Meredith, Tue Sep 23 17:08:53 PDT 2003
//    Made haswriter be a bool.
//
hrchilds's avatar
hrchilds committed
80 81 82
//    Jeremy Meredith, Wed Nov  5 13:28:03 PST 2003
//    Added ability to disable plugins by default.
//
hrchilds's avatar
hrchilds committed
83 84 85
//    Brad Whitlock, Tue Jun 29 12:01:39 PDT 2004
//    Improved how constants are written out.
//
hrchilds's avatar
hrchilds committed
86 87 88
//    Jeremy Meredith, Wed Jul  7 17:08:03 PDT 2004
//    Allow for mdserver-specific code in a plugin's source files.
//
hrchilds's avatar
hrchilds committed
89 90 91 92
//    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.
//
hrchilds's avatar
hrchilds committed
93 94 95
//    Brad Whitlock, Wed Dec 8 15:52:36 PST 2004
//    Added support for variable names.
//
hrchilds's avatar
hrchilds committed
96 97 98
//    Hank Childs, Tue May 24 10:19:40 PDT 2005
//    Add hasoptions.
//
hrchilds's avatar
hrchilds committed
99 100 101
//    Hank Childs, Fri Jun  9 09:46:13 PDT 2006
//    Added copyright string.
//
hrchilds's avatar
hrchilds committed
102 103 104
//    Cyrus Harrison, Wed Mar  7 09:49:20 PST 2007
//    Allow for engine-specific code in a plugin's source files.
//
hrchilds's avatar
hrchilds committed
105 106 107
//    Brad Whitlock, Wed Mar 14 17:50:07 PST 2007
//    Change the names of the attVector access functions.
//
108 109 110
//    Brad Whitlock, Mon Feb 25 14:04:48 PST 2008
//    Added methods to create toString methods in Java.
//
whitlocb's avatar
whitlocb committed
111 112 113
//    Brad Whitlock, Thu Feb 28 16:06:19 PST 2008
//    Made use of base classes for easier maintenance.
//
114 115 116
//    Jeremy Meredith, Thu Aug  7 14:34:01 EDT 2008
//    Reorder constructor initializers to be the correct order.
//
117 118 119
//    Brad Whitlock, Thu Aug 20 11:35:21 PDT 2009
//    Added support for state object inheritance.
//
120 121 122
//    Brad Whitlock, Thu Feb  2 11:55:54 PST 2012
//    Add support for MapNode.
//
hrchilds's avatar
hrchilds committed
123 124
// ****************************************************************************

whitlocb's avatar
whitlocb committed
125
class JavaGeneratorField : public virtual Field
hrchilds's avatar
hrchilds committed
126
{
whitlocb's avatar
whitlocb committed
127 128
  protected:
    QString generatorName;
hrchilds's avatar
hrchilds committed
129 130
  public:
    bool generatePlugin;
131
    bool custombase;
hrchilds's avatar
hrchilds committed
132

whitlocb's avatar
whitlocb committed
133 134
    JavaGeneratorField(const QString &t, const QString &n, const QString &l)
        : Field(t,n,l), generatorName(GENERATOR_NAME)
hrchilds's avatar
hrchilds committed
135 136
    {
        generatePlugin = false;
137
        custombase = false;
hrchilds's avatar
hrchilds committed
138 139 140 141 142
    }

    QString GetCPPNameW(int w, bool subtypename=false, const QString &classname="")
    {
        QString s = GetCPPName(subtypename,classname);
143
        for (size_t i = w - s.length(); i > 0; --i)
hrchilds's avatar
hrchilds committed
144 145 146 147
            s += " ";
        return s;
    }

148
    QString OffsetPlus(const QString &classname) const
149
    {
150
        return custombase ? (QString("(new ") + classname + QString("()).Offset() + ")) : QString();
151 152
    }

whitlocb's avatar
whitlocb committed
153 154 155
    virtual void WriteSourceWriteAtts(QTextStream &h, const QString &indent) = 0;
    virtual bool WriteSourceReadAtts(QTextStream &h, const QString &indent) = 0;
    virtual void WriteSourceSetDefault(QTextStream &c) = 0;
hrchilds's avatar
hrchilds committed
156 157 158

    virtual void AddImports(UniqueStringList &sl) { }

whitlocb's avatar
whitlocb committed
159
    virtual void WriteSourceAttribute(QTextStream &h, int w)
hrchilds's avatar
hrchilds committed
160 161 162 163 164 165
    {
        h << "    private " << GetCPPNameW(w) << " " << name << ";" << endl;
    }

    // ------------------------------------------------------------------------

166
    virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
167 168 169
    {
    }

whitlocb's avatar
whitlocb committed
170
    virtual void WriteSourceSetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
171 172 173 174 175 176 177 178 179
    {
        // Write prototype.
        c << "    public void Set" << Name << "(";
        c << GetCPPName(true,classname) << " ";
        c << name << "_)" << endl;
        c << "    {" << endl;
        if (!isArray)
        {
            c << "        " << name << " = " << name << "_;" << endl;
180
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
181 182 183 184 185 186 187 188 189 190 191 192 193
        }
        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;
            }
194
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
195 196 197 198 199
        }
        c << "    }" << endl;
        c << endl;

        // If it is an array with a size less than 6, write another set method.
200
        WriteAuxiliarySetFunction(c, classname);
hrchilds's avatar
hrchilds committed
201 202
    }

whitlocb's avatar
whitlocb committed
203
    virtual void WriteSourceGetFunction(QTextStream &c, int w)
hrchilds's avatar
hrchilds committed
204 205 206 207 208
    {
        c << "    public " << GetCPPNameW(w) << " Get" << Name << "() { return "
          << name << "; }" << endl;
    }

209
    virtual void WriteSourceAGVectorFunctions(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
210 211 212 213
    {
    }


whitlocb's avatar
whitlocb committed
214
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
215 216 217 218
    {
        c << "        " << name << " = obj." << name << ";" << endl;
    }

whitlocb's avatar
whitlocb committed
219
    virtual void WriteSourceComparisonPrecalc(QTextStream &c)
hrchilds's avatar
hrchilds committed
220 221 222 223 224 225 226 227 228 229 230
    {
        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;
        }
whitlocb's avatar
whitlocb committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
        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 "";
hrchilds's avatar
hrchilds committed
249 250
    }

whitlocb's avatar
whitlocb committed
251
    virtual void WriteSourceComparison(QTextStream &c)
hrchilds's avatar
hrchilds committed
252
    {
whitlocb's avatar
whitlocb committed
253
        if (isArray || isVector)
hrchilds's avatar
hrchilds committed
254 255 256 257 258 259
            c << name << "_equal";
        else
        {
            c << "(" << name << " == obj." << name << ")";
        }
    }
260

whitlocb's avatar
whitlocb committed
261
    virtual void WriteToString(QTextStream &c, const QString &indent)
262 263
    {
    }
hrchilds's avatar
hrchilds committed
264 265 266 267 268
};

//
// ------------------------------------ Int -----------------------------------
//
whitlocb's avatar
whitlocb committed
269
class JavaGeneratorInt : public virtual Int , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
270 271
{
  public:
whitlocb's avatar
whitlocb committed
272
    JavaGeneratorInt(const QString &n, const QString &l)
273
        : Field("int",n,l), Int(n,l), JavaGeneratorField("int",n,l) { }
hrchilds's avatar
hrchilds committed
274

whitlocb's avatar
whitlocb committed
275
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
276 277 278 279 280 281 282
    {
        if(valueSet)
            c << "    " << name << " = " << val << ";" << endl;
        else
            c << "    " << name << " = 0;" << endl;
    }

whitlocb's avatar
whitlocb committed
283
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
284 285 286 287
    {
        c << indent << "    buf.WriteInt(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
288
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
289 290 291 292
    {
        c << indent << "Set" << Name << "(buf.ReadInt());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
293
    virtual void WriteToString(QTextStream &c, const QString &indent)
294 295 296
    {
        c << indent << "str = str + intToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
297 298 299 300 301 302
};


//
// -------------------------------- IntArray --------------------------------
//
whitlocb's avatar
whitlocb committed
303
class JavaGeneratorIntArray : public virtual IntArray , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
304 305
{
  public:
whitlocb's avatar
whitlocb committed
306
    JavaGeneratorIntArray(const QString &s, const QString &n, const QString &l)
307
        : Field("intArray",n,l), IntArray(s,n,l), JavaGeneratorField("intArray",n,l) { }
hrchilds's avatar
hrchilds committed
308 309 310 311 312 313

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "int[]";
    }

whitlocb's avatar
whitlocb committed
314
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328
    {
        c << "    " << name << " = new int[" << length << "];" << endl;
        if(valueSet)
        {
            for (int i = 0; i < length; ++i)
                c << "        " << name << "["<<i<<"] = " << val[i] << ";" << endl;
        }
        else
        {
            c << "    " << "for (int i = 0; i < " << length << "; ++i)" << endl;
            c << "        " << name << "[i] = 0;" << endl;
        }
    }

whitlocb's avatar
whitlocb committed
329
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
    {
        c << "        " << name << " = new int[" << length << "];" << endl;

        if (length < 4)
        { 
           for(int i = 0; i < length; ++i)
           {
               c << "        " << name << "[" << i << "] = "
                 << "obj." << name << "[" << i << "];" << endl;
           }
        }
        else
        {
            c << "        for(i = 0; i < obj." << name << ".length; ++i)" << endl;
            c << "            " << name << "[i] = obj." << name << "[i];" << endl;
        }
        c << endl;
    }

349
    virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363
    {
        if(length < 6)
        {
            c << "    public void Set" << Name << "(";
            for(int i = 0; i < length; ++i)
            {
                c << "int e" << i;
                if(i < length-1)
                    c << ", ";
            }
            c << ")" << endl;
            c << "    {" << endl;
            for(int j = 0; j < length; ++j)
                c << "        " << name << "[" << j << "] = e" << j << ";"<< endl;
364
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
365 366 367 368 369
            c << "    }" << endl;
            c << endl;
        }
    }

whitlocb's avatar
whitlocb committed
370
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
371 372 373 374
    {
        c << indent << "    buf.WriteIntArray(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
375
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
376 377 378 379
    {
        c << indent << "Set" << Name << "(buf.ReadIntArray());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
380
    virtual void WriteToString(QTextStream &c, const QString &indent)
381 382 383
    {
        c << indent << "str = str + intArrayToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
384 385 386 387 388 389
};


//
// -------------------------------- IntVector --------------------------------
//
whitlocb's avatar
whitlocb committed
390
class JavaGeneratorIntVector : public virtual IntVector , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
391 392
{
  public:
whitlocb's avatar
whitlocb committed
393
    JavaGeneratorIntVector(const QString &n, const QString &l)
394
        : Field("intVector",n,l), IntVector(n,l), JavaGeneratorField("intVector",n,l) { }
hrchilds's avatar
hrchilds committed
395 396 397 398 399 400 401 402 403 404 405 406

    virtual void AddImports(UniqueStringList &sl) 
    { 
        sl.AddString("import java.lang.Integer;\n");
        sl.AddString("import java.util.Vector;\n");
    }

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "Vector";
    }

whitlocb's avatar
whitlocb committed
407
    virtual void WriteSourceAttribute(QTextStream &h, int w)
hrchilds's avatar
hrchilds committed
408 409 410 411
    {
        h << "    private " << GetCPPNameW(w) << " " << name << "; // vector of Integer objects" << endl;
    }

whitlocb's avatar
whitlocb committed
412
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
413 414 415 416
    {
        c << "    " << name << " = new Vector();" << endl;
        if(valueSet)
        {
417
            for (size_t i = 0; i < val.size(); ++i)
hrchilds's avatar
hrchilds committed
418 419 420 421
                c << "        " << name << ".addElement(new Integer(" << val[i] << "));" << endl;
        }
    }

whitlocb's avatar
whitlocb committed
422
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
423 424 425 426 427 428 429 430 431
    {
        c << "        " << name << " = new Vector();" << endl;
        c << "        for(i = 0; i < obj." << name << ".size(); ++i)" << endl;
        c << "        {" << endl;
        c << "            Integer iv = (Integer)obj." << name << ".elementAt(i);" << endl;
        c << "            " << name << ".addElement(new Integer(iv.intValue()));" << endl;
        c << "        }" << endl;
    }

whitlocb's avatar
whitlocb committed
432
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
433 434 435 436
    {
        c << indent << "    buf.WriteIntVector(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
437
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
438 439 440 441
    {
        c << indent << "Set" << Name << "(buf.ReadIntVector());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
442
    virtual void WriteToString(QTextStream &c, const QString &indent)
443 444 445
    {
        c << indent << "str = str + intVectorToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
whitlocb's avatar
whitlocb committed
446 447 448 449
    virtual QString GetVectorStorageName() const
    {
        return "Integer";
    }
hrchilds's avatar
hrchilds committed
450 451 452 453 454 455
};


// 
// ----------------------------------- Bool -----------------------------------
//
whitlocb's avatar
whitlocb committed
456
class JavaGeneratorBool : public virtual Bool , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
457 458
{
  public:
whitlocb's avatar
whitlocb committed
459
    JavaGeneratorBool(const QString &n, const QString &l)
460
        : Field("boolean",n,l), Bool(n,l), JavaGeneratorField("boolean",n,l) { }
hrchilds's avatar
hrchilds committed
461 462 463 464 465 466

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "boolean";
    }

whitlocb's avatar
whitlocb committed
467
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
468 469 470 471
    {
        c << "    " << name << " = " << (val ? "true" : "false") << ";" << endl;
    }

whitlocb's avatar
whitlocb committed
472
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
473 474 475 476
    {
        c << indent << "    buf.WriteBool(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
477
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
478 479 480 481
    {
        c << indent << "Set" << Name << "(buf.ReadBool());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
482
    virtual void WriteToString(QTextStream &c, const QString &indent)
483 484 485
    {
        c << indent << "str = str + boolToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
486 487 488 489 490 491
};


//
// ----------------------------------- Float ----------------------------------
//
whitlocb's avatar
whitlocb committed
492
class JavaGeneratorFloat : public virtual Float , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
493 494
{
  public:
whitlocb's avatar
whitlocb committed
495
    JavaGeneratorFloat(const QString &n, const QString &l)
496
        : Field("float",n,l), Float(n,l), JavaGeneratorField("float",n,l) { }
hrchilds's avatar
hrchilds committed
497

whitlocb's avatar
whitlocb committed
498
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
499 500 501 502
    {
        c << "    " << name << " = " << val << "f;" << endl;
    }

whitlocb's avatar
whitlocb committed
503
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
504 505 506 507
    {
        c << indent << "    buf.WriteFloat(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
508
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
509 510 511 512
    {
        c << indent << "Set" << Name << "(buf.ReadFloat());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
513
    virtual void WriteToString(QTextStream &c, const QString &indent)
514 515 516
    {
        c << indent << "str = str + floatToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
517 518 519 520 521 522
};


//
// -------------------------------- FloatArray -------------------------------
//
whitlocb's avatar
whitlocb committed
523
class JavaGeneratorFloatArray : public virtual FloatArray , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
524 525
{
  public:
whitlocb's avatar
whitlocb committed
526
    JavaGeneratorFloatArray(const QString &s, const QString &n, const QString &l)
527
        : Field("floatArray",n,l), FloatArray(s,n,l), JavaGeneratorField("floatArray",n,l) { }
hrchilds's avatar
hrchilds committed
528 529 530 531 532 533

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "float[]";
    }

whitlocb's avatar
whitlocb committed
534
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548
    {
        c << "    " << name << " = new float[" << length << "];" << endl;
        if(valueSet)
        {
            for (int i = 0; i < length; ++i)
                c << "        " << name << "["<<i<<"] = " << val[i] << "f;" << endl;
        }
        else
        {
            c << "        for (int i = 0; i < "<<name<<".length; ++i)" << endl;
            c << "            " << name << "[i] = 0f;" << endl;
        }
    }

whitlocb's avatar
whitlocb committed
549
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
    {
        c << "        " << name << " = new float[" << length << "];" << endl;

        if (length < 4)
        { 
           for(int i = 0; i < length; ++i)
           {
               c << "        " << name << "[" << i << "] = "
                 << "obj." << name << "[" << i << "];" << endl;
           }
        }
        else
        {
            c << "        for(i = 0; i < obj." << name << ".length; ++i)" << endl;
            c << "            " << name << "[i] = obj." << name << "[i];" << endl;
        }
        c << endl;
    }

569
    virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583
    {
        if(length < 6)
        {
            c << "    public void Set" << Name << "(";
            for(int i = 0; i < length; ++i)
            {
                c << "float e" << i;
                if(i < length-1)
                    c << ", ";
            }
            c << ")" << endl;
            c << "    {" << endl;
            for(int j = 0; j < length; ++j)
                c << "        " << name << "[" << j << "] = e" << j << ";"<< endl;
584
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
585 586 587 588 589
            c << "    }" << endl;
            c << endl;
        }
    }

whitlocb's avatar
whitlocb committed
590
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
591 592 593 594
    {
        c << indent << "    buf.WriteFloatArray(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
595
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
596 597 598 599
    {
        c << indent << "Set" << Name << "(buf.ReadFloatArray());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
600
    virtual void WriteToString(QTextStream &c, const QString &indent)
601 602 603
    {
        c << indent << "str = str + floatArrayToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
604 605
};

606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
//
// ------------------------------- FloatVector -------------------------------
//
class JavaGeneratorFloatVector : public virtual FloatVector , public virtual JavaGeneratorField
{
  public:
    JavaGeneratorFloatVector(const QString &n, const QString &l)
        : Field("floatVector",n,l), FloatVector(n,l), JavaGeneratorField("floatVector",n,l) { }

    virtual void AddImports(UniqueStringList &sl) 
    { 
        sl.AddString("import java.lang.Float;\n");
        sl.AddString("import java.util.Vector;\n");
    }

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "Vector";
    }

    virtual void WriteSourceAttribute(QTextStream &h, int w)
    {
        h << "    private " << GetCPPNameW(w) << " " << name << "; // vector of Float objects" << endl;
    }

    virtual void WriteSourceSetDefault(QTextStream &c)
    {
        c << "    " << name << " = new Vector();" << endl;
        for (size_t i = 0; i < val.size(); ++i)
            c << "        " << name << ".addElement(new Float(" << val[i] << "));" << endl;
    }

    virtual void WriteSourceCopyCode(QTextStream &c)
    {
        c << "        " << name << " = new Vector(obj." << name << ".size());" << endl;
        c << "        for(i = 0; i < obj." << name << ".size(); ++i)" << endl;
        c << "        {" << endl;
        c << "            Float dv = (Float)obj." << name << ".elementAt(i);" << endl;
        c << "            " << name << ".addElement(new Float(dv.floatValue()));" << endl;
        c << "        }" << endl;
        c << endl;
    }

    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
    {
        c << indent << "    buf.WriteFloatVector(" << name << ");" << endl;
    }

    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
    {
        c << indent << "Set" << Name << "(buf.ReadFloatVector());" << endl;
        return true;
    }
    virtual void WriteToString(QTextStream &c, const QString &indent)
    {
        c << indent << "str = str + floatVectorToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
    virtual QString GetVectorStorageName() const
    {
        return "Float";
    }
};

hrchilds's avatar
hrchilds committed
669 670 671 672

//
// ---------------------------------- Double ----------------------------------
//
whitlocb's avatar
whitlocb committed
673
class JavaGeneratorDouble : public virtual Double , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
674 675
{
  public:
whitlocb's avatar
whitlocb committed
676
    JavaGeneratorDouble(const QString &n, const QString &l)
677
        : Field("double",n,l), Double(n,l), JavaGeneratorField("double",n,l) { }
hrchilds's avatar
hrchilds committed
678

whitlocb's avatar
whitlocb committed
679
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
680 681 682 683
    {
        c << "    " << name << " = " << val << ";" << endl;
    }

whitlocb's avatar
whitlocb committed
684
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
685 686 687 688
    {
        c << indent << "    buf.WriteDouble(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
689
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
690 691 692 693
    {
        c << indent << "Set" << Name << "(buf.ReadDouble());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
694
    virtual void WriteToString(QTextStream &c, const QString &indent)
695 696 697
    {
        c << indent << "str = str + doubleToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
698 699 700 701 702 703
};


//
// -------------------------------- DoubleArray -------------------------------
//
whitlocb's avatar
whitlocb committed
704
class JavaGeneratorDoubleArray : public virtual DoubleArray , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
705 706
{
  public:
whitlocb's avatar
whitlocb committed
707
    JavaGeneratorDoubleArray(const QString &s, const QString &n, const QString &l)
708
        : Field("doubleArray",n,l), DoubleArray(s,n,l), JavaGeneratorField("doubleArray",n,l) { }
hrchilds's avatar
hrchilds committed
709 710 711 712 713 714

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "double[]";
    }

whitlocb's avatar
whitlocb committed
715
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
    {
        c << "    " << name << " = new double[" << length << "];" << endl;
        if(valueSet)
        {
            for (int i = 0; i < length; ++i)
                c << "        " << name << "["<<i<<"] = " << val[i] << ";" << endl;
        }
        else
        {
            c << "        for (int i = 0; i < "<<name<<".length; ++i)" << endl;
            c << "            " << name << "[i] = 0.;" << endl;
        }

    }

whitlocb's avatar
whitlocb committed
731
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
    {
        c << "        " << name << " = new double[" << length << "];" << endl;

        if (length < 4)
        { 
           for(int i = 0; i < length; ++i)
           {
               c << "        " << name << "[" << i << "] = "
                 << "obj." << name << "[" << i << "];" << endl;
           }
        }
        else
        {
            c << "        for(i = 0; i < obj." << name << ".length; ++i)" << endl;
            c << "            " << name << "[i] = obj." << name << "[i];" << endl;
        }
        c << endl;
    }

751
    virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765
    {
        if(length < 6)
        {
            c << "    public void Set" << Name << "(";
            for(int i = 0; i < length; ++i)
            {
                c << "double e" << i;
                if(i < length-1)
                    c << ", ";
            }
            c << ")" << endl;
            c << "    {" << endl;
            for(int j = 0; j < length; ++j)
                c << "        " << name << "[" << j << "] = e" << j << ";"<< endl;
766
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
767 768 769 770 771
            c << "    }" << endl;
            c << endl;
        }
    }

whitlocb's avatar
whitlocb committed
772
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
773 774 775 776
    {
        c << indent << "    buf.WriteDoubleArray(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
777
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
778 779 780 781
    {
        c << indent << "Set" << Name << "(buf.ReadDoubleArray());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
782
    virtual void WriteToString(QTextStream &c, const QString &indent)
783 784 785
    {
        c << indent << "str = str + doubleArrayToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
786 787 788 789 790
};

//
// ------------------------------- DoubleVector -------------------------------
//
whitlocb's avatar
whitlocb committed
791
class JavaGeneratorDoubleVector : public virtual DoubleVector , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
792 793
{
  public:
whitlocb's avatar
whitlocb committed
794
    JavaGeneratorDoubleVector(const QString &n, const QString &l)
795
        : Field("doubleVector",n,l), DoubleVector(n,l), JavaGeneratorField("doubleVector",n,l) { }
hrchilds's avatar
hrchilds committed
796 797 798 799 800 801 802 803 804 805 806 807

    virtual void AddImports(UniqueStringList &sl) 
    { 
        sl.AddString("import java.lang.Double;\n");
        sl.AddString("import java.util.Vector;\n");
    }

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "Vector";
    }

whitlocb's avatar
whitlocb committed
808
    virtual void WriteSourceAttribute(QTextStream &h, int w)
hrchilds's avatar
hrchilds committed
809 810 811 812
    {
        h << "    private " << GetCPPNameW(w) << " " << name << "; // vector of Double objects" << endl;
    }

whitlocb's avatar
whitlocb committed
813
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
814 815
    {
        c << "    " << name << " = new Vector();" << endl;
816
        for (size_t i = 0; i < val.size(); ++i)
hrchilds's avatar
hrchilds committed
817 818 819
            c << "        " << name << ".addElement(new Double(" << val[i] << "));" << endl;
    }

whitlocb's avatar
whitlocb committed
820
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
821 822 823 824 825 826 827 828 829 830
    {
        c << "        " << name << " = new Vector(obj." << name << ".size());" << endl;
        c << "        for(i = 0; i < obj." << name << ".size(); ++i)" << endl;
        c << "        {" << endl;
        c << "            Double dv = (Double)obj." << name << ".elementAt(i);" << endl;
        c << "            " << name << ".addElement(new Double(dv.doubleValue()));" << endl;
        c << "        }" << endl;
        c << endl;
    }

whitlocb's avatar
whitlocb committed
831
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
832 833 834 835
    {
        c << indent << "    buf.WriteDoubleVector(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
836
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
837 838 839 840
    {
        c << indent << "Set" << Name << "(buf.ReadDoubleVector());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
841
    virtual void WriteToString(QTextStream &c, const QString &indent)
842 843 844
    {
        c << indent << "str = str + doubleVectorToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
whitlocb's avatar
whitlocb committed
845 846 847 848
    virtual QString GetVectorStorageName() const
    {
        return "Double";
    }
hrchilds's avatar
hrchilds committed
849 850 851 852 853 854
};


//
// ----------------------------------- UChar ----------------------------------
//
whitlocb's avatar
whitlocb committed
855
class JavaGeneratorUChar : public virtual UChar , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
856 857
{
  public:
whitlocb's avatar
whitlocb committed
858
    JavaGeneratorUChar(const QString &n, const QString &l)
859
        : Field("uchar",n,l), UChar(n,l), JavaGeneratorField("uchar",n,l) { }
hrchilds's avatar
hrchilds committed
860 861 862 863 864 865

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "byte";
    }

whitlocb's avatar
whitlocb committed
866
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
867 868 869 870
    {
        c << "    " << name << " = " << int(val) << ";" << endl;
    }

whitlocb's avatar
whitlocb committed
871
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
872 873 874 875
    {
        c << indent << "    buf.WriteByte(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
876
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
877 878 879 880
    {
        c << indent << "Set" << Name << "(buf.ReadByte());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
881
    virtual void WriteToString(QTextStream &c, const QString &indent)
882 883 884
    {
        c << indent << "str = str + ucharToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
885 886 887 888 889 890
};


//
// -------------------------------- UCharArray --------------------------------
//
whitlocb's avatar
whitlocb committed
891
class JavaGeneratorUCharArray : public virtual UCharArray , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
892 893
{
  public:
whitlocb's avatar
whitlocb committed
894
    JavaGeneratorUCharArray(const QString &s, const QString &n, const QString &l)
895
        : Field("ucharArray",n,l), UCharArray(s,n,l), JavaGeneratorField("byte",n,l) { }
hrchilds's avatar
hrchilds committed
896 897 898 899 900 901

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "byte[]";
    }

whitlocb's avatar
whitlocb committed
902
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
903 904 905 906 907
    {
        c << "    " << name << " = new byte[" << length << "];" << endl;
        if(valueSet)
        {
            for (int i = 0; i < length; ++i)
whitlocb's avatar
whitlocb committed
908
                c << "        " << name << "["<<i<<"] = (byte)" << int(val[i]) << ";" << endl;
hrchilds's avatar
hrchilds committed
909 910 911 912 913 914 915 916
        }
        else
        {
            c << "        for (int i = 0; i < "<<name<<".length; ++i)" << endl;
            c << "            " << name << "[i] = 0;" << endl;
        }
    }

whitlocb's avatar
whitlocb committed
917
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
    {
        c << "        " << name << " = new byte[" << length << "];" << endl;

        if (length < 4)
        { 
           for(int i = 0; i < length; ++i)
           {
               c << "        " << name << "[" << i << "] = "
                 << "obj." << name << "[" << i << "];" << endl;
           }
        }
        else
        {
            c << "        for(i = 0; i < obj." << name << ".length; ++i)" << endl;
            c << "            " << name << "[i] = obj." << name << "[i];" << endl;
        }
        c << endl;
    }

937
    virtual void WriteAuxiliarySetFunction(QTextStream &c, const QString &classname)
hrchilds's avatar
hrchilds committed
938 939 940 941 942 943 944 945 946 947 948 949 950 951
    {
        if(length < 6)
        {
            c << "    public void Set" << Name << "(";
            for(int i = 0; i < length; ++i)
            {
                c << "byte e" << i;
                if(i < length-1)
                    c << ", ";
            }
            c << ")" << endl;
            c << "    {" << endl;
            for(int j = 0; j < length; ++j)
                c << "        " << name << "[" << j << "] = e" << j << ";"<< endl;
952
            c << "        Select(" << OffsetPlus(classname) << index << ");" << endl;
hrchilds's avatar
hrchilds committed
953 954 955 956 957
            c << "    }" << endl;
            c << endl;
        }
    }

whitlocb's avatar
whitlocb committed
958
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
959 960 961 962
    {
        c << indent << "    buf.WriteByteArray(" << name << ", true);" << endl;
    }

whitlocb's avatar
whitlocb committed
963
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
964 965 966 967
    {
        c << indent << "Set" << Name << "(buf.ReadByteArray());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
968
    virtual void WriteToString(QTextStream &c, const QString &indent)
969 970 971
    {
        c << indent << "str = str + ucharArrayToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
hrchilds's avatar
hrchilds committed
972 973 974 975 976 977
};


//
// ------------------------------- UCharVector -------------------------------
//
whitlocb's avatar
whitlocb committed
978
class JavaGeneratorUCharVector : public virtual UCharVector , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
979 980
{
  public:
whitlocb's avatar
whitlocb committed
981
    JavaGeneratorUCharVector(const QString &n, const QString &l)
982
        : Field("ucharVector",n,l), UCharVector(n,l), JavaGeneratorField("ucharVector",n,l) { }
hrchilds's avatar
hrchilds committed
983 984 985 986 987 988 989 990 991 992 993 994

    virtual void AddImports(UniqueStringList &sl) 
    { 
        sl.AddString("import java.lang.Byte;\n");
        sl.AddString("import java.util.Vector;\n");
    }

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "Vector";
    }

whitlocb's avatar
whitlocb committed
995
    virtual void WriteSourceAttribute(QTextStream &h, int w)
hrchilds's avatar
hrchilds committed
996 997 998 999
    {
        h << "    private " << GetCPPNameW(w) << " " << name << "; // vector of Byte objects" << endl;
    }

whitlocb's avatar
whitlocb committed
1000
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
1001 1002
    {
        c << "    " << name << " = new Vector();" << endl;
1003
        for (size_t i = 0; i < val.size(); ++i)
hrchilds's avatar
hrchilds committed
1004 1005 1006
            c << "        " << name << ".addElement(new Byte(" << val[i] << "));" << endl;
    }

whitlocb's avatar
whitlocb committed
1007
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
    {
        c << "        " << name << " = new Vector(obj." << name << ".size());" << endl;
        c << "        for(i = 0; i < obj." << name << ".size(); ++i)" << endl;
        c << "        {" << endl;
        c << "            Byte bv = (Byte)obj." << name << ".elementAt(i);" << endl;
        c << "            " << name << ".addElement(new Byte(bv.byteValue()));" << endl;
        c << "        }" << endl;
        c << endl;
    }

whitlocb's avatar
whitlocb committed
1018
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
1019 1020 1021 1022
    {
        c << indent << "    buf.WriteByteVector(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
1023
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
1024 1025 1026 1027
    {
        c << indent << "Set" << Name << "(buf.ReadByteVector());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
1028
    virtual void WriteToString(QTextStream &c, const QString &indent)
1029 1030 1031
    {
        c << indent << "str = str + ucharVectorToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
whitlocb's avatar
whitlocb committed
1032 1033 1034 1035
    virtual QString GetVectorStorageName() const
    {
        return "Byte";
    }
hrchilds's avatar
hrchilds committed
1036 1037 1038 1039 1040 1041
};


//
// ---------------------------------- String ----------------------------------
//
whitlocb's avatar
whitlocb committed
1042
class JavaGeneratorString : public virtual String , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
1043 1044
{
  public:
whitlocb's avatar
whitlocb committed
1045
    JavaGeneratorString(const QString &n, const QString &l)
1046
        : Field("string",n,l), String(n,l), JavaGeneratorField("string",n,l) { }
hrchilds's avatar
hrchilds committed
1047 1048 1049 1050 1051 1052

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "String";
    }

whitlocb's avatar
whitlocb committed
1053
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
1054
    {
hrchilds's avatar
hrchilds committed
1055 1056 1057 1058
        if (valueSet)
            c << "    " << name << " = new String(\"" << val << "\");" << endl;
        else
            c << "    " << name << " = new String(\"\");" << endl;
hrchilds's avatar
hrchilds committed
1059 1060
    }

whitlocb's avatar
whitlocb committed
1061
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
1062 1063 1064 1065
    {
        c << "        " << name << " = new String(obj." << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
1066
    virtual void WriteSourceWriteAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
1067 1068 1069 1070
    {
        c << indent << "    buf.WriteString(" << name << ");" << endl;
    }

whitlocb's avatar
whitlocb committed
1071
    virtual bool WriteSourceReadAtts(QTextStream &c, const QString &indent)
hrchilds's avatar
hrchilds committed
1072 1073 1074 1075
    {
        c << indent << "Set" << Name << "(buf.ReadString());" << endl;
        return true;
    }
whitlocb's avatar
whitlocb committed
1076
    virtual void WriteToString(QTextStream &c, const QString &indent)
1077 1078 1079
    {
        c << indent << "str = str + stringToString(\"" << name << "\", " << name << ", indent) + \"\\n\";" << endl;       
    }
whitlocb's avatar
whitlocb committed
1080
    virtual void WriteSourceComparison(QTextStream &c)
whitlocb's avatar
whitlocb committed
1081 1082 1083
    {
        c << "(" << name << ".equals(obj." << name << "))";
    }
hrchilds's avatar
hrchilds committed
1084 1085 1086 1087 1088 1089
};


//
// ------------------------------- StringVector -------------------------------
//
whitlocb's avatar
whitlocb committed
1090
class JavaGeneratorStringVector : public virtual StringVector , public virtual JavaGeneratorField
hrchilds's avatar
hrchilds committed
1091 1092
{
  public:
whitlocb's avatar
whitlocb committed
1093
    JavaGeneratorStringVector(const QString &n, const QString &l)
1094
        : Field("stringVector",n,l), StringVector(n,l), JavaGeneratorField("stringVector",n,l) { }
hrchilds's avatar
hrchilds committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105

    virtual void AddImports(UniqueStringList &sl) 
    { 
        sl.AddString("import java.util.Vector;\n");
    }

    virtual QString GetCPPName(bool, const QString &) 
    {
        return "Vector";
    }

whitlocb's avatar
whitlocb committed
1106
    virtual void WriteSourceAttribute(QTextStream &h, int w)
hrchilds's avatar
hrchilds committed
1107 1108 1109 1110
    {
        h << "    private " << GetCPPNameW(w) << " " << name << "; // vector of String objects" << endl;
    }

whitlocb's avatar
whitlocb committed
1111
    virtual void WriteSourceSetDefault(QTextStream &c)
hrchilds's avatar
hrchilds committed
1112 1113
    {
        c << "    " << name << " = new Vector();" << endl;
1114
        for (size_t i = 0; i < val.size(); ++i)
whitlocb's avatar
whitlocb committed
1115
        c << "        " << name << ".addElement(new String(" << "\"" << val[i] << "\"));" << endl;
hrchilds's avatar
hrchilds committed
1116 1117
    }

whitlocb's avatar
whitlocb committed
1118
    virtual void WriteSourceCopyCode(QTextStream &c)
hrchilds's avatar
hrchilds committed
1119