~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/sps/shl/Record.cpp

  • Committer: Package Import Robot
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2015-07-11 02:00:35 UTC
  • mfrom: (10.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150711020035-2nhpztq7s15qyc0v
Tags: 2.5.1-1
* New upstream release. (Closes: #789968)
* Update debian/control.
  - Update Standards-Version to 3.9.6.
* Add support mips64(el) and ppc64el. (Closes: #741508, #748146)
* Add patches/support-gcc-5.x.patch. (Closes: #777767)
  - Fix build with gcc-5.x.
* Add patches/Disable-NET0001.als.patch.
  - Disable test of NET0001.als.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
12
// - special damages arising in any way out of the use of this software.     -
13
13
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2012 amaury darsch                                   -
 
14
// - copyright (c) 1999-2015 amaury darsch                                   -
15
15
// ---------------------------------------------------------------------------
16
16
 
17
17
#include "Cons.hpp"
39
39
    return new Record;
40
40
  }
41
41
  // register this cell serial id
42
 
  static const t_byte SERIAL_ID = Serial::setsid (SERIAL_RECD_ID, mksob);
 
42
  static const t_byte SERIAL_ID __attribute__((unused)) = Serial::setsid (SERIAL_RECD_ID, mksob);
43
43
 
44
44
  // this function compare an object with another one in ascent mode
45
45
  static bool qsort_cmplth (Object* ref, Object* slv) {
70
70
 
71
71
  Record::Record (void) {
72
72
    d_quark = 0;
 
73
    p_style = nilp;
73
74
    reset ();
74
75
  }
75
76
 
77
78
 
78
79
  Record::Record (const String& name) {
79
80
    d_quark = name.toquark ();
 
81
    p_style = nilp;
80
82
    reset ();
81
83
  }
82
84
 
85
87
  Record::Record (const Record& that) {
86
88
    that.rdlock ();
87
89
    try {
88
 
      d_quark   = that.d_quark;
89
 
      d_trnum   = that.d_trnum;
 
90
      d_quark = that.d_quark;
 
91
      d_trnum = that.d_trnum;
 
92
      p_style = (that.p_style == nilp) ? nilp : new Style (*that.p_style);
 
93
      Object::iref (p_style);
90
94
      long rlen = that.length ();
91
95
      for (long i = 0; i < rlen; i++) {
92
96
        Cell* cell = that.get (i);
100
104
    }
101
105
  }
102
106
 
 
107
  // destroy this record
 
108
 
 
109
  Record::~Record (void) {
 
110
    Object::dref (p_style);
 
111
  }
 
112
 
103
113
  // return the object name
104
114
 
105
115
  String Record::repr (void) const {
129
139
      // save the transaction number
130
140
      Integer trnum  (d_trnum);
131
141
      trnum.wrstream (os);
 
142
      // save the style
 
143
      if (p_style == nilp) {
 
144
        Serial::wrnilid (os);
 
145
      } else {
 
146
        p_style->serialize (os);
 
147
      }
132
148
      // save the vector
133
149
      d_vcell.wrstream (os);
134
150
      unlock ();
151
167
      Integer trnum;
152
168
      trnum.rdstream (is);
153
169
      d_trnum = trnum.tolong ();
 
170
      // deserialize the style
 
171
      Object* sobj = Serial::deserialize (is);
 
172
      p_style = dynamic_cast <Style*> (sobj);
 
173
      if ((sobj != nilp) && (p_style == nilp)) {
 
174
        throw  Exception ("type-error", "invalid record style object", 
 
175
                          Object::repr (sobj));
 
176
      }
154
177
      // get the vector
155
178
      d_vcell.rdstream (is);
156
179
      unlock ();
169
192
    wrlock ();
170
193
    that.rdlock ();
171
194
    try {
172
 
      d_quark   = that.d_quark;
173
 
      d_trnum   = that.d_trnum;
 
195
      d_quark = that.d_quark;
 
196
      d_trnum = that.d_trnum;
 
197
      p_style = (that.p_style == nilp) ? nilp : new Style (*that.p_style);
 
198
      Object::iref (p_style);
174
199
      long rlen = that.length ();
175
200
      for (long i = 0; i < rlen; i++) {
176
201
        Cell* cell = that.get (i);
192
217
  void Record::reset (void) {
193
218
    wrlock ();
194
219
    try {
195
 
      d_trnum = -1;
 
220
      d_trnum = -1L;
 
221
      if (p_style != nilp) p_style->reset ();
196
222
      d_vcell.reset ();
197
223
      unlock ();
198
224
    } catch (...) {
201
227
    }
202
228
  }
203
229
 
 
230
  // clear this record
 
231
 
 
232
  void Record::clear (void) {
 
233
    wrlock ();
 
234
    try {
 
235
      d_trnum = -1L;
 
236
      long rlen = length ();
 
237
      for (long k = 0L; k < rlen; k++) {
 
238
        Cell* cell = get (k);
 
239
        if (cell != nilp) cell->clear ();
 
240
      }
 
241
      unlock ();
 
242
    } catch (...) {
 
243
      unlock ();
 
244
      throw;
 
245
    }
 
246
  }
 
247
 
204
248
  // return the record name
205
249
 
206
250
  String Record::getname (void) const {
269
313
    }
270
314
  }
271
315
 
 
316
  // get the record style
 
317
 
 
318
  Style* Record::getstyle (void) const {
 
319
    rdlock ();
 
320
    try {
 
321
      Style* result = p_style;
 
322
      unlock ();
 
323
      return result;
 
324
    } catch (...) {
 
325
      unlock ();
 
326
      throw;
 
327
    }
 
328
  }
 
329
 
 
330
  // get the record style
 
331
 
 
332
  Style* Record::getstyle (const long index) const {
 
333
    rdlock ();
 
334
    try {
 
335
      // get the cell by index
 
336
      Cell* cell = get (index);
 
337
      // get the cell style
 
338
      Style* result = (cell == nilp) ? nilp : cell->getstyle ();
 
339
      unlock ();
 
340
      return result;
 
341
    } catch (...) {
 
342
      unlock ();
 
343
      throw;
 
344
    }
 
345
  }
 
346
 
272
347
  // return the length of the record list
273
348
 
274
349
  long Record::length (void) const {
400
475
  Cell* Record::get (const long index) const {
401
476
    rdlock ();
402
477
    try {
403
 
      Cell* result = dynamic_cast <Cell*> (d_vcell.get (index));
 
478
      long rlen = d_vcell.length ();
 
479
      Cell* result = (index < rlen) 
 
480
        ? dynamic_cast <Cell*> (d_vcell.get (index))
 
481
        : nilp;
404
482
      unlock ();
405
483
      return result;
406
484
    } catch (...) {
429
507
  void Record::set (const long index, Cell* cell) {
430
508
    wrlock ();
431
509
    try {
432
 
      // add cell if necessary
 
510
      // fix the cell
 
511
      Cell* c = (cell == nilp) ? new Cell : cell;
 
512
      // set or add
433
513
      long rlen = length ();
434
 
      if (index >= rlen) {
435
 
        long delta = index - rlen + 1;
436
 
        for (long i = 0; i < delta; i++) add (new Cell);
 
514
      if (index < rlen) {
 
515
        d_vcell.set (index, c);
 
516
      } else {
 
517
        // add missing cell
 
518
        for (long k = rlen; k < index; k++) add (new Cell);
 
519
        // add the cell
 
520
        add (c); 
437
521
      }
438
 
      // set the cell
439
 
      d_vcell.set (index, cell);
440
522
      unlock ();
441
523
    } catch (...) {
442
524
      unlock ();
446
528
 
447
529
  // set a literal in this record by index
448
530
 
449
 
  void Record::set (const long index, Literal* lobj) {
 
531
  Cell* Record::set (const long index, Literal* lobj) {
450
532
    wrlock ();
451
 
    Cell* cell = new Cell (lobj);
452
 
    // update the record
453
533
    try {
454
 
      // add cell if necessary
455
 
      long rlen = length ();
456
 
      if (index >= rlen) {
457
 
        long delta = index - rlen + 1;
458
 
        for (long i = 0; i < delta; i++) add (new Cell);
 
534
      long  rlen = length ();
 
535
      Cell* cell = nilp;
 
536
      if (index < rlen) {
 
537
        cell = get (index);
 
538
        if (cell == nilp) d_vcell.set (index, new Cell (lobj));
 
539
        else cell->set (lobj);
 
540
      } else {
 
541
        // add missing cells
 
542
        for (long k = rlen; k < index; k++) add (new Cell);
 
543
        // add the cell
 
544
        cell = new Cell (lobj);
 
545
        add (cell);
459
546
      }
460
 
      // add the cell
461
 
      d_vcell.set (index, cell);
 
547
      unlock();
 
548
      return cell;
462
549
    } catch (...) {
463
 
      delete cell;
464
550
      unlock ();
465
551
      throw;
466
552
    }
469
555
 
470
556
  // set an object in this record by index
471
557
 
472
 
  void Record::set (const long index, Object* object) {
473
 
    if (object == nilp) return;
474
 
    // check for a cell
475
 
    Cell* cell = dynamic_cast <Cell*> (object);
476
 
    if (cell != nilp) {
477
 
      set (index, cell);
478
 
      return;
479
 
    }
480
 
    // check for a literal
481
 
    Literal* lobj = dynamic_cast <Literal*> (object);
482
 
    if (lobj != nilp) {
483
 
      set (index, lobj);
484
 
      return;
485
 
    }
486
 
    throw Exception ("type-error", "invalid object to set in record",
487
 
                     Object::repr (object));
 
558
  Cell* Record::set (const long index, Object* object) {
 
559
    // check for nil
 
560
    if (object == nilp) return nilp;
 
561
    // lock and set
 
562
    wrlock ();
 
563
    try {
 
564
      // check for a cell
 
565
      Cell* cell = dynamic_cast <Cell*> (object);
 
566
      if (cell != nilp) {
 
567
        set (index, cell);
 
568
        unlock ();
 
569
        return cell;
 
570
      }
 
571
      // check for a literal
 
572
      Literal* lobj = dynamic_cast <Literal*> (object);
 
573
      if (lobj != nilp) {
 
574
        Cell* cell = set (index, lobj);
 
575
        unlock ();
 
576
        return cell;
 
577
      }
 
578
      throw Exception ("type-error", "invalid object to set in record",
 
579
                       Object::repr (object));
 
580
    } catch (...) {
 
581
      unlock ();
 
582
      throw;
 
583
    }
488
584
  }
489
585
 
490
586
  // find a cell by quark
634
730
  // -------------------------------------------------------------------------
635
731
 
636
732
  // the quark zone
637
 
  static const long QUARK_ZONE_LENGTH = 13;
 
733
  static const long QUARK_ZONE_LENGTH = 14;
638
734
  static QuarkZone  zone (QUARK_ZONE_LENGTH);
639
735
 
640
736
  // the record supported quarks
645
741
  static const long QUARK_FIND     = zone.intern ("find");
646
742
  static const long QUARK_SORT     = zone.intern ("sort");
647
743
  static const long QUARK_RESET    = zone.intern ("reset");
 
744
  static const long QUARK_CLEAR    = zone.intern ("clear");
648
745
  static const long QUARK_LOOKUP   = zone.intern ("lookup");
649
746
  static const long QUARK_LENGTH   = zone.intern ("length");
650
747
  static const long QUARK_SETNAME  = zone.intern ("set-name");
675
772
      unlock ();
676
773
      return true;
677
774
    }
678
 
    bool result = hflg ? Persist::isquark (quark, hflg) : false;
 
775
    bool result = hflg ? Saveas::isquark (quark, hflg) : false;
679
776
    unlock ();
680
777
    return result;
681
778
  }
723
820
        reset ();
724
821
        return nilp;
725
822
      }
 
823
      if (quark == QUARK_CLEAR) {
 
824
        clear ();
 
825
        return nilp;
 
826
      }
726
827
      if (quark == QUARK_SORT) {
727
828
        sort (true);
728
829
        return nilp;
798
899
      if (quark == QUARK_SET) {
799
900
        long    idx = argv->getlong (0);
800
901
        Object* obj = argv->get (1);
801
 
        set (idx, obj);
802
 
        return nilp;
 
902
        wrlock ();
 
903
        try {
 
904
          Object* result = set (idx, obj);
 
905
          robj->post (result);
 
906
          unlock ();
 
907
          return result;
 
908
        } catch (...) {
 
909
          unlock ();
 
910
          throw;
 
911
        }
803
912
      }
804
913
      if (quark == QUARK_SETNAME) {
805
914
        long    idx = argv->getlong (0);
808
917
        return nilp;
809
918
      }
810
919
    }
811
 
    // call the persist method
812
 
    return Persist::apply (robj, nset, quark, argv);
 
920
    // call the saveas method
 
921
    return Saveas::apply (robj, nset, quark, argv);
813
922
  }
814
923
}