Changeset 3305 for branches/nanovis2/lang/ruby/Ruby_Rappture.cc
- Timestamp:
- Feb 18, 2013 2:32:14 PM (11 years ago)
- Location:
- branches/nanovis2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/nanovis2
- Property svn:mergeinfo changed
/trunk merged: 3174,3177-3182,3184-3199,3275-3282,3285,3287
- Property svn:mergeinfo changed
-
branches/nanovis2/lang/ruby/Ruby_Rappture.cc
r1100 r3305 5 5 * ====================================================================== 6 6 * AUTHOR: Benjamin Haley, Purdue University 7 * Copyright (c) 200 8 Purdue Research Foundation7 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 8 8 * 9 9 * See the file "license.terms" for information on usage and … … 27 27 #include "RpUnits.h" /* RpUnits::convert() */ 28 28 #include "ruby.h" /* VALUE, rb_*(), Data_*_Struct(), NUM2INT(), 29 INT2NUM(), NUM2DBL(), S TR2CSTR(), ANYARGS */29 INT2NUM(), NUM2DBL(), Str2Cstr(), ANYARGS */ 30 30 31 31 /****************************************************************************** … … 40 40 41 41 extern "C" void Init_Rappture(void); 42 43 static std::string 44 GetStdString(VALUE value) 45 { 46 VALUE strValue; 47 48 strValue = StringValue(value); 49 return std::string(RSTRING_PTR(strValue), RSTRING_LEN(strValue)); 50 } 51 52 static const char * 53 GetString(VALUE value) 54 { 55 return StringValuePtr(value); 56 } 42 57 43 58 /****************************************************************************** … … 61 76 { 62 77 RpLibrary *lib; 63 std::string str;78 std::string result; 64 79 65 80 /* Extract the pointer to the Rappture object, lib, from the Ruby object, … … 67 82 Data_Get_Struct(self, RpLibrary, lib); 68 83 84 69 85 /* Read the data from path in lib as a C++ std::string. */ 70 str = lib->getString(STR2CSTR(path));86 result = lib->getString(GetStdString(path)); 71 87 72 88 /* Return a Ruby VALUE */ 73 return rb_str_new2( str.c_str());89 return rb_str_new2(result.c_str()); 74 90 75 91 } /* end RbRp_GetString */ … … 95 111 96 112 /* Read the data from path in lib as a C++ std::string. */ 97 buf = lib->getData( STR2CSTR(path));113 buf = lib->getData(GetStdString(path)); 98 114 99 115 /* Return a Ruby VALUE */ … … 142 158 { 143 159 case T_STRING: 144 lib->put(STR2CSTR(path), STR2CSTR(value), "", NUM2INT(append)); 160 /* Read the data from path in lib as a C++ std::string. */ 161 lib->put(GetStdString(path), GetStdString(value), "", 162 NUM2INT(append)); 145 163 break; 146 164 case T_FIXNUM: 147 165 intVal = NUM2INT(value); 148 lib->putData( STR2CSTR(path), (const char *)&intVal, sizeof(int),166 lib->putData(GetStdString(path), (const char *)&intVal, sizeof(int), 149 167 NUM2INT(append)); 150 168 break; 151 169 case T_FLOAT: 152 lib->put( STR2CSTR(path), NUM2DBL(value), "", NUM2INT(append));170 lib->put(GetStdString(path), NUM2DBL(value), "", NUM2INT(append)); 153 171 break; 154 172 default: … … 156 174 rb_raise(rb_eRuntimeError, 157 175 "Unable to put object %s to Rappture: unknown type", 158 STR2CSTR(rbStrName));176 GetString(rbStrName)); 159 177 #endif 160 178 break; … … 199 217 if (T_STRING == TYPE(value)) 200 218 { 201 long int nbytes; 202 char *bytes = rb_str2cstr(value, &nbytes); 203 204 lib->putData(STR2CSTR(path), bytes, nbytes, NUM2INT(append)); 219 VALUE strValue; 220 221 strValue = StringValue(value); 222 lib->putData(GetStdString(path), 223 RSTRING_PTR(strValue), RSTRING_LEN(strValue), 224 NUM2INT(append)); 205 225 } 206 226 #ifdef RAISE_EXCEPTIONS … … 209 229 rb_raise(rb_eRuntimeError, 210 230 "Unable to put data \"%s\" to Rappture: unknown type", 211 STR2CSTR(rbStrName));231 GetString(rbStrName)); 212 232 } 213 233 #endif … … 257 277 if (Qtrue == rb_funcall(ft, id_filetest, 1, filename)) /* valid filename */ 258 278 { 259 lib->putFile( STR2CSTR(path), STR2CSTR(filename), NUM2INT(compress),260 279 lib->putFile(GetStdString(path), GetStdString(filename), 280 NUM2INT(compress), NUM2INT(append)); 261 281 } 262 282 #ifdef RAISE_EXCEPTIONS … … 264 284 { 265 285 rb_raise(rb_eRuntimeError, "%s is not a valid file", 266 STR2CSTR(rbStrName));286 GetString(rbStrName)); 267 287 } 268 288 #endif … … 270 290 #ifdef RAISE_EXCEPTIONS 271 291 else 272 rb_raise(rb_eRuntimeError, "Bad file name: %s", STR2CSTR(rbStrName)); 292 rb_raise(rb_eRuntimeError, "Bad file name: %s", 293 GetString(rbStrName)); 273 294 #endif 274 295 … … 360 381 361 382 /* Write the message */ 362 (void)Rappture::Utils::progress(NUM2INT(percent), STR2CSTR(message)); 383 (void)Rappture::Utils::progress(NUM2INT(percent), 384 GetString(message)); 363 385 364 386 /* Return a Ruby VALUE */ … … 385 407 { 386 408 VALUE retVal = Qnil; 387 RpLibrary *lib;388 409 std::string strRetVal; 389 410 int result; 390 411 391 /* Extract the pointer to the Rappture object, lib, from the Ruby392 object, self */393 Data_Get_Struct(self, RpLibrary, lib);394 395 412 /* Convert */ 396 strRetVal = RpUnits::convert( STR2CSTR(fromVal), STR2CSTR(toUnitsName),397 413 strRetVal = RpUnits::convert(GetStdString(fromVal), 414 GetStdString(toUnitsName), NUM2INT(showUnits), &result); 398 415 /* Return value */ 399 416 if (0 == result) … … 409 426 else 410 427 rb_raise(rb_eRuntimeError, "Unable to convert \"%s\" to \"%s\"", 411 STR2CSTR(fromVal), STR2CSTR(toUnitsName));428 GetString(fromVal), GetString(toUnitsName)); 412 429 #endif 413 430 return retVal; … … 473 490 { 474 491 /* Create the Rappture object from the XML driver file. */ 475 RpLibrary *lib = new RpLibrary( STR2CSTR(driver));492 RpLibrary *lib = new RpLibrary(GetStdString(driver)); 476 493 477 494 /* Data_Wrap_Struct() creates a new Ruby object which associates the
Note: See TracChangeset
for help on using the changeset viewer.