Class: Sfcc::Cim::Class

Inherits:
Object
  • Object
show all
Defined in:
lib/sfcc/class.rb,
ext/sfcc/cim_class.c

Instance Method Summary collapse

Instance Method Details

#abstract?Boolean

returns True if the class is abstract

Returns:

  • (Boolean)

112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/sfcc/cim_class.c', line 112

static VALUE is_abstract(VALUE self)
{
  CIMCClass *cimclass;
  CIMCBoolean is;
  if (*cimcEnvType == 'X') {
    CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };    
    sfcc_rb_raise_if_error(status, "Not supported in XML connection");
    return Qnil;
  }
  Data_Get_Struct(self, CIMCClass, cimclass);
  is = cimclass->ft->isAbstract(cimclass);
  return is ? Qtrue : Qfalse;
}

#association?Boolean

returns True if the class is an association

Returns:

  • (Boolean)

91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/sfcc/cim_class.c', line 91

static VALUE is_association(VALUE self)
{
  CIMCClass *cimclass;
  CIMCBoolean is;
  if (*cimcEnvType == 'X') {
    CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };    
    sfcc_rb_raise_if_error(status, "Not supported in XML connection");
    return Qnil;
  }
  Data_Get_Struct(self, CIMCClass, cimclass);
  is = cimclass->ft->isAssociation(cimclass);
  return is ? Qtrue : Qfalse;
}

#nameString

gets the class name

Returns:


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'ext/sfcc/cim_class.c', line 18

static VALUE class_name(VALUE self)
{
  CIMCClass *cimclass;
  CIMCString *name;
  CIMCStatus status = { 0 };
  Data_Get_Struct(self, CIMCClass, cimclass);
  name = cimclass->ft->getClassName(cimclass, &status);
  if ( !status.rc )
    return CIMSTR_2_RUBYSTR(name);

  sfcc_rb_raise_if_error(status, "Can't retrieve class name");
  return Qnil;
}

#do(|name, data|) ⇒ Object

end

enumerates properties yielding the property name and its Cim::Data


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'ext/sfcc/cim_class.c', line 179

static VALUE each_property(VALUE self)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  int k=0;
  int num_props=0;
  CIMCString *property_name;
  CIMCData data;
  Data_Get_Struct(self, CIMCClass, ptr);

  num_props = ptr->ft->getPropertyCount(ptr, &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getPropertyAt(ptr, k, &property_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (property_name ? rb_str_intern(rb_str_new2(property_name->ft->getCharPtr(property_name, NULL))) : Qnil), Sfcc_wrap_cim_data(&data));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve property #%d", k);
      }
      if (property_name) property_name->ft->release(property_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve property count");
  }
  return Qnil;
}

#each_property_qualifier(property_name) ⇒ Object

end

enumerates properties yielding the property qualifier name and its Cim::Data


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'ext/sfcc/cim_class.c', line 326

static VALUE each_property_qualifier(VALUE self, VALUE property_name)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  int k=0;
  int num_props=0;
  CIMCString *property_qualifier_name;
  CIMCData data;
  Data_Get_Struct(self, CIMCClass, ptr);

  num_props = ptr->ft->getPropQualifierCount(ptr, to_charptr(property_name), &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getPropQualifierAt(ptr, to_charptr(property_name), k, &property_qualifier_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (property_qualifier_name ? rb_str_intern(rb_str_new2(property_qualifier_name->ft->getCharPtr(property_qualifier_name, NULL))) : Qnil), Sfcc_wrap_cim_data(&data));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier #%d", k);
      }
      if (property_qualifier_name) property_qualifier_name->ft->release(property_qualifier_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve property qualifier count");
  }
  return Qnil;
}

#do(|name, data|) ⇒ Object

end

enumerates properties yielding the qualifier name and its Cim::Data


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'ext/sfcc/cim_class.c', line 252

static VALUE each_qualifier(VALUE self)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  int k=0;
  int num_props=0;
  CIMCString *qualifier_name;
  CIMCData data;
  Data_Get_Struct(self, CIMCClass, ptr);

  num_props = ptr->ft->getQualifierCount(ptr, &status);
  if (!status.rc) {
    for (; k < num_props; ++k) {
      data = ptr->ft->getQualifierAt(ptr, k, &qualifier_name, &status);
      if (!status.rc) {
        rb_yield_values(2, (qualifier_name ? rb_str_intern(rb_str_new2(qualifier_name->ft->getCharPtr(qualifier_name, NULL))) : Qnil), Sfcc_wrap_cim_data(&data));
      }
      else {
        sfcc_rb_raise_if_error(status, "Can't retrieve qualifier #%d", k);
      }
      if (qualifier_name) qualifier_name->ft->release(qualifier_name);
    }
  }
  else {
    sfcc_rb_raise_if_error(status, "Can't retrieve qualifier count");
  }
  return Qnil;
}

#indication?Boolean

returns True if the class is an indication

Returns:

  • (Boolean)

133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'ext/sfcc/cim_class.c', line 133

static VALUE is_indication(VALUE self)
{
  CIMCClass *cimclass;
  CIMCBoolean is;
  if (*cimcEnvType == 'X') {
    CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };    
    sfcc_rb_raise_if_error(status, "Not supported in XML connection");
    return Qnil;
  }
  Data_Get_Struct(self, CIMCClass, cimclass);
  is = cimclass->ft->isIndication(cimclass);
  return is ? Qtrue : Qfalse;
}

#keysArray

gets the list of keys

Returns:

  • (Array)

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/sfcc/cim_class.c', line 63

static VALUE keys(VALUE self)
{
  VALUE ret;
  CIMCClass *cimclass;
  CIMCArray *keylist;
  
  if (*cimcEnvType == 'X') {
    CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };    
    sfcc_rb_raise_if_error(status, "Not supported in XML connection");
    return Qnil;
  }
  Data_Get_Struct(self, CIMCClass, cimclass);
  keylist = cimclass->ft->getKeyList(cimclass);
  if (!keylist)
    return Qnil;
  
  ret = sfcc_cimcarray_to_rubyarray(keylist, Qnil);
  keylist->ft->release(keylist);
  return ret;
}

#propertiesObject

properties => Hash

return a hash with all properties


11
12
13
14
15
# File 'lib/sfcc/class.rb', line 11

def properties
  ret = {}
  each_property { |key, value| ret[key] = value }
  ret
end

#property(name) ⇒ Cim::Data

gets a named property

Returns:


154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'ext/sfcc/cim_class.c', line 154

static VALUE property(VALUE self, VALUE name)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  CIMCData data;
  memset(&status, 0, sizeof(CIMCStatus));
  Data_Get_Struct(self, CIMCClass, ptr);
  data = ptr->ft->getProperty(ptr, to_charptr(name), &status);
  if ( !status.rc )
    return Sfcc_wrap_cim_data(&data);

  sfcc_rb_raise_if_error(status, "Can't retrieve property '%s'", to_charptr(name));
  return Qnil;
}

#property_countInteger

Gets the number of properties contained in this class

Returns:

  • (Integer)

214
215
216
217
218
219
# File 'ext/sfcc/cim_class.c', line 214

static VALUE property_count(VALUE self)
{
  CIMCClass *ptr;
  Data_Get_Struct(self, CIMCClass, ptr);
  return UINT2NUM(ptr->ft->getPropertyCount(ptr, NULL));
}

#property_qualifier(property_name, qualifier_name) ⇒ Cim::Data

gets a named property qualifier

Returns:


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'ext/sfcc/cim_class.c', line 300

static VALUE property_qualifier(VALUE self, VALUE property_name, VALUE qualifier_name)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  CIMCData data;
  memset(&status, 0, sizeof(CIMCStatus));
  Data_Get_Struct(self, CIMCClass, ptr);
  data = ptr->ft->getPropQualifier(ptr, to_charptr(property_name),
                                        to_charptr(qualifier_name), &status);
  if ( !status.rc )
    return Sfcc_wrap_cim_data(&data);

  sfcc_rb_raise_if_error(status, "Can't retrieve property_qualifier '%s'", to_charptr(qualifier_name));
  return Qnil;
}

#property_qualifier_count(property_name) ⇒ Integer

Gets the number of qualifiers contained in this property

Returns:

  • (Integer)

361
362
363
364
365
366
# File 'ext/sfcc/cim_class.c', line 361

static VALUE property_qualifier_count(VALUE self, VALUE property_name)
{
  CIMCClass *ptr;
  Data_Get_Struct(self, CIMCClass, ptr);
  return UINT2NUM(ptr->ft->getPropQualifierCount(ptr, to_charptr(property_name), NULL));
}

#property_qualifiers(property_name) ⇒ Object

property_qualifiers(property_name) => Hash

return a hash with all qualifiers for property_name


29
30
31
32
33
# File 'lib/sfcc/class.rb', line 29

def property_qualifiers(property_name)
  ret = {}
  each_property_qualifier(property_name) { |key, value| ret[key] = value }
  ret
end

#qualifier(name) ⇒ Cim::Data

gets a named qualifier

Returns:


227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'ext/sfcc/cim_class.c', line 227

static VALUE qualifier(VALUE self, VALUE name)
{
  CIMCClass *ptr;
  CIMCStatus status = { 0 };
  CIMCData data;
  memset(&status, 0, sizeof(CIMCStatus));
  Data_Get_Struct(self, CIMCClass, ptr);
  data = ptr->ft->getQualifier(ptr, to_charptr(name), &status);
  if ( !status.rc )
    return Sfcc_wrap_cim_data(&data);

  sfcc_rb_raise_if_error(status, "Can't retrieve qualifier '%s'", to_charptr(name));
  return Qnil;
}

#qualifier_countInteger

Gets the number of qualifiers in this class

Returns:

  • (Integer)

287
288
289
290
291
292
# File 'ext/sfcc/cim_class.c', line 287

static VALUE qualifier_count(VALUE self)
{
  CIMCClass *ptr;
  Data_Get_Struct(self, CIMCClass, ptr);
  return UINT2NUM(ptr->ft->getQualifierCount(ptr, NULL));
}

#qualifiersObject

qualifiers => Hash

return a hash with all qualifiers


20
21
22
23
24
# File 'lib/sfcc/class.rb', line 20

def qualifiers
  ret = {}
  each_qualifier { |key, value| ret[key] = value }
  ret
end

#superclass_nameString

gets the superclass name

Returns:


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'ext/sfcc/cim_class.c', line 38

static VALUE superclass_name(VALUE self)
{
  CIMCClass *cimclass;
  const char *classname;
  if (*cimcEnvType == 'X') {
    CIMCStatus status = { CIMC_RC_ERR_NOT_SUPPORTED, NULL };    
    sfcc_rb_raise_if_error(status, "Not supported in XML connection");
    return Qnil;
  }
  Data_Get_Struct(self, CIMCClass, cimclass);
  classname = cimclass->ft->getCharSuperClassName(cimclass);
  if (!classname) {
    rb_raise(rb_eArgError, "Cannot retrieve superclass name");
    return Qnil;
  }
  return rb_str_new2(classname);
}