1
// ---------------------------------------------------------------------------
3
// - afnix:mth module - real sparse interface implementation -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2011 amaury darsch -
15
// ---------------------------------------------------------------------------
20
#include "Integer.hpp"
21
#include "Runnable.hpp"
22
#include "QuarkZone.hpp"
23
#include "Exception.hpp"
27
// -------------------------------------------------------------------------
29
// -------------------------------------------------------------------------
31
// create a default sparse object
37
// create a sparse object by size
39
Rsi::Rsi (const t_long size) {
42
throw Exception ("size-error", "invalid sparse object size");
47
// get the sparse object size
49
t_long Rsi::getsize (void) const {
52
t_long result = d_size;
61
// -------------------------------------------------------------------------
63
// -------------------------------------------------------------------------
66
static const long QUARK_ZONE_LENGTH = 5;
67
static QuarkZone zone (QUARK_ZONE_LENGTH);
69
// the rsi supported quarks
70
static const long QUARK_SET = zone.intern ("set");
71
static const long QUARK_LENGTH = zone.intern ("length");
72
static const long QUARK_GETIDX = zone.intern ("get-index");
73
static const long QUARK_GETVAL = zone.intern ("get-value");
74
static const long QUARK_GETSIZE = zone.intern ("get-size");
76
// return true if the given quark is defined
78
bool Rsi::isquark (const long quark, const bool hflg) const {
80
if (zone.exists (quark) == true){
84
bool result = hflg ? Object::isquark (quark, hflg) : false;
89
// apply this object with a set of arguments and a quark
91
Object* Rsi::apply (Runnable* robj, Nameset* nset, const long quark,
93
// get the number of arguments
94
long argc = (argv == nilp) ? 0 : argv->length ();
96
// dispatch 0 argument
98
if (quark == QUARK_LENGTH) return new Integer (length ());
99
if (quark == QUARK_GETSIZE) return new Integer (getsize ());
101
// dispatch 1 argument
103
if (quark == QUARK_GETIDX) {
104
t_long pos = argv->getlong (0);
105
return new Integer (getidx (pos));
107
if (quark == QUARK_GETVAL) {
108
t_long pos = argv->getlong (0);
109
return new Real (getval (pos));
112
// dispatch 2 arguments
114
if (quark == QUARK_SET) {
115
t_long sidx = argv->getlong (0);
116
t_real sval = argv->getreal (1);
117
return new Integer (set (sidx, sval));
121
return Object::apply (robj, nset, quark, argv);