Changeset 1018 for trunk/src/core
- Timestamp:
- Jun 8, 2008, 6:24:34 PM (16 years ago)
- Location:
- trunk/src/core
- Files:
-
- 33 added
- 5 edited
- 27 copied
- 12 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpBuffer.cc
r1017 r1018 5 5 * AUTHOR: Derrick Kearney, Purdue University 6 6 * 7 * Copyright (c) 2004-200 8Purdue Research Foundation7 * Copyright (c) 2004-2007 Purdue Research Foundation 8 8 * ---------------------------------------------------------------------- 9 9 * See the file "license.terms" for information on usage and 10 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 12 * 13 * This code is based on the Tcl_DString facility included in the 14 * Tcl source release, which includes the following copyright: 15 * 16 * Copyright (c) 1987-1993 The Regents of the University of California. 17 * Copyright (c) 1994-1998 Sun Microsystems, Inc. 18 * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. 19 * 20 * This software is copyrighted by the Regents of the University of 21 * California, Sun Microsystems, Inc., Scriptics Corporation, 22 * and other parties. The following terms apply to all files associated 23 * with the software unless explicitly disclaimed in individual files. 24 * 25 * The authors hereby grant permission to use, copy, modify, distribute, 26 * and license this software and its documentation for any purpose, provided 27 * that existing copyright notices are retained in all copies and that this 28 * notice is included verbatim in any distributions. No written agreement, 29 * license, or royalty fee is required for any of the authorized uses. 30 * Modifications to this software may be copyrighted by their authors 31 * and need not follow the licensing terms described here, provided that 32 * the new terms are clearly indicated on the first page of each file where 33 * they apply. 34 * 35 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY 36 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 37 * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY 38 * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE 39 * POSSIBILITY OF SUCH DAMAGE. 40 * 41 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 42 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 43 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE 44 * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE 45 * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 46 * MODIFICATIONS. 47 * 48 * GOVERNMENT USE: If you are acquiring this software on behalf of the 49 * U.S. government, the Government shall have only "Restricted Rights" 50 * in the software and related documentation as defined in the Federal· 51 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you 52 * are acquiring the software on behalf of the Department of Defense, the 53 * software shall be classified as "Commercial Computer Software" and the 54 * Government shall have only "Restricted Rights" as defined in Clause 55 * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the 56 * authors grant the U.S. Government and others acting in its behalf 57 * permission to use and distribute the software in accordance with the 58 * terms specified in this license.· 59 * 11 60 * ====================================================================== 12 61 */ … … 27 76 28 77 /** 78 * Construct an empty SimpleBuffer. 79 */ 80 SimpleBuffer::SimpleBuffer() 81 { 82 bufferInit(); 83 } 84 85 86 /** 87 * Construct a SimpleBuffer loaded with initial data. 88 * 89 * @param bytes pointer to bytes being stored. 90 * @param nbytes number of bytes being stored. 91 */ 92 SimpleBuffer::SimpleBuffer(const char* bytes, int nbytes) 93 { 94 bufferInit(); 95 append(bytes,nbytes); 96 } 97 98 99 /** 100 * Copy constructor 101 * @param SimpleBuffer object to copy 102 */ 103 SimpleBuffer::SimpleBuffer(const SimpleBuffer& b) 104 { 105 bufferInit(); 106 append(b.bytes(),b.size()); 107 } 108 109 110 /** 111 * Assignment operator 112 * @param SimpleBuffer object to copy 113 */ 114 SimpleBuffer& 115 SimpleBuffer::operator=(const SimpleBuffer& b) 116 { 117 bufferFree(); 118 bufferInit(); 119 append(b.bytes(),b.size()); 120 return *this; 121 } 122 123 124 /** 125 * Operator + 126 * @param SimpleBuffer object to add 127 */ 128 SimpleBuffer 129 SimpleBuffer::operator+(const SimpleBuffer& b) const 130 { 131 SimpleBuffer newBuffer(*this); 132 newBuffer.operator+=(b); 133 return newBuffer; 134 } 135 136 137 /** 138 * Operator += 139 * @param SimpleBuffer object to add 140 */ 141 SimpleBuffer& 142 SimpleBuffer::operator+=(const SimpleBuffer& b) 143 { 144 append(b.bytes(),b.size()); 145 return *this; 146 } 147 148 149 /** 150 * Destructor 151 */ 152 SimpleBuffer::~SimpleBuffer() 153 { 154 bufferFree(); 155 } 156 157 158 /** 159 * Get the bytes currently stored in the buffer. These bytes can 160 * be stored, and used later to construct another Buffer to 161 * decode the information. 162 * 163 * @return Pointer to the bytes in the buffer. 164 */ 165 const char* 166 SimpleBuffer::bytes() const 167 { 168 return _buf; 169 } 170 171 172 /** 173 * Get the number of bytes currently stored in the buffer. 174 * @return Number of the bytes used in the buffer. 175 */ 176 unsigned int 177 SimpleBuffer::size() const 178 { 179 return _size; 180 } 181 182 183 /** 184 * Clear the buffer, making it empty. 185 * @return Reference to this buffer. 186 */ 187 SimpleBuffer& 188 SimpleBuffer::clear() 189 { 190 bufferFree(); 191 bufferInit(); 192 193 return *this; 194 } 195 196 197 /** 198 * Append bytes to the end of this buffer 199 * @param Buffer object to copy 200 * @return Reference to this buffer. 201 */ 202 int 203 SimpleBuffer::append(const char* bytes, int nbytes) 204 { 205 unsigned int newSize = 0; 206 char *newBuffer = NULL; 207 208 // User specified NULL buffer to append 209 if ( (bytes == NULL) && (nbytes < 1) ) { 210 return 0; 211 } 212 213 if (nbytes == -1) { 214 // user signaled null terminated string 215 nbytes = strlen(bytes); 216 } 217 218 if (nbytes <= 0) { 219 // no data written, invalid option 220 return nbytes; 221 } 222 223 // Empty internal buffer, make sure its properly initialized. 224 if (_buf == NULL) { 225 bufferInit(); 226 } 227 228 newSize = (unsigned int)(_size + nbytes); 229 230 // ensure that our smallest buffer is 200 bytes 231 if (newSize < (RP_BUFFER_MIN_SIZE/2)) { 232 newSize = (RP_BUFFER_MIN_SIZE/2); 233 } 234 235 /* 236 * Allocate a larger buffer for the string if the current one isn't 237 * large enough. Allocate extra space in the new buffer so that there 238 * will be room to grow before we have to allocate again. 239 */ 240 241 if (newSize >= _spaceAvl) { 242 _spaceAvl = newSize * 2; 243 newBuffer = new char[_spaceAvl]; 244 if (newBuffer == NULL) { 245 // return memory error 246 return -1; 247 } 248 if (_buf != NULL) { 249 memcpy((void*) newBuffer, (void*) _buf, (size_t) _size); 250 delete [] _buf; 251 _buf = NULL; 252 } 253 _buf = newBuffer; 254 } 255 256 memcpy((void*) (_buf + _size), (void*) bytes, (size_t) nbytes); 257 258 _size = _size + (unsigned int) nbytes; 259 260 return nbytes; 261 } 262 263 264 /** 265 * Read data from the buffer into a memory location provided by caller 266 * @param Pointer locating where to place read bytes. 267 * @param Size of the memory location. 268 * @return Number of bytes written to memory location 269 */ 270 int 271 SimpleBuffer::read(const char* bytes, int nbytes) 272 { 273 unsigned int bytesRead = 0; 274 275 // SimpleBuffer is empty. 276 if (_buf == NULL) { 277 return 0; 278 } 279 280 // User specified NULL buffer. 281 if (bytes == NULL) { 282 return 0; 283 } 284 285 // User specified negative buffer size 286 if (nbytes <= 0) { 287 return 0; 288 } 289 290 // make sure we don't read off the end of our buffer 291 if ( (_pos + nbytes) >= _size ) { 292 bytesRead = (_size - _pos); 293 } 294 else { 295 bytesRead = (unsigned int) nbytes; 296 } 297 298 if (bytesRead <= 0) { 299 return 0; 300 } 301 302 if (bytesRead > 0) { 303 memcpy((void*) bytes, (void*) (_buf+_pos), (size_t) bytesRead); 304 } 305 306 _pos = (_pos + bytesRead); 307 308 return (int)bytesRead; 309 } 310 311 312 /** 313 * Set buffer position indicator to spot within the buffer 314 * @param Offset from whence location in buffer. 315 * @param Place from where offset is added or subtracted. 316 * @return 0 on success, anything else is failure 317 */ 318 int 319 SimpleBuffer::seek(int offset, int whence) 320 { 321 int retVal = 0; 322 323 if (_buf == NULL) { 324 return -1 ; 325 } 326 327 if (whence == SEEK_SET) { 328 if (offset < 0) { 329 /* dont go off the beginning of data */ 330 _pos = 0; 331 } 332 else if (offset >= (int)_size) { 333 /* dont go off the end of data */ 334 _pos = _size - 1; 335 } 336 else { 337 _pos = (unsigned int)(_pos + offset); 338 } 339 } 340 else if (whence == SEEK_CUR) { 341 if ( (_pos + offset) < 0) { 342 /* dont go off the beginning of data */ 343 _pos = 0; 344 } 345 else if ((_pos + offset) >= _size) { 346 /* dont go off the end of data */ 347 _pos = _size - 1; 348 } 349 else { 350 _pos = (unsigned int)(_pos + offset); 351 } 352 } 353 else if (whence == SEEK_END) { 354 if (offset <= (-1*((int)_size))) { 355 /* dont go off the beginning of data */ 356 _pos = 0; 357 } 358 else if (offset >= 0) { 359 /* dont go off the end of data */ 360 _pos = _size - 1; 361 } 362 else { 363 _pos = (unsigned int)((_size - 1) + offset); 364 } 365 } 366 else { 367 retVal = -1; 368 } 369 370 return retVal; 371 } 372 373 374 /** 375 * Tell caller the offset of the position indicator from the start of buffer 376 * @return Number of bytes the position indicator is from start of buffer 377 */ 378 int 379 SimpleBuffer::tell() 380 { 381 return (int)_pos; 382 } 383 384 385 /** 386 * Read data from the buffer into a memory location provided by caller 387 */ 388 SimpleBuffer& 389 SimpleBuffer::rewind() 390 { 391 _pos = 0; 392 return *this; 393 } 394 395 396 /** 397 * Tell if the last file like operation (ie. read()) was successful 398 * or if there was a failure like eof, or bad memory 399 * @return True or false boolean value 400 */ 401 bool 402 SimpleBuffer::good() const 403 { 404 return (_fileState); 405 } 406 407 408 /** 409 * Tell if the last file like operation (ie. read()) failed 410 * Opposite of good() 411 * @return True or false boolean value 412 */ 413 bool 414 SimpleBuffer::bad() const 415 { 416 return (!_fileState); 417 } 418 419 420 /** 421 * Tell if the position flag is at the end of the buffer 422 * @return True or false boolean value 423 */ 424 bool 425 SimpleBuffer::eof() const 426 { 427 return (_pos >= _size); 428 } 429 430 431 /** 432 * Move the data from this SimpleBuffer to the SimpleBuffer provided by 433 * the caller. All data except the _pos is moved and this SimpleBuffer is 434 * re-initialized with bufferInit(). 435 * @param SimpleBuffer to move the information to 436 * @return reference to this SimpleBuffer object. 437 */ 438 SimpleBuffer& 439 SimpleBuffer::move(SimpleBuffer& b) 440 { 441 bufferFree(); 442 443 _buf = b._buf; 444 _pos = b._pos; 445 _size = b._size; 446 _spaceAvl = b._spaceAvl; 447 _fileState = b._fileState; 448 449 b.bufferInit(); 450 451 return *this; 452 } 453 454 455 /** 456 * Initializes a dynamic buffer, discarding any previous contents 457 * of the buffer. bufferFree() should have been called already 458 * if the dynamic buffer was previously in use. 459 */ 460 void 461 SimpleBuffer::bufferInit() 462 { 463 _buf = NULL; 464 _pos = 0; 465 _size = 0; 466 _spaceAvl = 0; 467 _fileState = true; 468 } 469 470 471 /** 472 * Frees up any memory allocated for the dynamic buffer and 473 * reinitializes the buffer to an empty state. 474 */ 475 void 476 SimpleBuffer::bufferFree() 477 { 478 if (_buf != NULL) { 479 delete [] _buf; 480 _buf = NULL; 481 } 482 bufferInit(); 483 } 484 485 486 /** 29 487 * Construct an empty Buffer. 30 488 */ 31 489 Buffer::Buffer() 32 490 : SimpleBuffer(), 33 _level(6),34 _compressionType(RPCOMPRESS_GZIP),35 _windowBits(15)36 {}37 38 39 /**40 * Construct an empty Buffer of specified size.41 */42 Buffer::Buffer(int nbytes)43 : SimpleBuffer(nbytes),44 491 _level(6), 45 492 _compressionType(RPCOMPRESS_GZIP), -
trunk/src/core/RpBuffer.h
r1017 r1018 5 5 * AUTHOR: Derrick Kearney, Purdue University 6 6 * 7 * Copyright (c) 2004-200 8Purdue Research Foundation7 * Copyright (c) 2004-2007 Purdue Research Foundation 8 8 * ---------------------------------------------------------------------- 9 9 * See the file "license.terms" for information on usage and 10 10 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 11 * ====================================================================== 12 * 13 * This code is based on the Tcl_DString facility included in the 14 * Tcl source release, which includes the following copyright: 15 * 16 * Copyright (c) 1987-1993 The Regents of the University of California. 17 * Copyright (c) 1994-1998 Sun Microsystems, Inc. 18 * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. 19 * 20 * This software is copyrighted by the Regents of the University of 21 * California, Sun Microsystems, Inc., Scriptics Corporation, 22 * and other parties. The following terms apply to all files associated 23 * with the software unless explicitly disclaimed in individual files. 24 * 25 * The authors hereby grant permission to use, copy, modify, distribute, 26 * and license this software and its documentation for any purpose, provided 27 * that existing copyright notices are retained in all copies and that this 28 * notice is included verbatim in any distributions. No written agreement, 29 * license, or royalty fee is required for any of the authorized uses. 30 * Modifications to this software may be copyrighted by their authors 31 * and need not follow the licensing terms described here, provided that 32 * the new terms are clearly indicated on the first page of each file where 33 * they apply. 34 * 35 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY 36 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 37 * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY 38 * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE 39 * POSSIBILITY OF SUCH DAMAGE. 40 * 41 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 42 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 43 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE 44 * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE 45 * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 46 * MODIFICATIONS. 47 * 48 * GOVERNMENT USE: If you are acquiring this software on behalf of the 49 * U.S. government, the Government shall have only "Restricted Rights" 50 * in the software and related documentation as defined in the Federal· 51 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you 52 * are acquiring the software on behalf of the Department of Defense, the 53 * software shall be classified as "Commercial Computer Software" and the 54 * Government shall have only "Restricted Rights" as defined in Clause 55 * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the 56 * authors grant the U.S. Government and others acting in its behalf 57 * permission to use and distribute the software in accordance with the 58 * terms specified in this license.· 59 * 11 60 * ====================================================================== 12 61 */ … … 15 64 #define RAPPTURE_BUFFER_H 16 65 17 #include "Outcome.h" 18 #include "RpSimpleBuffer.h" 66 #define RP_BUFFER_MIN_SIZE 200 67 68 #include "RpOutcome.h" 19 69 20 70 #ifdef __cplusplus … … 29 79 namespace Rappture { 30 80 81 class SimpleBuffer { 82 public: 83 SimpleBuffer(); 84 SimpleBuffer(const char* bytes, int nbytes=-1); 85 SimpleBuffer(const SimpleBuffer& b); 86 SimpleBuffer& operator=(const SimpleBuffer& b); 87 SimpleBuffer operator+(const SimpleBuffer& b) const; 88 SimpleBuffer& operator+=(const SimpleBuffer& b); 89 virtual ~SimpleBuffer(); 90 91 const char* bytes() const; 92 unsigned int size() const; 93 94 SimpleBuffer& clear(); 95 int append(const char* bytes, int nbytes=-1); 96 int read(const char* bytes, int nbytes); 97 int seek(int offset, int whence); 98 int tell(); 99 SimpleBuffer& rewind(); 100 101 bool good() const; 102 bool bad() const; 103 bool eof() const; 104 105 SimpleBuffer& move(SimpleBuffer& b); 106 107 protected: 108 109 void bufferInit(); 110 void bufferFree(); 111 112 private: 113 114 /// Pointer to the memory that holds our buffer's data 115 char* _buf; 116 117 /// Position offset within the buffer's memory 118 unsigned int _pos; 119 120 /// Size of the used memory in the buffer 121 unsigned int _size; 122 123 /// Total space available in the buffer 124 unsigned int _spaceAvl; 125 126 /// State of the last file like operation. 127 bool _fileState; 128 }; 31 129 32 130 /** … … 40 138 public: 41 139 Buffer(); 42 Buffer(int nbytes);43 140 Buffer(const char* bytes, int nbytes=-1); 44 141 Buffer(const Buffer& buffer); -
trunk/src/core/RpEncode.h
r1017 r1018 17 17 // #include "rappture.h" 18 18 #include "RpBuffer.h" 19 #include " Outcome.h"19 #include "RpOutcome.h" 20 20 21 21 #define RPENC_Z 1 -
trunk/src/core/RpLibrary.cc
r962 r1018 1449 1449 1450 1450 RpLibrary& 1451 RpLibrary::childCount ( std::string path, 1452 int* childCount ) 1453 { 1454 scew_element* parentNode; 1455 int myChildCount = 0; 1456 1451 RpLibrary::childCount(std::string path, int* childCount) 1452 { 1457 1453 if (this->root) { 1458 1454 scew_element* parentNode; 1455 int myChildCount = 0; 1456 1457 parentNode = NULL; 1459 1458 if (path.empty()) { 1460 1459 // an empty path uses the current RpLibrary as parent … … 1469 1468 *childCount = myChildCount; 1470 1469 } 1471 1472 } 1473 1470 } 1474 1471 return *this; 1475 1472 } -
trunk/src/core/RpLibrary.h
r759 r1018 31 31 #include <list> 32 32 #include "RpBuffer.h" 33 #include " Outcome.h"33 #include "RpOutcome.h" 34 34 35 35 /* indentation size (in whitespaces) */ -
trunk/src/core/RpOutcome.cc
r1017 r1018 1 1 /* 2 * ====================================================================== 3 * Rappture::Outcome 4 * 5 * AUTHOR: Michael McLennan, Purdue University 6 * Copyright (c) 2004-2007 Purdue Research Foundation 2 7 * ---------------------------------------------------------------------- 3 * Rappture::Outcome4 * This object represents the result of any Rappture call. It acts5 * like a boolean, so it can be tested for success/failure. But6 * it can also contain information about failure, including a trace7 * back of messages indicating the cause.8 *9 * ======================================================================10 * AUTHOR: Michael McLennan, Purdue University11 * Copyright (c) 2004-2006 Purdue Research Foundation12 *13 8 * See the file "license.terms" for information on usage and 14 9 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. … … 16 11 */ 17 12 #include "RpOutcome.h" 18 13 #include <stdarg.h> 19 14 using namespace Rappture; 20 15 21 Outcome::Outcome(const char *errmsg) 22 : _status(0), 16 /** 17 * Create a negative outcome, with the given error message. 18 */ 19 Outcome::Outcome(const char *errmsg) : 20 _status(0), 23 21 _remarkPtr(NULL), 24 22 _contextPtr(NULL) … … 29 27 } 30 28 31 Outcome::Outcome(const Outcome& oc) 32 : _status(oc._status), 29 /// Copy constructor 30 Outcome::Outcome(const Outcome& oc) : 31 _status(oc._status), 33 32 _remarkPtr(oc._remarkPtr), 34 33 _contextPtr(oc._contextPtr) … … 36 35 } 37 36 37 /// Assignment operator 38 38 Outcome& 39 39 Outcome::operator=(const Outcome& oc) … … 45 45 } 46 46 47 /// Destructor 48 Outcome::~Outcome() 49 {} 50 51 /** 52 * Assign an error condition to the outcome. 53 */ 47 54 Outcome& 48 55 Outcome::error(const char* errmsg, int status) … … 55 62 56 63 Outcome& 64 Outcome::AddError(const char* format, ...) 65 { 66 char stackSpace[1024]; 67 va_list lst; 68 size_t n; 69 char *bufPtr; 70 71 va_start(lst, format); 72 bufPtr = stackSpace; 73 n = vsnprintf(bufPtr, 1024, format, lst); 74 if (n >= 1024) { 75 bufPtr = (char *)malloc(n); 76 vsnprintf(bufPtr, n, format, lst); 77 } 78 if (_remarkPtr.isNull()) { 79 _remarkPtr = Ptr<std::string>(new std::string(bufPtr)); 80 } else { 81 _remarkPtr->append("\n"); 82 _remarkPtr->append(bufPtr); 83 } 84 _contextPtr.clear(); 85 _status = 1; /* Set to error */ 86 if (bufPtr != stackSpace) { 87 free(bufPtr); 88 } 89 return *this; 90 } 91 92 /** 93 * Clear the status of this outcome. 94 */ 95 Outcome& 57 96 Outcome::clear() 58 97 { … … 63 102 } 64 103 104 /** 105 * Returns the status of this outcome as an integer. 106 * As in Unix systems, 0 = okay. 107 */ 65 108 Outcome::operator int() const 66 109 { … … 68 111 } 69 112 113 /** 114 * For !error tests. 115 */ 70 116 int 71 117 Outcome::operator!() const … … 74 120 } 75 121 122 /** 123 * Use this to concatenate many different outcomes. 124 */ 76 125 Outcome& 77 126 Outcome::operator&=(Outcome oc) … … 85 134 } 86 135 136 /** 137 * Query the error remark from an outcome. 138 */ 87 139 std::string 88 140 Outcome::remark() const … … 94 146 } 95 147 148 /** 149 * Add information to the context stack for an outcome. 150 */ 96 151 Outcome& 97 152 Outcome::addContext(const char *rem) … … 105 160 } 106 161 162 /** 163 * Query the context stack from an outcome. 164 */ 107 165 std::string 108 166 Outcome::context() const -
trunk/src/core/RpOutcome.h
r1017 r1018 1 1 /* 2 * ====================================================================== 3 * Rappture::Outcome 4 * 5 * AUTHOR: Michael McLennan, Purdue University 6 * Copyright (c) 2004-2007 Purdue Research Foundation 2 7 * ---------------------------------------------------------------------- 3 * Rappture::Outcome4 * This object represents the result of any Rappture call. It acts5 * like a boolean, so it can be tested for success/failure. But6 * it can also contain information about failure, including a trace7 * back of messages indicating the cause.8 *9 * ======================================================================10 * AUTHOR: Michael McLennan, Purdue University11 * Copyright (c) 2004-2006 Purdue Research Foundation12 *13 8 * See the file "license.terms" for information on usage and 14 9 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. … … 19 14 20 15 #include <string> 21 #include "RpPtr.h"16 #include <RpPtr.h> 22 17 23 18 namespace Rappture { 24 19 20 /** 21 * This object represents the result of any Rappture call. It acts 22 * like a boolean, so it can be tested for success/failure. But 23 * it can also contain information about failure, including a trace 24 * back of messages indicating the cause. 25 */ 25 26 class Outcome { 26 27 public: … … 28 29 Outcome(const Outcome& status); 29 30 Outcome& operator=(const Outcome& status); 31 virtual ~Outcome(); 30 32 31 33 virtual Outcome& error(const char* errmsg, int status=1); … … 41 43 42 44 private: 43 int _status; // overall pass/fail status 44 Ptr<std::string>_remarkPtr; // error message 45 Ptr<std::string>_contextPtr; // stack trace 45 /// overall pass/fail status 46 int _status; 47 48 /// error message 49 Ptr<std::string>_remarkPtr; 50 51 /// stack trace 52 Ptr<std::string>_contextPtr; 46 53 }; 47 54 -
trunk/src/core/RpOutcomeCInterface.cc
r1017 r1018 12 12 */ 13 13 14 #include " Outcome.h"14 #include "RpOutcome.h" 15 15 #include "RpOutcomeCInterface.h" 16 16 #include "RpOutcomeCHelper.h" … … 134 134 RapptureOutcomeCheck(RapptureOutcome* status) 135 135 { 136 return ((int)( *((Rappture::Outcome*)status)));136 return ((int)((Rappture::Outcome*)status->_status)); 137 137 } 138 138 -
trunk/src/core/RpPtr.h
r1017 r1018 1 1 /* 2 * ----------------------------------------------------------------------2 * ====================================================================== 3 3 * Rappture::Ptr<type> 4 * This is a smart pointer with reference counting. Once one of5 * these pointers is constructed with an object of the underlying6 * type, that object becomes property of the pointer. Other7 * pointers can point to the same object. When all such pointers8 * have been destroyed, the underlying object goes away.9 4 * 10 * ======================================================================11 5 * AUTHOR: Michael McLennan, Purdue University 12 6 * Copyright (c) 2004-2006 Purdue Research Foundation 13 * 7 * ---------------------------------------------------------------------- 14 8 * See the file "license.terms" for information on usage and 15 9 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 16 10 * ====================================================================== 17 11 */ 18 #ifndef RAPPTURE_P OINTER_H19 #define RAPPTURE_P OINTER_H12 #ifndef RAPPTURE_PTR_H 13 #define RAPPTURE_PTR_H 20 14 21 15 #include <assert.h> 22 16 23 #ifndef NULL24 # define NULL 025 #endif26 27 17 namespace Rappture { 28 18 29 template <class Type> 19 /** 20 * This is the core of a smart pointer, built to keep a reference 21 * count and do most of the work, so the template class can be lean 22 * and mean. 23 */ 30 24 class PtrCore { 31 25 public: 32 explicit PtrCore( Type* ptr=NULL);26 explicit PtrCore(void* ptr=NULL); 33 27 ~PtrCore(); 34 28 29 void* pointer() const; 30 void attach(); 31 void* detach(); 32 33 private: 35 34 // copying the core is not allowed 36 35 PtrCore(const PtrCore& pc) { assert(0); } 37 PtrCore& operator=(const PtrCore& pc) { assert(0); }36 PtrCore& operator=(const PtrCore& pc) { assert(0); return *this; } 38 37 39 Type* pointer() const; 40 void attach(); 41 void detach(); 42 43 private: 44 Type *_ptr; 38 void *_ptr; 45 39 int _refcount; 46 40 }; 47 41 48 template <class Type> 49 PtrCore<Type>::PtrCore(Type* ptr) 50 : _ptr(ptr), 51 _refcount(1) 52 { 53 } 54 55 template <class Type> 56 PtrCore<Type>::~PtrCore() 57 { 58 assert(_refcount <= 0); 59 } 60 61 template <class Type> 62 Type* 63 PtrCore<Type>::pointer() const 64 { 65 return _ptr; 66 } 67 68 template <class Type> 69 void 70 PtrCore<Type>::attach() 71 { 72 _refcount++; 73 } 74 75 template <class Type> 76 void 77 PtrCore<Type>::detach() 78 { 79 if (--_refcount <= 0 && _ptr != NULL) { 80 delete _ptr; 81 delete this; 82 } 83 } 84 85 42 /** 43 * This is a smart pointer with reference counting. Once one of 44 * these pointers is constructed with an object of the underlying 45 * type, that object becomes property of the pointer. Other 46 * pointers can point to the same object. When all such pointers 47 * have been destroyed, the underlying object goes away. 48 */ 86 49 template <class Type> 87 50 class Ptr { … … 100 63 101 64 private: 102 PtrCore <Type>*_pc;65 PtrCore *_pc; 103 66 }; 104 67 … … 108 71 { 109 72 if (ptr) { 110 _pc = new PtrCore <Type>(ptr);73 _pc = new PtrCore(ptr); 111 74 } 112 75 } … … 125 88 Ptr<Type>::~Ptr() 126 89 { 127 if (_pc) { 128 _pc->detach(); 129 } 90 clear(); 130 91 } 131 92 … … 134 95 Ptr<Type>::operator=(Type* ptr) 135 96 { 136 if (_pc) { 137 _pc->detach(); 138 } 139 _pc = new PtrCore<Type>(ptr); 97 clear(); 98 _pc = new PtrCore(ptr); 99 return *this; 140 100 } 141 101 … … 147 107 ptr._pc->attach(); 148 108 } 149 if (_pc) { 150 _pc->detach(); 151 } 109 clear(); 152 110 _pc = ptr._pc; 153 111 return *this; … … 169 127 { 170 128 if (_pc) { 171 return _pc->pointer();129 return static_cast<Type*>(_pc->pointer()); 172 130 } 173 131 return NULL; … … 179 137 { 180 138 if (_pc) { 181 return _pc->pointer();139 return (Type*)_pc->pointer(); 182 140 } 183 141 return NULL; … … 197 155 { 198 156 if (_pc) { 199 _pc->detach(); 157 Type* ptr = (Type*)_pc->detach(); 158 if (ptr) { 159 // If we get back a pointer, then it is fully detached. 160 // Clean it up. 161 delete ptr; 162 delete _pc; 163 } 200 164 _pc = NULL; 201 165 } … … 204 168 } // namespace Rappture 205 169 206 #endif 170 #endif // RAPPTURE_PTR_H -
trunk/src/core/RpResult.cc
r115 r1018 17 17 #include <stdlib.h> 18 18 #include <time.h> 19 #include <RpLibrary.h> 20 #include <errno.h> 19 21 20 22 void 21 rpResult(PyObject* lib) { 23 rpResult(RpLibrary* lib) 24 { 22 25 char outputFile[100]; 23 char*xtext;26 std::string xtext; 24 27 FILE* fp; 25 28 time_t t; 26 29 27 xtext = rpXml(lib);30 xtext = lib->xml(); 28 31 29 32 // create output filename … … 36 39 return; 37 40 } 38 int fsize = fwrite(xtext, strlen(xtext), sizeof(char), fp); 41 int fsize = fwrite(xtext.c_str(), xtext.length(), sizeof(char), fp); 42 if (fsize != (int)xtext.length()) { 43 fprintf(stderr, "short write: can't save results (err=%d)\n", errno); 44 fclose(fp); 45 return; 46 } 39 47 fclose(fp); 40 41 48 // tell Rappture the file name 42 49 printf("=RAPPTURE-RUN=>%s\n", outputFile); -
trunk/src/core/RpUnitsCInterface.cc
r1017 r1018 14 14 #include "RpUnits.h" 15 15 #include "RpUnitsCInterface.h" 16 17 #ifdef __cplusplus18 extern "C" {19 #endif20 16 21 17 const RpUnits* … … 133 129 } 134 130 135 #ifdef __cplusplus136 }137 #endif -
trunk/src/core/RpUnitsFInterface.cc
r1017 r1018 33 33 34 34 if (basisName && *basisName) { 35 long int basisNameKey = *basisName; 36 basisStrName = ObjDictUnits.find(basisNameKey); 35 basisStrName = ObjDictUnits.find(*basisName); 37 36 38 37 if (basisStrName != "") { -
trunk/src/core/RpUnitsStd.cc
r999 r1018 10 10 #include <math.h> 11 11 12 #ifdef __cplusplus13 extern "C" {14 #endif15 16 12 double invert (double inVal) 17 13 { … … 22 18 * METRIC CONVERSIONS 23 19 ****************************************/ 24 25 20 26 21 double deci2base (double deci) … … 572 567 } 573 568 574 #ifdef __cplusplus575 }576 #endif -
trunk/src/core/scew_extras.c
r583 r1018 11 11 * ====================================================================== 12 12 */ 13 13 14 #include "scew/scew.h" 14 15 #include "scew/xelement.h" … … 16 17 #include "scew/xerror.h" 17 18 #include "scew/str.h" 18 19 #include "scew_extras.h" 19 20 #include <assert.h> 20 21 #include "scew_extras.h"22 21 23 22 scew_element*
Note: See TracChangeset
for help on using the changeset viewer.