source: to-imperative/trunk/runtime/rf_vector.ih @ 1048

Last change on this file since 1048 was 1048, checked in by sveta, 18 years ago
  • Methods for Vector are added.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1#ifndef __rf_vector_ih__
2#define __rf_vector_ih__
3
4#include "rf_vector.hh"
5#include "rf_object.ih"
6#include "rf_expr.ih"
7#include "pxx_vector.ih"
8#include <typeinfo>
9
10namespace rftype
11{
12
13inline Vector::Vector (size_t _length /* = 0 */) :
14  Object (),
15  pxx::Vector<Expr> (_length)
16{}
17
18inline Vector::Vector (size_t _length, Expr const& _fill) :
19  Object (),
20  pxx::Vector<Expr> (_length)
21{
22  for (size_t i = 0; i < _length; i++) {
23    self[i] = _fill;
24  }
25
26
27inline Vector::Vector (Expr const& _expr, size_t _length) :
28  Object (),
29  pxx::Vector<Expr> (_length)
30{
31  Term* p = _expr.get_first();
32  Term* q = _expr.get_last();
33  size_t index = 0;
34  for (; p < q; p++) {
35    if (p->is_ref()) {
36      self[index++] = (Expr(p))();
37    } else {
38      FATAL("Invalid argument");               //  RF_LIB_ERROR - ??????
39    }
40  }
41}
42
43inline Vector::Vector(Vector const& _vector, size_t _index, size_t _length) :
44  Object(),
45  pxx::Vector<Expr> (_length)
46{
47  for (size_t i = 0; i < _length; i++)
48    self[i] = _vector[_index + i];
49}
50
51
52inline unsigned Vector::get_type () const
53{
54  return reg.get_type();
55}
56
57//
58// FIXME: Implement real hashing
59inline uint32_t Vector::hash () const
60{
61  return 0;
62}
63
64inline bool Vector::operator == (Object const& _obj) const
65{
66  try {
67    Vector const& v = dynamic_cast<Vector const&>(_obj);
68    if (get_length() == v.get_length()) {
69      for (size_t i = 0; i < get_length(); i++) {
70        if (self[i] != v[i]) return false;
71      }
72      return true;
73    }
74    return false;
75  } catch (std::bad_cast&) {
76    return false;
77  }
78}
79
80inline void Vector::vector_to_exp (Expr& _exp)
81{
82  for (size_t i = 0; i < get_length(); i++)
83    _exp = _exp + self[i];
84}
85
86inline void Vector::vector_init (size_t _length, Expr const& _fill)
87{
88  size_t n = get_length();
89  if (n < _length) 
90      expand (_length - n);
91  else
92    if (n > _length)
93      decrease(n - _length);
94   n = _length;
95   for (  ; n  ; n--)
96     self[n-1] = _fill();
97}
98
99inline void Vector::vector_replace (size_t _length, Expr const& _exp)
100{
101  size_t n = get_length();
102  if (n < _length)
103    expand (_length - n);
104  else
105    if (n > _length)
106      decrease(n - _length);
107  Term* p = _exp.get_first();
108  Term* q = _exp.get_last();
109  n = 0;
110  for ( ; p < q ; p++) {
111    if (p->is_ref()) {
112      self[n++] = (Expr(p))();
113    } else {
114      FATAL("Invalid argument");     
115    }
116  }
117}   
118
119inline void  vector_meaning (Expr const& _exp, Expr& _result)
120{
121  Term* p = _exp.get_first();
122  Term* q = _exp.get_last();
123  for ( ; p < q; p++) {
124    if (p->is_ref()) {
125      _result = _result + (Expr(p))();
126    } else {
127      Vector* v = p->cast_to<Vector> (type_vector);
128      if (!v)
129        FATAL ("Invalid argument");
130      for (size_t i = 0; i < v->get_length(); i++)
131        _result = _result + (*v)[i];
132    }
133  }
134}     
135 
136inline void Vector::vector_fill (Expr const& _fill)
137{
138  for (size_t i = 0; i < get_length(); i++)
139    self[i] = _fill();
140}
141
142inline void Vector::subvector_fill (size_t _index, size_t _length, Expr const& _fill)
143{
144  for (size_t i = 0; i < _length; i++)
145    self[_index + i] = _fill();
146}
147
148}
149
150#endif // __rf_vector_ih__
151
Note: See TracBrowser for help on using the repository browser.