- Timestamp:
- Feb 24, 2010 4:24:33 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r26603 r26753 96 96 Guid(const Bstr &that) 97 97 { 98 ::RTUuidClear 99 if (!that.is Null())98 ::RTUuidClear(&uuid); 99 if (!that.isEmpty()) 100 100 ::RTUuidFromUtf16(&uuid, that.raw()); 101 101 refresh(); 102 102 } 103 103 104 Guid &operator=(const Guid &that)104 Guid& operator=(const Guid &that) 105 105 { 106 106 ::memcpy(&uuid, &that.uuid, sizeof (RTUUID)); … … 108 108 return *this; 109 109 } 110 Guid &operator=(const GUID &guid)110 Guid& operator=(const GUID &guid) 111 111 { 112 112 ::memcpy(&uuid, &guid, sizeof (GUID)); … … 114 114 return *this; 115 115 } 116 Guid &operator=(const RTUUID &guid)116 Guid& operator=(const RTUUID &guid) 117 117 { 118 118 ::memcpy(&uuid, &guid, sizeof (RTUUID)); … … 120 120 return *this; 121 121 } 122 Guid &operator=(const char *str)122 Guid& operator=(const char *str) 123 123 { 124 124 ::RTUuidFromStr(&uuid, str); … … 145 145 } 146 146 147 Bstr toUtf16 147 Bstr toUtf16() const 148 148 { 149 149 if (isEmpty()) -
trunk/include/VBox/com/string.h
r26603 r26753 49 49 #include "VBox/com/assert.h" 50 50 51 #include <iprt/cpp/utils.h>52 51 #include <iprt/alloc.h> 53 52 #include <iprt/cpp/ministring.h> … … 58 57 class Utf8Str; 59 58 59 // global constant in glue/string.cpp that represents an empty BSTR 60 extern const BSTR g_bstrEmpty; 61 60 62 /** 61 * Helper class that represents the |BSTR| type and hides platform-specific 62 * implementation details. 63 * 64 * This class uses COM/XPCOM-provided memory management routines to allocate 65 * and free string buffers. This makes it possible to: 66 * - use it as a type of member variables of COM/XPCOM components and pass 67 * their values to callers through component methods' output parameters 68 * using the #cloneTo() operation; 69 * - adopt (take ownership of) string buffers returned in output parameters 70 * of COM methods using the #asOutParam() operation and correctly free them 71 * afterwards. 63 * String class used universally in Main for COM-style Utf-16 strings. 64 * Unfortunately COM on Windows uses UTF-16 everywhere, requiring conversions 65 * back and forth since most of VirtualBox and our libraries use UTF-8. 66 * 67 * To make things more obscure, on Windows, a COM-style BSTR is not just a 68 * pointer to a null-terminated wide character array, but the four bytes 69 * (32 bits) BEFORE the memory that the pointer points to are a length 70 * DWORD. One must therefore avoid pointer arithmetic and always use 71 * SysAllocString and the like to deal with BSTR pointers, which manage 72 * that DWORD correctly. 73 * 74 * For platforms other than Windows, we provide our own versions of the 75 * Sys* functions in Main/xpcom/helpers.cpp which do NOT use length 76 * prefixes though to be compatible with how XPCOM allocates string 77 * parameters to public functions. 78 * 79 * The Bstr class hides all this handling behind a std::string-like interface 80 * and also provides automatic conversions to MiniString and Utf8Str instances. 81 * 82 * The one advantage of using the SysString* routines is that this makes it 83 * possible to use it as a type of member variables of COM/XPCOM components 84 * and pass their values to callers through component methods' output parameters 85 * using the #cloneTo() operation. Also, the class can adopt (take ownership of) 86 * string buffers returned in output parameters of COM methods using the 87 * #asOutParam() operation and correctly free them afterwards. 88 * 89 * Starting with VirtualBox 3.2, like Utf8Str, Bstr no longer differentiates 90 * between NULL strings and empty strings. In other words, Bstr("") and 91 * Bstr(NULL) behave the same. In both cases, Bstr allocates no memory, 92 * reports a zero length and zero allocated bytes for both, and returns an 93 * empty C wide string from raw(). 72 94 */ 73 95 class Bstr … … 75 97 public: 76 98 77 typedef BSTR String; 78 typedef CBSTR ConstString; 79 80 Bstr() : bstr(NULL) {} 81 82 Bstr(const Bstr &that) : bstr(NULL) { raw_copy(bstr, that.bstr); } 83 Bstr(CBSTR that) : bstr(NULL) { raw_copy(bstr, that); } 99 Bstr() 100 : m_bstr(NULL) 101 { } 102 103 Bstr(const Bstr &that) 104 { 105 copyFrom((const OLECHAR *)that.m_bstr); 106 } 107 108 Bstr(CBSTR that) 109 { 110 copyFrom((const OLECHAR *)that); 111 } 84 112 85 113 #if defined (VBOX_WITH_XPCOM) 86 Bstr(const wchar_t *that) : bstr(NULL)114 Bstr(const wchar_t *that) 87 115 { 88 116 AssertCompile(sizeof(wchar_t) == sizeof(OLECHAR)); 89 raw_copy(bstr, (CBSTR)that); 90 } 91 #endif 92 93 Bstr(const iprt::MiniString &that); 94 Bstr(const char *that); 95 96 /** Shortcut that calls #alloc(aSize) right after object creation. */ 97 Bstr(size_t aSize) : bstr(NULL) { alloc(aSize); } 98 99 ~Bstr() { setNull(); } 100 101 Bstr &operator=(const Bstr &that) { safe_assign(that.bstr); return *this; } 102 Bstr &operator=(CBSTR that) { safe_assign(that); return *this; } 103 104 Bstr &operator=(const Utf8Str &that); 105 Bstr &operator=(const char *that); 106 107 Bstr &setNull() 108 { 109 if (bstr) 110 { 111 ::SysFreeString(bstr); 112 bstr = NULL; 113 } 117 copyFrom((const OLECHAR *)that); 118 } 119 #endif 120 121 Bstr(const iprt::MiniString &that) 122 { 123 copyFrom(that.raw()); 124 } 125 126 Bstr(const char *that) 127 { 128 copyFrom(that); 129 } 130 131 ~Bstr() 132 { 133 setNull(); 134 } 135 136 Bstr& operator=(const Bstr &that) 137 { 138 cleanup(); 139 copyFrom((const OLECHAR *)that.m_bstr); 114 140 return *this; 115 141 } 116 142 117 Bstr &setNullIfEmpty() 118 { 119 if (bstr && *bstr == 0) 120 { 121 ::SysFreeString(bstr); 122 bstr = NULL; 123 } 143 Bstr& operator=(CBSTR that) 144 { 145 cleanup(); 146 copyFrom((const OLECHAR *)that); 124 147 return *this; 125 148 } 126 149 127 /** 128 * Allocates memory for a string capable to store \a aSize - 1 characters; 129 * in other words, aSize includes the terminating zero character. If \a aSize 130 * is zero, or if a memory allocation error occurs, this object will become null. 131 */ 132 Bstr &alloc(size_t aSize) 133 { 134 setNull(); 135 if (aSize) 136 { 137 unsigned int size = (unsigned int) aSize; Assert(size == aSize); 138 bstr = ::SysAllocStringLen(NULL, size - 1); 139 if (bstr) 140 bstr[0] = 0; 141 } 150 #if defined (VBOX_WITH_XPCOM) 151 Bstr& operator=(const wchar_t *that) 152 { 153 cleanup(); 154 copyFrom((const OLECHAR *)that); 142 155 return *this; 143 156 } 144 145 int compare(CBSTR str) const 146 { 147 return ::RTUtf16Cmp((PRTUTF16) bstr, (PRTUTF16) str); 157 #endif 158 159 Bstr& setNull() 160 { 161 cleanup(); 162 return *this; 163 } 164 165 /** Case sensitivity selector. */ 166 enum CaseSensitivity 167 { 168 CaseSensitive, 169 CaseInsensitive 170 }; 171 172 /** 173 * Compares the member string to str. 174 * @param str 175 * @param cs Whether comparison should be case-sensitive. 176 * @return 177 */ 178 int compare(CBSTR str, CaseSensitivity cs = CaseSensitive) const 179 { 180 if (cs == CaseSensitive) 181 return ::RTUtf16Cmp((PRTUTF16)m_bstr, (PRTUTF16)str); 182 return ::RTUtf16LocaleICmp((PRTUTF16)m_bstr, (PRTUTF16)str); 148 183 } 149 184 150 185 int compare(BSTR str) const 151 186 { 152 return ::RTUtf16Cmp((PRTUTF16) bstr, (PRTUTF16)str);153 } 154 155 bool operator==(const Bstr &that) const { return !compare(that. bstr); }156 bool operator!=(const Bstr &that) const { return !!compare(that. bstr); }187 return compare((CBSTR)str); 188 } 189 190 bool operator==(const Bstr &that) const { return !compare(that.m_bstr); } 191 bool operator!=(const Bstr &that) const { return !!compare(that.m_bstr); } 157 192 bool operator==(CBSTR that) const { return !compare(that); } 158 193 bool operator==(BSTR that) const { return !compare(that); } 159 194 160 #if defined (VBOX_WITH_XPCOM)161 bool operator!=(const wchar_t *that) const162 {163 AssertCompile(sizeof(wchar_t) == sizeof(OLECHAR));164 return !!compare((CBSTR) that);165 }166 bool operator==(const wchar_t *that) const167 {168 AssertCompile(sizeof(wchar_t) == sizeof(OLECHAR));169 return !compare((CBSTR) that);170 }171 #endif172 173 195 bool operator!=(CBSTR that) const { return !!compare(that); } 174 196 bool operator!=(BSTR that) const { return !!compare(that); } 175 bool operator<(const Bstr &that) const { return compare(that. bstr) < 0; }197 bool operator<(const Bstr &that) const { return compare(that.m_bstr) < 0; } 176 198 bool operator<(CBSTR that) const { return compare(that) < 0; } 177 199 bool operator<(BSTR that) const { return compare(that) < 0; } 178 #if defined (VBOX_WITH_XPCOM) 179 bool operator<(const wchar_t *that) const 180 { 181 AssertCompile(sizeof(wchar_t) == sizeof(OLECHAR)); 182 return compare((CBSTR) that) < 0; 183 } 184 #endif 185 186 int compareIgnoreCase(CBSTR str) const 187 { 188 return ::RTUtf16LocaleICmp(bstr, str); 189 } 190 191 bool isNull() const { return bstr == NULL; } 192 operator bool() const { return !isNull(); } 193 194 bool isEmpty() const { return isNull() || *bstr == 0; } 195 196 size_t length() const { return isNull() ? 0 : ::RTUtf16Len((PRTUTF16) bstr); } 197 198 /** Intended to to pass instances as |CBSTR| input parameters to methods. */ 199 operator CBSTR() const { return bstr; } 200 201 /** 202 * Intended to to pass instances as |BSTR| input parameters to methods. 203 * Note that we have to provide this mutable BSTR operator since in MS COM 204 * input BSTR parameters of interface methods are not const. 205 */ 206 operator BSTR() { return bstr; } 207 208 /** 209 * The same as operator CBSTR(), but for situations where the compiler 210 * cannot typecast implicitly (for example, in printf() argument list). 211 */ 212 CBSTR raw() const { return bstr; } 200 201 /** 202 * Returns true if the member string has no length. 203 * This is true for instances created from both NULL and "" input strings. 204 * 205 * @note Always use this method to check if an instance is empty. Do not 206 * use length() because that may need to run through the entire string 207 * (Bstr does not cache string lengths). Also do not use operator bool(); 208 * for one, MSVC is really annoying with its thinking that that is ambiguous, 209 * and even though operator bool() is protected with Bstr, at least gcc uses 210 * operator CBSTR() when a construct like "if (string)" is encountered, which 211 * is always true now since it raw() never returns an empty string. Again, 212 * always use isEmpty() even though if (string) may compile! 213 */ 214 bool isEmpty() const { return m_bstr == NULL || *m_bstr == 0; } 215 216 size_t length() const { return isEmpty() ? 0 : ::RTUtf16Len((PRTUTF16)m_bstr); } 217 218 /** 219 * Returns true if the member string is not empty. I'd like to make this 220 * private but since we require operator BSTR() it's futile anyway because 221 * the compiler will then (wrongly) use that one instead. Also if this is 222 * private the odd WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP macro below 223 * will fail on Windows. 224 */ 225 operator bool() const 226 { 227 return m_bstr != NULL; 228 } 229 230 /** 231 * Returns a pointer to the raw member UTF-16 string. If the member string is empty, 232 * returns a pointer to a global variable containing an empty BSTR with a proper zero 233 * length prefix so that Windows is happy. 234 */ 235 CBSTR raw() const 236 { 237 if (m_bstr) 238 return m_bstr; 239 240 return g_bstrEmpty; 241 } 242 243 /** 244 * Convenience operator so that Bstr's can be passed to CBSTR input parameters 245 * of COM methods. 246 */ 247 operator CBSTR() const { return raw(); } 248 249 /** 250 * Convenience operator so that Bstr's can be passed to CBSTR input parameters 251 * of COM methods. Unfortunately this is required for Windows since with 252 * MSCOM, input BSTR parameters of interface methods are not const. 253 */ 254 operator BSTR() { return (BSTR)raw(); } 213 255 214 256 /** 215 257 * Returns a non-const raw pointer that allows to modify the string directly. 258 * As opposed to raw(), this DOES return NULL if the member string is empty 259 * because we cannot return a mutable pointer to the global variable with the 260 * empty string. 261 * 216 262 * @warning 217 263 * Be sure not to modify data beyond the allocated memory! The … … 219 265 * bytes after creation and after every assignment operation. 220 266 */ 221 BSTR mutableRaw() { return bstr; }267 BSTR mutableRaw() { return m_bstr; } 222 268 223 269 /** … … 225 271 * within the interface method. Transfers the ownership of the duplicated 226 272 * string to the caller. 227 */ 228 const Bstr &cloneTo(BSTR *pstr) const 273 * 274 * If the member string is empty, this allocates an empty BSTR in *pstr 275 * (i.e. makes it point to a new buffer with a null byte). 276 */ 277 void cloneTo(BSTR *pstr) const 229 278 { 230 279 if (pstr) 231 280 { 232 *pstr = NULL; 233 raw_copy(*pstr, bstr); 281 *pstr = ::SysAllocString((const OLECHAR *)raw()); // raw() returns a pointer to "" if empty 282 #ifdef RT_EXCEPTIONS_ENABLED 283 if (!*pstr) 284 throw std::bad_alloc(); 285 #endif 234 286 } 235 return *this;236 287 } 237 288 … … 243 294 * As opposed to cloneTo(), this method doesn't create a copy of the 244 295 * string. 245 */ 246 Bstr &detachTo(BSTR *pstr) 247 { 248 *pstr = bstr; 249 bstr = NULL; 250 return *this; 251 } 252 253 /** 254 * Intended to assign copies of instances to |char *| out parameters from 255 * within the interface method. Transfers the ownership of the duplicated 256 * string to the caller. 257 */ 258 const Bstr &cloneTo(char **pstr) const; 296 * 297 * If the member string is empty, this allocates an empty BSTR in *pstr 298 * (i.e. makes it point to a new buffer with a null byte). 299 */ 300 void detachTo(BSTR *pstr) 301 { 302 if (m_bstr) 303 *pstr = m_bstr; 304 else 305 { 306 // allocate null BSTR 307 *pstr = ::SysAllocString((const OLECHAR *)g_bstrEmpty); 308 #ifdef RT_EXCEPTIONS_ENABLED 309 if (!*pstr) 310 throw std::bad_alloc(); 311 #endif 312 } 313 m_bstr = NULL; 314 } 259 315 260 316 /** … … 262 318 * Takes the ownership of the returned data. 263 319 */ 264 BSTR *asOutParam() { setNull(); return &bstr; } 320 BSTR* asOutParam() 321 { 322 cleanup(); 323 return &m_bstr; 324 } 265 325 266 326 /** … … 271 331 protected: 272 332 273 void safe_assign(CBSTR str)274 { 275 if ( bstr !=str)333 void cleanup() 334 { 335 if (m_bstr) 276 336 { 277 setNull();278 raw_copy(bstr, str);337 ::SysFreeString(m_bstr); 338 m_bstr = NULL; 279 339 } 280 340 } 281 341 282 inline static void raw_copy(BSTR &ls, CBSTR rs) 283 { 284 if (rs) 285 ls = ::SysAllocString((const OLECHAR *) rs); 286 } 287 288 inline static void raw_copy(BSTR &ls, const char *rs) 289 { 290 if (rs) 342 /** 343 * Protected internal helper to copy a string. This ignores the previous object 344 * state, so either call this from a constructor or call cleanup() first. 345 * 346 * This variant copies from a zero-terminated UTF-16 string (which need not 347 * be a BSTR, i.e. need not have a length prefix). 348 * 349 * If the source is empty, this sets the member string to NULL. 350 * @param rs 351 */ 352 void copyFrom(const OLECHAR *rs) 353 { 354 if (rs && *rs) 355 { 356 m_bstr = ::SysAllocString(rs); 357 #ifdef RT_EXCEPTIONS_ENABLED 358 if (!m_bstr) 359 throw std::bad_alloc(); 360 #endif 361 } 362 else 363 m_bstr = NULL; 364 } 365 366 /** 367 * Protected internal helper to copy a string. This ignores the previous object 368 * state, so either call this from a constructor or call cleanup() first. 369 * 370 * This variant copies and converts from a zero-terminated UTF-8 string. 371 * 372 * If the source is empty, this sets the member string to NULL. 373 * @param rs 374 */ 375 void copyFrom(const char *rs) 376 { 377 if (rs && *rs) 291 378 { 292 379 PRTUTF16 s = NULL; 293 380 ::RTStrToUtf16(rs, &s); 294 raw_copy(ls, (BSTR)s); 381 #ifdef RT_EXCEPTIONS_ENABLED 382 if (!s) 383 throw std::bad_alloc(); 384 #endif 385 copyFrom((const OLECHAR *)s); // allocates BSTR from zero-terminated input string 295 386 ::RTUtf16Free(s); 296 387 } 297 } 298 299 BSTR bstr; 388 else 389 m_bstr = NULL; 390 } 391 392 BSTR m_bstr; 300 393 301 394 friend class Utf8Str; /* to access our raw_copy() */ … … 308 401 inline bool operator!=(BSTR l, const Bstr &r) { return r.operator!=(l); } 309 402 403 // work around error C2593 of the stupid MSVC 7.x ambiguity resolver 404 WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Bstr) 405 310 406 //////////////////////////////////////////////////////////////////////////////// 311 407 312 408 /** 313 * Helper class that represents UTF8 (|char *|) strings. Useful in 314 * conjunction with Bstr to simplify conversions between UTF16 (|BSTR|) 315 * and UTF8. 316 * 317 * This class uses COM/XPCOM-provided memory management routines to allocate 318 * and free string buffers. This makes it possible to: 319 * - use it as a type of member variables of COM/XPCOM components and pass 320 * their values to callers through component methods' output parameters 321 * using the #cloneTo() operation; 322 * - adopt (take ownership of) string buffers returned in output parameters 323 * of COM methods using the #asOutParam() operation and correctly free them 324 * afterwards. 409 * String class used universally in Main for UTF-8 strings. 410 * 411 * This is based on iprt::MiniString, to which some functionality has been 412 * moved. Here we keep things that are specific to Main, such as conversions 413 * with UTF-16 strings (Bstr). 414 * 415 * Like iprt::MiniString, Utf8Str does not differentiate between NULL strings 416 * and empty strings. In other words, Utf8Str("") and Utf8Str(NULL) 417 * behave the same. In both cases, MiniString allocates no memory, reports 418 * a zero length and zero allocated bytes for both, and returns an empty 419 * C string from c_str(). 325 420 */ 326 421 class Utf8Str : public iprt::MiniString … … 374 469 } 375 470 471 #if defined (VBOX_WITH_XPCOM) 376 472 /** 377 473 * Intended to assign instances to |char *| out parameters from within the … … 379 475 * caller. 380 476 * 381 * @remarks The returned string must be freed by RTStrFree, not RTMemFree. 382 */ 383 const Utf8Str& cloneTo(char **pstr) const 384 { 385 if (pstr) /** @todo r=bird: This needs to if m_psz is NULL. Shouldn't it also throw std::bad_alloc? */ 386 *pstr = RTStrDup(m_psz); 387 return *this; 388 } 389 390 /** 391 * Intended to assign instances to |char *| out parameters from within the 392 * interface method. Transfers the ownership of the original string to the 393 * caller and resets the instance to null. 394 * 395 * As opposed to cloneTo(), this method doesn't create a copy of the 396 * string. 397 */ 398 Utf8Str& detachTo(char **pstr) 399 { 400 *pstr = m_psz; 401 m_psz = NULL; 402 m_cbAllocated = 0; 403 m_cbLength = 0; 404 return *this; 405 } 477 * This allocates a single 0 byte in the target if the member string is empty. 478 * 479 * This uses XPCOM memory allocation and thus only works on XPCOM. MSCOM doesn't 480 * like char* strings anyway. 481 */ 482 void cloneTo(char **pstr) const; 483 #endif 406 484 407 485 /** … … 410 488 * caller. 411 489 */ 412 const Utf8Str&cloneTo(BSTR *pstr) const490 void cloneTo(BSTR *pstr) const 413 491 { 414 492 if (pstr) 415 493 { 416 *pstr = NULL;417 Bstr::raw_copy(*pstr, m_psz);494 Bstr bstr(*this); 495 bstr.cloneTo(pstr); 418 496 } 419 return *this;420 497 } 421 498 … … 505 582 void copyFrom(CBSTR s) 506 583 { 507 if (s )584 if (s && *s) 508 585 { 509 586 RTUtf16ToUtf8((PRTUTF16)s, &m_psz); /** @todo r=bird: This isn't throwing std::bad_alloc / handling return codes. … … 523 600 }; 524 601 525 // work around error C2593 of the stupid MSVC 7.x ambiguity resolver526 WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Bstr)527 528 ////////////////////////////////////////////////////////////////////////////////529 530 // inlined Bstr members that depend on Utf8Str531 532 inline Bstr::Bstr(const iprt::MiniString &that)533 : bstr(NULL)534 {535 raw_copy(bstr, that.c_str());536 }537 538 inline Bstr::Bstr(const char *that)539 : bstr(NULL)540 {541 raw_copy(bstr, that);542 }543 544 inline Bstr &Bstr::operator=(const Utf8Str &that)545 {546 setNull();547 raw_copy(bstr, that.c_str());548 return *this;549 }550 inline Bstr &Bstr::operator=(const char *that)551 {552 setNull();553 raw_copy(bstr, that);554 return *this;555 }556 557 inline const Bstr& Bstr::cloneTo(char **pstr) const558 {559 if (pstr)560 {561 Utf8Str ustr(*this);562 ustr.detachTo(pstr);563 }564 return *this;565 }566 567 ////////////////////////////////////////////////////////////////////////////////568 569 602 /** 570 603 * This class is a printf-like formatter for Utf8Str strings. Its purpose is … … 654 687 va_list args; 655 688 va_start(args, aFormat); 656 raw_copy(bstr,Utf8StrFmtVA(aFormat, args).c_str());689 copyFrom(Utf8StrFmtVA(aFormat, args).c_str()); 657 690 va_end(args); 658 691 } … … 675 708 BstrFmtVA(const char *aFormat, va_list aArgs) 676 709 { 677 raw_copy(bstr,Utf8StrFmtVA(aFormat, aArgs).c_str());710 copyFrom(Utf8StrFmtVA(aFormat, aArgs).c_str()); 678 711 } 679 712 }; -
trunk/include/iprt/cpp/ministring.h
r26603 r26753 45 45 * else except IPRT memory management functions. Semantics are like in 46 46 * std::string, except it can do a lot less. 47 * 48 * 49 * Note that MiniString does not differentiate between NULL strings and 50 * empty strings. In other words, MiniString("") and MiniString(NULL) 51 * behave the same. In both cases, MiniString allocates no memory, reports 52 * a zero length and zero allocated bytes for both, and returns an empty 53 * C string from c_str(). 47 54 */ 48 55 #ifdef VBOX … … 71 78 * Creates a copy of another MiniString. 72 79 * 73 * This allocates s.length() + 1 bytes for the new instance .80 * This allocates s.length() + 1 bytes for the new instance, unless s is empty. 74 81 * 75 82 * @param s The source string. … … 83 90 84 91 /** 85 * Creates a copy of a nother MiniString.86 * 87 * This allocates strlen(pcsz) + 1 bytes for the new instance .92 * Creates a copy of a C string. 93 * 94 * This allocates strlen(pcsz) + 1 bytes for the new instance, unless s is empty. 88 95 * 89 96 * @param pcsz The source string. … … 123 130 * 124 131 * Returns the number of bytes allocated in the internal string buffer, which is 125 * at least length() + 1 if length() > 0 .132 * at least length() + 1 if length() > 0; for an empty string, this returns 0. 126 133 * 127 134 * @returns m_cbAllocated. … … 172 179 173 180 /** 181 * Assigns a copy of pcsz to "this". 182 * 183 * @param pcsz The source string. 184 * 185 * @throws std::bad_alloc On allocation failure. The object is left describing 186 * a NULL string. 187 * 188 * @returns Reference to the object. 189 */ 190 MiniString &operator=(const char *pcsz) 191 { 192 if (m_psz != pcsz) 193 { 194 cleanup(); 195 copyFrom(pcsz); 196 } 197 return *this; 198 } 199 200 /** 201 * Assigns a copy of s to "this". 202 * 203 * @param s The source string. 204 * 205 * @throws std::bad_alloc On allocation failure. The object is left describing 206 * a NULL string. 207 * 208 * @returns Reference to the object. 209 */ 210 MiniString &operator=(const MiniString &s) 211 { 212 if (this != &s) 213 { 214 cleanup(); 215 copyFrom(s); 216 } 217 return *this; 218 } 219 220 /** 221 * Appends the string "that" to "this". 222 * 223 * @param that The string to append. 224 * 225 * @throws std::bad_alloc On allocation error. The object is left unchanged. 226 * 227 * @returns Reference to the object. 228 */ 229 MiniString &append(const MiniString &that); 230 231 /** 232 * Appends the given character to "this". 233 * 234 * @param c The character to append. 235 * 236 * @throws std::bad_alloc On allocation error. The object is left unchanged. 237 * 238 * @returns Reference to the object. 239 */ 240 MiniString &append(char c); 241 242 /** 243 * Index operator. 244 * 245 * Returns the byte at the given index, or a null byte if the index is not 246 * smaller than length(). This does _not_ count codepoints but simply points 247 * into the member C string. 248 * 249 * @param i The index into the string buffer. 250 * @returns char at the index or null. 251 */ 252 inline char operator[](size_t i) const 253 { 254 if (i < length()) 255 return m_psz[i]; 256 return '\0'; 257 } 258 259 /** 260 * Returns the contained string as a C-style const char* pointer. 261 * This never returns NULL; if the string is empty, this returns a 262 * pointer to static null byte. 263 * 264 * @returns const pointer to C-style string. 265 */ 266 inline const char *c_str() const 267 { 268 return (m_psz) ? m_psz : ""; 269 } 270 271 /** 272 * Like c_str(), for compatibility with lots of VirtualBox Main code. 273 * 274 * @returns const pointer to C-style string. 275 */ 276 inline const char *raw() const 277 { 278 return (m_psz) ? m_psz : ""; 279 } 280 281 /** 174 282 * Returns a non-const raw pointer that allows to modify the string directly. 283 * As opposed to c_str() and raw(), this DOES return NULL for an empty string 284 * because we cannot return a non-const pointer to a static "" global. 175 285 * 176 286 * @warning … … 209 319 210 320 /** 211 * Assigns a copy of pcsz to "this". 212 * 213 * @param pcsz The source string. 214 * 215 * @throws std::bad_alloc On allocation failure. The object is left describing 216 * a NULL string. 217 * 218 * @returns Reference to the object. 219 */ 220 MiniString &operator=(const char *pcsz) 221 { 222 if (m_psz != pcsz) 223 { 224 cleanup(); 225 copyFrom(pcsz); 226 } 227 return *this; 228 } 229 230 /** 231 * Assigns a copy of s to "this". 232 * 233 * @param s The source string. 234 * 235 * @throws std::bad_alloc On allocation failure. The object is left describing 236 * a NULL string. 237 * 238 * @returns Reference to the object. 239 */ 240 MiniString &operator=(const MiniString &s) 241 { 242 if (this != &s) 243 { 244 cleanup(); 245 copyFrom(s); 246 } 247 return *this; 248 } 249 250 /** 251 * Appends the string "that" to "this". 252 * 253 * @param that The string to append. 254 * 255 * @throws std::bad_alloc On allocation error. The object is left unchanged. 256 * 257 * @returns Reference to the object. 258 */ 259 MiniString &append(const MiniString &that); 260 261 /** 262 * Appends the given character to "this". 263 * 264 * @param c The character to append. 265 * 266 * @throws std::bad_alloc On allocation error. The object is left unchanged. 267 * 268 * @returns Reference to the object. 269 */ 270 MiniString &append(char c); 271 272 /** 273 * Index operator. 274 * 275 * Returns the byte at the given index, or a null byte if the index is not 276 * smaller than length(). This does _not_ count codepoints but simply points 277 * into the member C string. 278 * 279 * @param i The index into the string buffer. 280 * @returns char at the index or null. 281 */ 282 inline char operator[](size_t i) const 283 { 284 if (i < length()) 285 return m_psz[i]; 286 return '\0'; 287 } 288 289 /** 290 * Returns the contained string as a C-style const char* pointer. 291 * 292 * @returns const pointer to C-style string. 293 */ 294 inline const char *c_str() const 295 { 296 return m_psz; 297 } 298 299 /** 300 * Like c_str(), for compatibility with lots of VirtualBox Main code. 301 * 302 * @returns const pointer to C-style string. 303 */ 304 inline const char *raw() const 305 { 306 return m_psz; 307 } 308 309 /** 310 * Emptry string or not? 311 * 312 * Returns true if the member string has no length. This states nothing about 313 * how much memory might be allocated. 321 * Returns true if the member string has no length. 322 * This is true for instances created from both NULL and "" input strings. 323 * 324 * This states nothing about how much memory might be allocated. 314 325 * 315 326 * @returns true if empty, false if not. … … 474 485 * Hide operator bool() to force people to use isEmpty() explicitly. 475 486 */ 476 operator bool() const { return false; }487 operator bool() const; 477 488 478 489 /** … … 492 503 493 504 /** 494 * Protected internal helper for copy a string that completely ignors the495 * current object state.505 * Protected internal helper to copy a string. This ignores the previous object 506 * state, so either call this from a constructor or call cleanup() first. 496 507 * 497 508 * copyFrom() unconditionally sets the members to a copy of the given other … … 501 512 * 502 513 * This variant copies from another MiniString and is fast since 503 * the length of source string is known.514 * the length of the source string is known. 504 515 * 505 516 * @param s The source string. … … 533 544 534 545 /** 535 * Protected internal helper for copy a string that completely ignors the536 * current object state.546 * Protected internal helper to copy a string. This ignores the previous object 547 * state, so either call this from a constructor or call cleanup() first. 537 548 * 538 549 * See copyFrom() above. … … 548 559 void copyFrom(const char *pcsz) 549 560 { 550 if (pcsz )561 if (pcsz && *pcsz) 551 562 { 552 563 m_cbLength = strlen(pcsz); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r26603 r26753 281 281 bool doClose = false; 282 282 283 if (!comment.is Null())283 if (!comment.isEmpty()) 284 284 { 285 285 CHECK_ERROR(hardDisk,COMSETTER(Description)(comment)); 286 286 } 287 287 288 ComPtr<IProgress> progress; 288 289 CHECK_ERROR(hardDisk, CreateBaseStorage(sizeMB, DiskVariant, progress.asOutParam())); … … 1038 1039 if (FAILED(rc)) break; 1039 1040 1040 if (!port.is Null())1041 if (!port.isEmpty()) 1041 1042 server = BstrFmt ("%ls:%ls", server.raw(), port.raw()); 1042 1043 … … 1049 1050 target.detachTo (values.appendedRaw()); 1050 1051 1051 if (!lun.is Null())1052 if (!lun.isEmpty()) 1052 1053 { 1053 1054 Bstr ("LUN").detachTo (names.appendedRaw()); 1054 1055 lun.detachTo (values.appendedRaw()); 1055 1056 } 1056 if (!username.is Null())1057 if (!username.isEmpty()) 1057 1058 { 1058 1059 Bstr ("InitiatorUsername").detachTo (names.appendedRaw()); 1059 1060 username.detachTo (values.appendedRaw()); 1060 1061 } 1061 if (!password.is Null())1062 if (!password.isEmpty()) 1062 1063 { 1063 1064 Bstr ("InitiatorSecret").detachTo (names.appendedRaw()); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageUSB.cpp
r26603 r26753 441 441 if (!f.mActive.isNull()) 442 442 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive)); 443 if (!f.mVendorId.is Null())444 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId .setNullIfEmpty()));445 if (!f.mProductId.is Null())446 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId .setNullIfEmpty()));447 if (!f.mRevision.is Null())448 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision .setNullIfEmpty()));449 if (!f.mManufacturer.is Null())450 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer .setNullIfEmpty()));451 if (!f.mSerialNumber.is Null())452 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber .setNullIfEmpty()));443 if (!f.mVendorId.isEmpty()) 444 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId)); 445 if (!f.mProductId.isEmpty()) 446 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId)); 447 if (!f.mRevision.isEmpty()) 448 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision)); 449 if (!f.mManufacturer.isEmpty()) 450 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer)); 451 if (!f.mSerialNumber.isEmpty()) 452 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber)); 453 453 if (!f.mMaskedInterfaces.isNull()) 454 454 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces)); … … 466 466 if (!f.mActive.isNull()) 467 467 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive)); 468 if (!f.mVendorId.is Null())469 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId .setNullIfEmpty()));470 if (!f.mProductId.is Null())471 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId .setNullIfEmpty()));472 if (!f.mRevision.is Null())473 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision .setNullIfEmpty()));474 if (!f.mManufacturer.is Null())475 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer .setNullIfEmpty()));476 if (!f.mRemote.is Null())477 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote .setNullIfEmpty()));478 if (!f.mSerialNumber.is Null())479 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber .setNullIfEmpty()));468 if (!f.mVendorId.isEmpty()) 469 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId)); 470 if (!f.mProductId.isEmpty()) 471 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId)); 472 if (!f.mRevision.isEmpty()) 473 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision)); 474 if (!f.mManufacturer.isEmpty()) 475 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer)); 476 if (!f.mRemote.isEmpty()) 477 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote)); 478 if (!f.mSerialNumber.isEmpty()) 479 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber)); 480 480 if (!f.mMaskedInterfaces.isNull()) 481 481 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces)); … … 494 494 ComPtr <IHostUSBDeviceFilter> flt = coll[cmd.mIndex]; 495 495 496 if (!f.mName.is Null())497 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName .setNullIfEmpty()));496 if (!f.mName.isEmpty()) 497 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName)); 498 498 if (!f.mActive.isNull()) 499 499 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive)); 500 if (!f.mVendorId.is Null())501 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId .setNullIfEmpty()));502 if (!f.mProductId.is Null())503 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId .setNullIfEmpty()));504 if (!f.mRevision.is Null())505 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision .setNullIfEmpty()));506 if (!f.mManufacturer.is Null())507 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer .setNullIfEmpty()));508 if (!f.mSerialNumber.is Null())509 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber .setNullIfEmpty()));500 if (!f.mVendorId.isEmpty()) 501 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId)); 502 if (!f.mProductId.isEmpty()) 503 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId)); 504 if (!f.mRevision.isEmpty()) 505 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision)); 506 if (!f.mManufacturer.isEmpty()) 507 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer)); 508 if (!f.mSerialNumber.isEmpty()) 509 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber)); 510 510 if (!f.mMaskedInterfaces.isNull()) 511 511 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces)); … … 521 521 ComPtr <IUSBDeviceFilter> flt = coll[cmd.mIndex]; 522 522 523 if (!f.mName.is Null())524 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName .setNullIfEmpty()));523 if (!f.mName.isEmpty()) 524 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName)); 525 525 if (!f.mActive.isNull()) 526 526 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive)); 527 if (!f.mVendorId.is Null())528 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId .setNullIfEmpty()));529 if (!f.mProductId.is Null())530 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId .setNullIfEmpty()));531 if (!f.mRevision.is Null())532 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision .setNullIfEmpty()));533 if (!f.mManufacturer.is Null())534 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer .setNullIfEmpty()));535 if (!f.mRemote.is Null())536 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote .setNullIfEmpty()));537 if (!f.mSerialNumber.is Null())538 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber .setNullIfEmpty()));527 if (!f.mVendorId.isEmpty()) 528 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId)); 529 if (!f.mProductId.isEmpty()) 530 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId)); 531 if (!f.mRevision.isEmpty()) 532 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision)); 533 if (!f.mManufacturer.isEmpty()) 534 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer)); 535 if (!f.mRemote.isEmpty()) 536 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote)); 537 if (!f.mSerialNumber.isEmpty()) 538 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber)); 539 539 if (!f.mMaskedInterfaces.isNull()) 540 540 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces)); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r26714 r26753 232 232 return E_INVALIDARG; 233 233 234 if (com::asGuidStr(id).is Null())234 if (com::asGuidStr(id).isEmpty()) 235 235 { 236 236 /* it's a global extra data key someone wants to change */ … … 314 314 IN_BSTR key, IN_BSTR value) 315 315 { 316 if (com::asGuidStr(id).is Null())316 if (com::asGuidStr(id).isEmpty()) 317 317 { 318 318 QString sKey = QString::fromUtf16 (key); -
trunk/src/VBox/Main/ApplianceImpl.cpp
r26603 r26753 1569 1569 mhda.lDevice, 1570 1570 DeviceType_Floppy, 1571 Bstr(""));1571 NULL); 1572 1572 if (FAILED(rc)) throw rc; 1573 1573 … … 1618 1618 mhda.lDevice, 1619 1619 DeviceType_DVD, 1620 Bstr(""));1620 NULL); 1621 1621 if (FAILED(rc)) throw rc; 1622 1622 … … 1744 1744 rc = mVirtualBox->OpenHardDisk(Bstr(strSrcFilePath), 1745 1745 AccessMode_ReadOnly, 1746 false, Bstr(""), false, Bstr(""), 1746 false, 1747 NULL, 1748 false, 1749 NULL, 1747 1750 srcHdVBox.asOutParam()); 1748 1751 if (FAILED(rc)) throw rc; … … 4281 4284 IN_BSTR aExtraConfigValue) 4282 4285 { 4283 CheckComArgNotNull(aVboxValue);4284 CheckComArgNotNull(aExtraConfigValue);4285 4286 4286 AutoCaller autoCaller(this); 4287 4287 if (FAILED(autoCaller.rc())) return autoCaller.rc(); -
trunk/src/VBox/Main/ConsoleImpl.cpp
r26615 r26753 574 574 { 575 575 if (!enabledGuestPropertiesVRDP()) 576 {577 576 return; 578 } 577 578 Bstr bstrReadOnlyGuest(L"RDONLYGUEST"); 579 579 580 580 int rc; … … 584 584 if (RT_SUCCESS(rc)) 585 585 { 586 mMachine->SetGuestProperty(Bstr(pszPropertyName), Bstr(""), Bstr("RDONLYGUEST"));586 mMachine->SetGuestProperty(Bstr(pszPropertyName), NULL, bstrReadOnlyGuest); 587 587 RTStrFree(pszPropertyName); 588 588 } … … 591 591 if (RT_SUCCESS(rc)) 592 592 { 593 mMachine->SetGuestProperty(Bstr(pszPropertyName), Bstr(""), Bstr("RDONLYGUEST"));593 mMachine->SetGuestProperty(Bstr(pszPropertyName), NULL, bstrReadOnlyGuest); 594 594 RTStrFree(pszPropertyName); 595 595 } … … 598 598 if (RT_SUCCESS(rc)) 599 599 { 600 mMachine->SetGuestProperty(Bstr(pszPropertyName), Bstr(""), Bstr("RDONLYGUEST"));600 mMachine->SetGuestProperty(Bstr(pszPropertyName), NULL, bstrReadOnlyGuest); 601 601 RTStrFree(pszPropertyName); 602 602 } … … 606 606 if (RT_SUCCESS(rc)) 607 607 { 608 mMachine->SetGuestProperty(Bstr("/VirtualBox/HostInfo/VRDP/LastDisconnectedClient"), Bstr(pszClientId), Bstr("RDONLYGUEST"));608 mMachine->SetGuestProperty(Bstr("/VirtualBox/HostInfo/VRDP/LastDisconnectedClient"), Bstr(pszClientId), bstrReadOnlyGuest); 609 609 RTStrFree(pszClientId); 610 610 } … … 1190 1190 1191 1191 // static 1192 DECLCALLBACK(int) 1193 Console::doGuestPropNotification(void *pvExtension, uint32_t u32Function, 1194 void *pvParms, uint32_t cbParms) 1192 DECLCALLBACK(int) Console::doGuestPropNotification(void *pvExtension, 1193 uint32_t u32Function, 1194 void *pvParms, 1195 uint32_t cbParms) 1195 1196 { 1196 1197 using namespace guestProp; … … 1212 1213 Bstr value(pCBData->pcszValue); 1213 1214 Bstr flags(pCBData->pcszFlags); 1214 if ( !name.isNull() 1215 && (!value.isNull() || pCBData->pcszValue == NULL) 1216 && (!flags.isNull() || pCBData->pcszFlags == NULL) 1217 ) 1218 { 1219 ComObjPtr<Console> ptrConsole = reinterpret_cast<Console *>(pvExtension); 1220 HRESULT hrc = ptrConsole->mControl->PushGuestProperty(name, 1221 value, 1222 pCBData->u64Timestamp, 1223 flags); 1224 if (SUCCEEDED(hrc)) 1225 rc = VINF_SUCCESS; 1226 else 1227 { 1228 LogFunc(("Console::doGuestPropNotification: hrc=%Rhrc pCBData={.pcszName=%s, .pcszValue=%s, .pcszFlags=%s}\n", 1229 pCBData->pcszName, pCBData->pcszValue, pCBData->pcszFlags)); 1230 rc = Global::vboxStatusCodeFromCOM(hrc); 1231 } 1232 } 1215 ComObjPtr<Console> ptrConsole = reinterpret_cast<Console *>(pvExtension); 1216 HRESULT hrc = ptrConsole->mControl->PushGuestProperty(name, 1217 value, 1218 pCBData->u64Timestamp, 1219 flags); 1220 if (SUCCEEDED(hrc)) 1221 rc = VINF_SUCCESS; 1233 1222 else 1234 rc = VERR_NO_MEMORY; 1223 { 1224 LogFunc(("Console::doGuestPropNotification: hrc=%Rhrc pCBData={.pcszName=%s, .pcszValue=%s, .pcszFlags=%s}\n", 1225 pCBData->pcszName, pCBData->pcszValue, pCBData->pcszFlags)); 1226 rc = Global::vboxStatusCodeFromCOM(hrc); 1227 } 1235 1228 return rc; 1236 1229 } … … 1248 1241 Utf8Str utf8Patterns(aPatterns); 1249 1242 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 1243 // mutableRaw() returns NULL for an empty string 1244 // if ((parm[0].u.pointer.addr = utf8Patterns.mutableRaw())) 1245 // parm[0].u.pointer.size = (uint32_t)utf8Patterns.length() + 1; 1246 // else 1247 // { 1248 // parm[0].u.pointer.addr = (void*)""; 1249 // parm[0].u.pointer.size = 1; 1250 // } 1250 1251 parm[0].u.pointer.addr = utf8Patterns.mutableRaw(); 1251 1252 parm[0].u.pointer.size = (uint32_t)utf8Patterns.length() + 1; … … 1364 1365 try 1365 1366 { 1366 Bstr pattern(""); 1367 hrc = doEnumerateGuestProperties(pattern, ComSafeArrayAsOutParam(namesOut), 1367 Bstr pattern; 1368 hrc = doEnumerateGuestProperties(pattern, 1369 ComSafeArrayAsOutParam(namesOut), 1368 1370 ComSafeArrayAsOutParam(valuesOut), 1369 1371 ComSafeArrayAsOutParam(timestampsOut), … … 1371 1373 if (SUCCEEDED(hrc)) 1372 1374 { 1373 std::vector 1374 std::vector 1375 std::vector 1376 std::vector 1375 std::vector<BSTR> names; 1376 std::vector<BSTR> values; 1377 std::vector<ULONG64> timestamps; 1378 std::vector<BSTR> flags; 1377 1379 for (size_t i = 0; i < namesOut.size(); ++i) 1378 1380 { … … 1392 1394 com::SafeArray<ULONG64> timestampsIn(timestamps); 1393 1395 com::SafeArray<BSTR> flagsIn(flags); 1394 if ( namesIn.isNull()1395 || valuesIn.isNull()1396 || timestampsIn.isNull()1397 || flagsIn.isNull()1398 )1399 throw std::bad_alloc();1400 1396 /* PushGuestProperties() calls DiscardSettings(), which calls us back */ 1401 1397 mControl->PushGuestProperties(ComSafeArrayAsInParam(namesIn), … … 2594 2590 { 2595 2591 #ifdef VBOX_WITH_USB 2596 CheckComArg NotNull(aAddress);2592 CheckComArgStrNotEmptyOrNull(aAddress); 2597 2593 CheckComArgOutPointerValid(aDevice); 2598 2594 … … 2664 2660 Console::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable) 2665 2661 { 2666 CheckComArg NotNull(aName);2667 CheckComArg NotNull(aHostPath);2662 CheckComArgStrNotEmptyOrNull(aName); 2663 CheckComArgStrNotEmptyOrNull(aHostPath); 2668 2664 2669 2665 AutoCaller autoCaller(this); … … 2732 2728 STDMETHODIMP Console::RemoveSharedFolder(IN_BSTR aName) 2733 2729 { 2734 CheckComArg NotNull(aName);2730 CheckComArgStrNotEmptyOrNull(aName); 2735 2731 2736 2732 AutoCaller autoCaller(this); … … 2798 2794 LogFlowThisFunc(("aName='%ls' mMachineState=%08X\n", aName, mMachineState)); 2799 2795 2800 CheckComArg NotNull(aName);2796 CheckComArgStrNotEmptyOrNull(aName); 2801 2797 CheckComArgOutPointerValid(aProgress); 2802 2798 … … 7725 7721 * (i.e. creating a snapshot online) 7726 7722 */ 7727 ComAssertThrow( (!pTask->bstrSavedStateFile.is Null() &&pTask->fTakingSnapshotOnline)7728 || ( pTask->bstrSavedStateFile.isNull() && !pTask->fTakingSnapshotOnline),7723 ComAssertThrow( (!pTask->bstrSavedStateFile.isEmpty() && pTask->fTakingSnapshotOnline) 7724 || ( pTask->bstrSavedStateFile.isEmpty() && !pTask->fTakingSnapshotOnline), 7729 7725 rc = E_FAIL); 7730 7726 … … 8040 8036 task->mProgress->notifyComplete(rc, 8041 8037 COM_IIDOF(IConsole), 8042 Console::getComponentName(),8038 (CBSTR)Console::getComponentName(), 8043 8039 errMsg.c_str()); 8044 8040 else -
trunk/src/VBox/Main/ConsoleImpl2.cpp
r26681 r26753 3180 3180 } 3181 3181 3182 if (!networkName.is Null())3182 if (!networkName.isEmpty()) 3183 3183 { 3184 3184 /* … … 3187 3187 */ 3188 3188 ComPtr<IDHCPServer> dhcpServer; 3189 hrc = virtualBox->FindDHCPServerByNetworkName(networkName .mutableRaw(), dhcpServer.asOutParam());3189 hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam()); 3190 3190 if (SUCCEEDED(hrc)) 3191 3191 { -
trunk/src/VBox/Main/ConsoleImplTeleporter.cpp
r26603 r26753 903 903 CheckComArgOutPointerValid(aProgress); 904 904 CheckComArgStrNotEmptyOrNull(aHostname); 905 CheckComArg NotNull(aHostname);905 CheckComArgStrNotEmptyOrNull(aHostname); 906 906 CheckComArgExprMsg(aPort, aPort > 0 && aPort <= 65535, ("is %u", aPort)); 907 907 CheckComArgExprMsg(aMaxDowntime, aMaxDowntime > 0, ("is %u", aMaxDowntime)); -
trunk/src/VBox/Main/GuestImpl.cpp
r26603 r26753 127 127 128 128 // redirect the call to IMachine if no additions are installed 129 if (mData.mAdditionsVersion.is Null())130 return mParent->machine()->COMGETTER(OSTypeId) 129 if (mData.mAdditionsVersion.isEmpty()) 130 return mParent->machine()->COMGETTER(OSTypeId)(aOSTypeId); 131 131 132 132 mData.mOSTypeId.cloneTo(aOSTypeId); … … 262 262 IN_BSTR aDomain, BOOL aAllowInteractiveLogon) 263 263 { 264 CheckComArgNotNull(aUserName);265 CheckComArgNotNull(aPassword);266 CheckComArgNotNull(aDomain);267 268 264 AutoCaller autoCaller(this); 269 265 if (FAILED(autoCaller.rc())) return autoCaller.rc(); … … 315 311 ///////////////////////////////////////////////////////////////////////////// 316 312 317 void Guest::setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType) 318 { 319 Assert(aVersion.isNull() || !aVersion.isEmpty()); 320 313 void Guest::setAdditionsVersion(Bstr aVersion, VBOXOSTYPE aOsType) 314 { 321 315 AutoCaller autoCaller(this); 322 316 AssertComRCReturnVoid (autoCaller.rc()); … … 325 319 326 320 mData.mAdditionsVersion = aVersion; 327 mData.mAdditionsActive = !aVersion.is Null();321 mData.mAdditionsActive = !aVersion.isEmpty(); 328 322 329 323 mData.mOSTypeId = Global::OSTypeId (aOsType); -
trunk/src/VBox/Main/HostImpl.cpp
r26603 r26753 451 451 if(hr == S_OK) 452 452 { 453 size_t cUnicodeName = wcslen(lpszName) + 1; 454 size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR); 455 Bstr name (uniLen + 1 /* extra zero */); 456 wcscpy((wchar_t *) name.mutableRaw(), lpszName); 453 Bstr name((CBSTR)lpszName); 457 454 458 455 hr = pncc->GetInstanceGuid(&IfGuid); … … 1290 1287 STDMETHODIMP Host::FindHostDVDDrive(IN_BSTR aName, IMedium **aDrive) 1291 1288 { 1292 CheckComArg NotNull(aName);1289 CheckComArgStrNotEmptyOrNull(aName); 1293 1290 CheckComArgOutPointerValid(aDrive); 1294 1291 … … 1317 1314 STDMETHODIMP Host::FindHostFloppyDrive(IN_BSTR aName, IMedium **aDrive) 1318 1315 { 1319 CheckComArg NotNull(aName);1316 CheckComArgStrNotEmptyOrNull(aName); 1320 1317 CheckComArgOutPointerValid(aDrive); 1321 1318 … … 1451 1448 { 1452 1449 #ifdef VBOX_WITH_USB 1453 CheckComArg NotNull(aAddress);1450 CheckComArgStrNotEmptyOrNull(aAddress); 1454 1451 CheckComArgOutPointerValid(aDevice); 1455 1452 -
trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp
r26603 r26753 423 423 { 424 424 m.realIPAddress = 0; 425 if (FAILED(mVBox->SetExtraData(Bstr (Utf8StrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw())), Bstr(""))))425 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()), NULL))) 426 426 return E_FAIL; 427 if (FAILED(mVBox->SetExtraData(Bstr (Utf8StrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw())), Bstr(""))))427 if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()), NULL))) 428 428 return E_FAIL; 429 429 return S_OK; -
trunk/src/VBox/Main/MachineImpl.cpp
r26738 r26753 697 697 STDMETHODIMP Machine::COMSETTER(Name)(IN_BSTR aName) 698 698 { 699 CheckComArgNotNull(aName); 700 701 if (!*aName) 702 return setError(E_INVALIDARG, 703 tr("Machine name cannot be empty")); 699 CheckComArgStrNotEmptyOrNull(aName); 704 700 705 701 AutoCaller autoCaller(this); … … 779 775 STDMETHODIMP Machine::COMSETTER(OSTypeId)(IN_BSTR aOSTypeId) 780 776 { 781 CheckComArg NotNull(aOSTypeId);777 CheckComArgStrNotEmptyOrNull(aOSTypeId); 782 778 783 779 AutoCaller autoCaller(this); … … 1930 1926 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1931 1927 1932 if (mData->mSession.mType.isNull()) 1933 Bstr("").cloneTo(aSessionType); 1934 else 1935 mData->mSession.mType.cloneTo(aSessionType); 1928 mData->mSession.mType.cloneTo(aSessionType); 1936 1929 1937 1930 return S_OK; … … 1990 1983 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1991 1984 1992 if (mSSData->mStateFilePath.isEmpty()) 1993 Bstr("").cloneTo(aStateFilePath); 1994 else 1995 mSSData->mStateFilePath.cloneTo(aStateFilePath); 1985 mSSData->mStateFilePath.cloneTo(aStateFilePath); 1996 1986 1997 1987 return S_OK; … … 2137 2127 Machine::COMSETTER(GuestPropertyNotificationPatterns)(IN_BSTR aPatterns) 2138 2128 { 2139 CheckComArgNotNull(aPatterns);2140 2129 AutoCaller autoCaller(this); 2141 2130 if (FAILED(autoCaller.rc())) return autoCaller.rc(); … … 2403 2392 aControllerName, aControllerPort, aDevice, aType, aId)); 2404 2393 2405 CheckComArgNotNull(aControllerName); 2406 CheckComArgNotNull(aId); 2394 CheckComArgStrNotEmptyOrNull(aControllerName); 2407 2395 2408 2396 AutoCaller autoCaller(this); … … 2829 2817 LONG aDevice) 2830 2818 { 2831 CheckComArg NotNull(aControllerName);2819 CheckComArgStrNotEmptyOrNull(aControllerName); 2832 2820 2833 2821 LogFlowThisFunc(("aControllerName=\"%ls\" aControllerPort=%ld aDevice=%ld\n", … … 2914 2902 LONG aDevice, BOOL aPassthrough) 2915 2903 { 2916 CheckComArg NotNull(aControllerName);2904 CheckComArgStrNotEmptyOrNull(aControllerName); 2917 2905 2918 2906 LogFlowThisFunc(("aControllerName=\"%ls\" aControllerPort=%ld aDevice=%ld aPassthrough=%d\n", … … 2968 2956 aControllerName, aControllerPort, aDevice, aForce)); 2969 2957 2970 CheckComArg NotNull(aControllerName);2971 CheckComArg NotNull(aId);2958 CheckComArgStrNotEmptyOrNull(aControllerName); 2959 CheckComArgStrNotEmptyOrNull(aId); 2972 2960 2973 2961 AutoCaller autoCaller(this); … … 3109 3097 aControllerName, aControllerPort, aDevice)); 3110 3098 3111 CheckComArg NotNull(aControllerName);3099 CheckComArgStrNotEmptyOrNull(aControllerName); 3112 3100 CheckComArgOutPointerValid(aMedium); 3113 3101 … … 3208 3196 BSTR *aValue) 3209 3197 { 3210 CheckComArg NotNull(aKey);3198 CheckComArgStrNotEmptyOrNull(aKey); 3211 3199 CheckComArgOutPointerValid(aValue); 3212 3200 … … 3235 3223 STDMETHODIMP Machine::SetExtraData(IN_BSTR aKey, IN_BSTR aValue) 3236 3224 { 3237 CheckComArg NotNull(aKey);3225 CheckComArgStrNotEmptyOrNull(aKey); 3238 3226 3239 3227 AutoCaller autoCaller(this); … … 3266 3254 // lock to copy the list of callbacks to invoke 3267 3255 Bstr error; 3268 Bstr bstrValue; 3269 if (aValue) 3270 bstrValue = aValue; 3271 else 3272 bstrValue = (const char *)""; 3256 Bstr bstrValue(aValue); 3273 3257 3274 3258 if (!mParent->onExtraDataCanChange(mData->mUuid, aKey, bstrValue, error)) 3275 3259 { 3276 3260 const char *sep = error.isEmpty() ? "" : ": "; 3277 CBSTR err = error. isNull() ? (CBSTR) L"" : error.raw();3261 CBSTR err = error.raw(); 3278 3262 LogWarningFunc(("Someone vetoed! Change refused%s%ls\n", 3279 3263 sep, err)); … … 3459 3443 STDMETHODIMP Machine::FindSnapshot(IN_BSTR aName, ISnapshot **aSnapshot) 3460 3444 { 3461 CheckComArg NotNull(aName);3445 CheckComArgStrNotEmptyOrNull(aName); 3462 3446 CheckComArgOutPointerValid(aSnapshot); 3463 3447 … … 3485 3469 STDMETHODIMP Machine::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable) 3486 3470 { 3487 CheckComArg NotNull(aName);3488 CheckComArg NotNull(aHostPath);3471 CheckComArgStrNotEmptyOrNull(aName); 3472 CheckComArgStrNotEmptyOrNull(aHostPath); 3489 3473 3490 3474 AutoCaller autoCaller(this); … … 3520 3504 STDMETHODIMP Machine::RemoveSharedFolder(IN_BSTR aName) 3521 3505 { 3522 CheckComArg NotNull(aName);3506 CheckComArgStrNotEmptyOrNull(aName); 3523 3507 3524 3508 AutoCaller autoCaller(this); … … 3610 3594 ReturnComNotImplemented(); 3611 3595 #else // VBOX_WITH_GUEST_PROPS 3612 CheckComArg NotNull(aName);3596 CheckComArgStrNotEmptyOrNull(aName); 3613 3597 CheckComArgOutPointerValid(aValue); 3614 3598 CheckComArgOutPointerValid(aTimestamp); … … 3689 3673 using namespace guestProp; 3690 3674 3691 CheckComArgNotNull(aName); 3692 CheckComArgNotNull(aValue); 3675 CheckComArgStrNotEmptyOrNull(aName); 3693 3676 if ((aFlags != NULL) && !VALID_PTR(aFlags)) 3694 3677 return E_INVALIDARG; … … 3934 3917 aControllerName, aControllerPort, aDevice)); 3935 3918 3936 CheckComArg NotNull(aControllerName);3919 CheckComArgStrNotEmptyOrNull(aControllerName); 3937 3920 CheckComArgOutPointerValid(aAttachment); 3938 3921 … … 8950 8933 #endif /* VBOX_WITH_USB */ 8951 8934 8952 if (!mData->mSession.mType.is Null())8935 if (!mData->mSession.mType.isEmpty()) 8953 8936 { 8954 8937 /* mType is not null when this machine's process has been started by … … 9658 9641 using namespace guestProp; 9659 9642 9660 CheckComArg NotNull(aName);9643 CheckComArgStrNotEmptyOrNull(aName); 9661 9644 if (aValue != NULL && (!VALID_PTR(aValue) || !VALID_PTR(aFlags))) 9662 9645 return E_POINTER; /* aValue can be NULL to indicate deletion */ -
trunk/src/VBox/Main/Matching.cpp
r26603 r26753 196 196 197 197 // empty or null mSimple matches any match 198 return 199 mSimple.isEmpty() || 200 (mIgnoreCase && mSimple.compareIgnoreCase (aValue) == 0) || 201 (!mIgnoreCase && mSimple.compare (aValue) == 0); 198 return mSimple.isEmpty() 199 || (mIgnoreCase && mSimple.compare(aValue, Bstr::CaseInsensitive) == 0) 200 || (!mIgnoreCase && mSimple.compare(aValue) == 0); 202 201 } 203 202 -
trunk/src/VBox/Main/MediumImpl.cpp
r26603 r26753 1361 1361 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1362 1362 1363 if (m->strDescription.isEmpty()) 1364 Bstr("").cloneTo(aDescription); 1365 else 1366 m->strDescription.cloneTo(aDescription); 1363 m->strDescription.cloneTo(aDescription); 1367 1364 1368 1365 return S_OK; … … 1371 1368 STDMETHODIMP Medium::COMSETTER(Description)(IN_BSTR aDescription) 1372 1369 { 1373 CheckComArgNotNull(aDescription);1374 1375 1370 AutoCaller autoCaller(this); 1376 1371 if (FAILED(autoCaller.rc())) return autoCaller.rc(); … … 1415 1410 STDMETHODIMP Medium::COMSETTER(Location)(IN_BSTR aLocation) 1416 1411 { 1417 CheckComArg NotNull(aLocation);1412 CheckComArgStrNotEmptyOrNull(aLocation); 1418 1413 1419 1414 AutoCaller autoCaller(this); … … 1725 1720 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1726 1721 1727 if (m->strLastAccessError.isEmpty()) 1728 Bstr("").cloneTo(aLastAccessError); 1729 else 1730 m->strLastAccessError.cloneTo(aLastAccessError); 1722 m->strLastAccessError.cloneTo(aLastAccessError); 1731 1723 1732 1724 return S_OK; … … 2102 2094 tr("Property '%ls' does not exist"), aName); 2103 2095 2104 if (it->second.isEmpty()) 2105 Bstr("").cloneTo(aValue); 2106 else 2107 it->second.cloneTo(aValue); 2096 it->second.cloneTo(aValue); 2108 2097 2109 2098 return S_OK; … … 2169 2158 { 2170 2159 it->first.cloneTo(&names[i]); 2171 if (it->second.isEmpty()) 2172 Bstr("").cloneTo(&values[i]); 2173 else 2174 it->second.cloneTo(&values[i]); 2175 ++ i; 2160 it->second.cloneTo(&values[i]); 2161 ++i; 2176 2162 } 2177 2163 … … 2362 2348 2363 2349 STDMETHODIMP Medium::CloneTo(IMedium *aTarget, 2364 2365 2366 2350 MediumVariant_T aVariant, 2351 IMedium *aParent, 2352 IProgress **aProgress) 2367 2353 { 2368 2354 CheckComArgNotNull(aTarget); … … 3090 3076 { 3091 3077 /* only save properties that have non-default values */ 3092 if (!it->second.is Null())3078 if (!it->second.isEmpty()) 3093 3079 { 3094 3080 Utf8Str name = it->first; … … 4858 4844 4859 4845 /* we interpret null values as "no value" in Medium */ 4860 if (it->second.is Null())4846 if (it->second.isEmpty()) 4861 4847 return VERR_CFGM_VALUE_NOT_FOUND; 4862 4848 … … 4885 4871 4886 4872 /* we interpret null values as "no value" in Medium */ 4887 if (it->second.is Null())4873 if (it->second.isEmpty()) 4888 4874 return VERR_CFGM_VALUE_NOT_FOUND; 4889 4875 -
trunk/src/VBox/Main/NetworkAdapterImpl.cpp
r26603 r26753 1026 1026 case NetworkAttachmentType_NAT: 1027 1027 mData->mNATNetwork = data.strName; 1028 if (mData->mNATNetwork.isNull())1029 mData->mNATNetwork = "";1030 1028 rc = AttachToNAT(); 1031 1029 if (FAILED(rc)) return rc; … … 1041 1039 case NetworkAttachmentType_Internal: 1042 1040 mData->mInternalNetwork = data.strName; 1043 Assert(!mData->mInternalNetwork.is Null());1041 Assert(!mData->mInternalNetwork.isEmpty()); 1044 1042 1045 1043 rc = AttachToInternalNetwork(); -
trunk/src/VBox/Main/RemoteUSBDeviceImpl.cpp
r26603 r26753 142 142 143 143 /* this is const, no need to lock */ 144 Bstr(mData.id).cloneTo(aId);144 mData.id.toUtf16().detachTo(aId); 145 145 146 146 return S_OK; -
trunk/src/VBox/Main/SessionImpl.cpp
r26603 r26753 694 694 Global::stringifySessionState(mState)); 695 695 AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE); 696 CheckComArg NotNull(aName);696 CheckComArgStrNotEmptyOrNull(aName); 697 697 if (!aIsSetter && !VALID_PTR(aRetValue)) 698 698 return E_POINTER; -
trunk/src/VBox/Main/SharedFolderImpl.cpp
r26603 r26753 333 333 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 334 334 335 if (m.lastAccessError.isEmpty()) 336 Bstr("").cloneTo(aLastAccessError); 337 else 338 m.lastAccessError.cloneTo(aLastAccessError); 335 m.lastAccessError.cloneTo(aLastAccessError); 339 336 340 337 return S_OK; -
trunk/src/VBox/Main/SnapshotImpl.cpp
r26603 r26753 342 342 STDMETHODIMP Snapshot::COMSETTER(Name)(IN_BSTR aName) 343 343 { 344 CheckComArg NotNull(aName);344 CheckComArgStrNotEmptyOrNull(aName); 345 345 346 346 AutoCaller autoCaller(this); … … 378 378 STDMETHODIMP Snapshot::COMSETTER(Description)(IN_BSTR aDescription) 379 379 { 380 CheckComArgNotNull(aDescription);381 382 380 AutoCaller autoCaller(this); 383 381 if (FAILED(autoCaller.rc())) return autoCaller.rc(); -
trunk/src/VBox/Main/SystemPropertiesImpl.cpp
r26603 r26753 828 828 /* MediumFormat is all const, no need to lock */ 829 829 830 if ((*it)->id().compare IgnoreCase (aFormat) == 0)830 if ((*it)->id().compare(aFormat, Bstr::CaseInsensitive) == 0) 831 831 { 832 832 format = *it; -
trunk/src/VBox/Main/USBControllerImpl.cpp
r26603 r26753 1110 1110 rc = aUSBDevice->COMGETTER(Manufacturer) (manufacturer.asOutParam()); 1111 1111 ComAssertComRCRet(rc, false); 1112 if (!manufacturer.is Null())1112 if (!manufacturer.isEmpty()) 1113 1113 USBFilterSetStringExact (&dev, USBFILTERIDX_MANUFACTURER_STR, Utf8Str(manufacturer).c_str(), true); 1114 1114 … … 1116 1116 rc = aUSBDevice->COMGETTER(Product) (product.asOutParam()); 1117 1117 ComAssertComRCRet(rc, false); 1118 if (!product.is Null())1118 if (!product.isEmpty()) 1119 1119 USBFilterSetStringExact (&dev, USBFILTERIDX_PRODUCT_STR, Utf8Str(product).c_str(), true); 1120 1120 … … 1122 1122 rc = aUSBDevice->COMGETTER(SerialNumber) (serialNumber.asOutParam()); 1123 1123 ComAssertComRCRet(rc, false); 1124 if (!serialNumber.is Null())1124 if (!serialNumber.isEmpty()) 1125 1125 USBFilterSetStringExact (&dev, USBFILTERIDX_SERIAL_NUMBER_STR, Utf8Str(serialNumber).c_str(), true); 1126 1126 -
trunk/src/VBox/Main/USBDeviceImpl.cpp
r26603 r26753 155 155 156 156 /* this is const, no need to lock */ 157 Guid(mData.id).to String().cloneTo(aId);157 Guid(mData.id).toUtf16().detachTo(aId); 158 158 159 159 return S_OK; -
trunk/src/VBox/Main/VFSExplorerImpl.cpp
r25860 r26753 561 561 STDMETHODIMP VFSExplorer::Cd(IN_BSTR aDir, IProgress **aProgress) 562 562 { 563 CheckComArg NotNull(aDir);563 CheckComArgStrNotEmptyOrNull(aDir); 564 564 CheckComArgOutPointerValid(aProgress); 565 565 -
trunk/src/VBox/Main/VirtualBoxBase.cpp
r26603 r26753 810 810 */ 811 811 /* static */ 812 HRESULT VirtualBoxSupportErrorInfoImplBase::setErrorInternal ( 813 HRESULT aResultCode, const GUID &aIID, 814 const Bstr &aComponent, const Bstr &aText, 815 bool aWarning, bool aLogIt) 812 HRESULT VirtualBoxSupportErrorInfoImplBase::setErrorInternal(HRESULT aResultCode, 813 const GUID &aIID, 814 const wchar_t *aComponent, 815 const Bstr &aText, 816 bool aWarning, 817 bool aLogIt) 816 818 { 817 819 /* whether multi-error mode is turned on */ 818 bool preserve = ((uintptr_t) RTTlsGet (MultiResult::sCounter)) > 0; 820 bool preserve = ((uintptr_t)RTTlsGet(MultiResult::sCounter)) > 0; 821 822 Bstr bstrComponent((CBSTR)aComponent); 819 823 820 824 if (aLogIt) 821 LogRel 822 823 aResultCode, aResultCode, &aIID, aComponent.raw(), aText.raw(), aWarning,824 825 LogRel(("ERROR [COM]: aRC=%Rhrc (%#08x) aIID={%RTuuid} aComponent={%ls} aText={%ls} " 826 "aWarning=%RTbool, preserve=%RTbool\n", 827 aResultCode, aResultCode, &aIID, bstrComponent.raw(), aText.raw(), aWarning, 828 preserve)); 825 829 826 830 /* these are mandatory, others -- not */ … … 870 874 871 875 /* set the current error info and preserve the previous one if any */ 872 rc = info->init (aResultCode, aIID, aComponent, aText, curInfo);876 rc = info->init(aResultCode, aIID, bstrComponent, aText, curInfo); 873 877 if (FAILED(rc)) break; 874 878 … … 914 918 915 919 /* set the current error info and preserve the previous one if any */ 916 rc = info->init (aResultCode, aIID, aComponent, aText, curInfo);920 rc = info->init(aResultCode, aIID, bstrComponent, aText, curInfo); 917 921 if (FAILED(rc)) break; 918 922 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r26603 r26753 302 302 LogFlowThisFuncEnter(); 303 303 304 if (sVersion.is Null())304 if (sVersion.isEmpty()) 305 305 sVersion = VBOX_VERSION_STRING; 306 306 sRevision = RTBldCfgRevision(); 307 if (sPackageType.is Null())307 if (sPackageType.isEmpty()) 308 308 sPackageType = VBOX_PACKAGE_STRING; 309 309 LogFlowThisFunc(("Version: %ls, Package: %ls\n", sVersion.raw(), sPackageType.raw())); … … 1225 1225 LogFlowThisFunc(("aName=\"%ls\", aMachine={%p}\n", aName, aMachine)); 1226 1226 1227 CheckComArg NotNull(aName);1227 CheckComArgStrNotEmptyOrNull(aName); 1228 1228 CheckComArgOutSafeArrayPointerValid(aMachine); 1229 1229 … … 1342 1342 STDMETHODIMP VirtualBox::OpenHardDisk(IN_BSTR aLocation, 1343 1343 AccessMode_T accessMode, 1344 BOOL aSetImageId, IN_BSTR aImageId, 1345 BOOL aSetParentId, IN_BSTR aParentId, 1344 BOOL aSetImageId, 1345 IN_BSTR aImageId, 1346 BOOL aSetParentId, 1347 IN_BSTR aParentId, 1346 1348 IMedium **aHardDisk) 1347 1349 { 1348 CheckComArgNotNull(aLocation); 1349 CheckComArgNotNull(aImageId); 1350 CheckComArgNotNull(aParentId); 1350 CheckComArgStrNotEmptyOrNull(aLocation); 1351 1351 CheckComArgOutSafeArrayPointerValid(aHardDisk); 1352 1352 … … 1423 1423 IMedium **aHardDisk) 1424 1424 { 1425 CheckComArg NotNull(aLocation);1425 CheckComArgStrNotEmptyOrNull(aLocation); 1426 1426 CheckComArgOutSafeArrayPointerValid(aHardDisk); 1427 1427 … … 1499 1499 STDMETHODIMP VirtualBox::FindDVDImage (IN_BSTR aLocation, IMedium **aDVDImage) 1500 1500 { 1501 CheckComArg NotNull(aLocation);1501 CheckComArgStrNotEmptyOrNull(aLocation); 1502 1502 CheckComArgOutSafeArrayPointerValid(aDVDImage); 1503 1503 … … 1578 1578 IMedium **aFloppyImage) 1579 1579 { 1580 CheckComArg NotNull(aLocation);1580 CheckComArgStrNotEmptyOrNull(aLocation); 1581 1581 CheckComArgOutSafeArrayPointerValid(aFloppyImage); 1582 1582 … … 1615 1615 }; 1616 1616 1617 CheckComArgNotNull 1617 CheckComArgNotNull(aType); 1618 1618 1619 1619 AutoCaller autoCaller(this); … … 1639 1639 { 1640 1640 const Bstr &typeId = (*it)->id(); 1641 AssertMsg (!!typeId, ("ID must not be NULL"));1642 if (typeId.compare IgnoreCase (id) == 0)1641 AssertMsg(!typeId.isEmpty(), ("ID must not be NULL")); 1642 if (typeId.compare(id, Bstr::CaseInsensitive) == 0) 1643 1643 { 1644 1644 (*it).queryInterfaceTo(aType); … … 1655 1655 STDMETHODIMP VirtualBox::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */) 1656 1656 { 1657 CheckComArg NotNull(aName);1658 CheckComArg NotNull(aHostPath);1657 CheckComArgStrNotEmptyOrNull(aName); 1658 CheckComArgStrNotEmptyOrNull(aHostPath); 1659 1659 1660 1660 AutoCaller autoCaller(this); … … 1666 1666 STDMETHODIMP VirtualBox::RemoveSharedFolder(IN_BSTR aName) 1667 1667 { 1668 CheckComArg NotNull(aName);1668 CheckComArgStrNotEmptyOrNull(aName); 1669 1669 1670 1670 AutoCaller autoCaller(this); … … 1709 1709 BSTR *aValue) 1710 1710 { 1711 CheckComArg NotNull(aKey);1711 CheckComArgStrNotEmptyOrNull(aKey); 1712 1712 CheckComArgNotNull(aValue); 1713 1713 … … 1716 1716 1717 1717 /* start with nothing found */ 1718 Bstr bstrResult(""); 1719 1720 settings::ExtraDataItemsMap::const_iterator it = m->pMainConfigFile->mapExtraDataItems.find(Utf8Str(aKey)); 1718 Utf8Str strKey(aKey); 1719 Bstr bstrResult; 1720 1721 settings::ExtraDataItemsMap::const_iterator it = m->pMainConfigFile->mapExtraDataItems.find(strKey); 1721 1722 if (it != m->pMainConfigFile->mapExtraDataItems.end()) 1722 1723 // found: … … 1735 1736 IN_BSTR aValue) 1736 1737 { 1737 CheckComArg NotNull(aKey);1738 CheckComArgStrNotEmptyOrNull(aKey); 1738 1739 1739 1740 AutoCaller autoCaller(this); … … 1766 1767 // lock to copy the list of callbacks to invoke 1767 1768 Bstr error; 1768 Bstr bstrValue; 1769 if (aValue) 1770 bstrValue = aValue; 1771 else 1772 bstrValue = (const char *)""; 1769 Bstr bstrValue(aValue); 1773 1770 1774 1771 if (!onExtraDataCanChange(Guid::Empty, aKey, bstrValue, error)) 1775 1772 { 1776 1773 const char *sep = error.isEmpty() ? "" : ": "; 1777 CBSTR err = error. isNull() ? (CBSTR) L"" : error.raw();1774 CBSTR err = error.raw(); 1778 1775 LogWarningFunc(("Someone vetoed! Change refused%s%ls\n", 1779 1776 sep, err)); … … 1866 1863 LogRel(("remotesession=%s\n", Utf8Str(aMachineId).c_str())); 1867 1864 1868 CheckComArg NotNull(aMachineId);1865 CheckComArgStrNotEmptyOrNull(aMachineId); 1869 1866 CheckComArgNotNull(aSession); 1870 CheckComArg NotNull(aType);1867 CheckComArgStrNotEmptyOrNull(aType); 1871 1868 CheckComArgOutSafeArrayPointerValid(aProgress); 1872 1869 … … 4359 4356 STDMETHODIMP VirtualBox::CreateDHCPServer (IN_BSTR aName, IDHCPServer ** aServer) 4360 4357 { 4361 CheckComArg NotNull(aName);4358 CheckComArgStrNotEmptyOrNull(aName); 4362 4359 CheckComArgNotNull(aServer); 4363 4360 … … 4380 4377 STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName(IN_BSTR aName, IDHCPServer ** aServer) 4381 4378 { 4382 CheckComArg NotNull(aName);4379 CheckComArgStrNotEmptyOrNull(aName); 4383 4380 CheckComArgNotNull(aServer); 4384 4381 … … 4456 4453 4457 4454 ComPtr<IDHCPServer> existing; 4458 rc = FindDHCPServerByNetworkName(name .mutableRaw(), existing.asOutParam());4455 rc = FindDHCPServerByNetworkName(name, existing.asOutParam()); 4459 4456 if (SUCCEEDED(rc)) 4460 4457 { -
trunk/src/VBox/Main/generic/NetIf-generic.cpp
r26603 r26753 234 234 return VERR_INVALID_PARAMETER; 235 235 iface->COMGETTER(Name) (ifname.asOutParam()); 236 if (ifname.is Null())236 if (ifname.isEmpty()) 237 237 return VERR_INTERNAL_ERROR; 238 238 -
trunk/src/VBox/Main/glue/VirtualBoxErrorInfo.cpp
r25149 r26753 202 202 return NS_ERROR_INVALID_POINTER; 203 203 204 Utf8Str 204 Utf8Str(mText).cloneTo(aMessage); 205 205 return S_OK; 206 206 } -
trunk/src/VBox/Main/glue/string.cpp
r26186 r26753 4 4 * 5 5 * MS COM / XPCOM Abstraction Layer: 6 * Smart string classes definition6 * UTF-8 and UTF-16 string classes 7 7 */ 8 8 … … 31 31 { 32 32 33 // BSTR representing a null wide char with 32 bits of length prefix (0); 34 // this will work on Windows as well as other platforms where BSTR does 35 // not use length prefixes 36 const OLECHAR g_achEmptyBstr[3] = { 0, 0, 0 }; 37 const BSTR g_bstrEmpty = (BSTR)(&g_achEmptyBstr[2]); 38 33 39 /* static */ 34 40 const Bstr Bstr::Null; /* default ctor is OK */ … … 36 42 /* static */ 37 43 const Utf8Str Utf8Str::Null; /* default ctor is OK */ 44 45 #if defined (VBOX_WITH_XPCOM) 46 void Utf8Str::cloneTo(char **pstr) const 47 { 48 size_t cb = length() + 1; 49 *pstr = (char*)nsMemory::Alloc(cb); 50 if (!*pstr) 51 throw std::bad_alloc(); 52 memcpy(*pstr, c_str(), cb); 53 } 54 #endif 38 55 39 56 Utf8Str& Utf8Str::toLower() -
trunk/src/VBox/Main/include/VirtualBoxBase.h
r26238 r26753 781 781 class VirtualBoxSupportErrorInfoImplBase 782 782 { 783 static HRESULT setErrorInternal(HRESULT aResultCode, const GUID &aIID, 784 const Bstr &aComponent, const Bstr &aText, 785 bool aWarning, bool aLogIt); 783 static HRESULT setErrorInternal(HRESULT aResultCode, 784 const GUID &aIID, 785 const wchar_t *aComponent, 786 const Bstr &aText, 787 bool aWarning, 788 bool aLogIt); 786 789 787 790 protected: … … 910 913 }; 911 914 912 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 913 const Bstr &aComponent, 915 static HRESULT setError(HRESULT aResultCode, 916 const GUID &aIID, 917 const wchar_t *aComponent, 914 918 const Bstr &aText, 915 919 bool aLogIt = true) … … 919 923 } 920 924 921 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 922 const Bstr &aComponent, 925 static HRESULT setWarning(HRESULT aResultCode, 926 const GUID &aIID, 927 const wchar_t *aComponent, 923 928 const Bstr &aText) 924 929 { … … 927 932 } 928 933 929 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 930 const Bstr &aComponent, 934 static HRESULT setError(HRESULT aResultCode, 935 const GUID &aIID, 936 const wchar_t *aComponent, 931 937 const char *aText, va_list aArgs, bool aLogIt = true) 932 938 { … … 936 942 } 937 943 938 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 939 const Bstr &aComponent, 944 static HRESULT setWarning(HRESULT aResultCode, 945 const GUID &aIID, 946 const wchar_t *aComponent, 940 947 const char *aText, va_list aArgs) 941 948 { … … 1061 1068 va_list args; 1062 1069 va_start(args, aText); 1063 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1064 aResultCode, aIID, aComponent, aText, args, true /* aLogIt */); 1070 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError(aResultCode, 1071 aIID, 1072 aComponent, 1073 aText, 1074 args, 1075 true /* aLogIt */); 1065 1076 va_end(args); 1066 1077 return rc; … … 1115 1126 va_list args; 1116 1127 va_start(args, aText); 1117 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1118 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, true /* aLogIt */); 1128 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError(aResultCode, 1129 COM_IIDOF(I), 1130 C::getComponentName(), 1131 aText, 1132 args, 1133 true /* aLogIt */); 1119 1134 va_end(args); 1120 1135 return rc; … … 1134 1149 va_list args; 1135 1150 va_start(args, aText); 1136 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1137 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args); 1151 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning(aResultCode, 1152 COM_IIDOF(I), 1153 C::getComponentName(), 1154 aText, 1155 args); 1138 1156 va_end(args); 1139 1157 return rc; … … 1152 1170 va_list aArgs) 1153 1171 { 1154 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1155 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs, true /* aLogIt */); 1172 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError(aResultCode, 1173 COM_IIDOF(I), 1174 C::getComponentName(), 1175 aText, 1176 aArgs, 1177 true /* aLogIt */); 1156 1178 return rc; 1157 1179 } … … 1169 1191 va_list aArgs) 1170 1192 { 1171 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1172 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs); 1193 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning(aResultCode, 1194 COM_IIDOF(I), 1195 C::getComponentName(), 1196 aText, 1197 aArgs); 1173 1198 return rc; 1174 1199 } … … 1188 1213 va_list args; 1189 1214 va_start(args, aText); 1190 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1191 aResultCode, aIID, C::getComponentName(), aText, args, true /* aLogIt */); 1215 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError(aResultCode, 1216 aIID, 1217 C::getComponentName(), 1218 aText, 1219 args, 1220 true /* aLogIt */); 1192 1221 va_end(args); 1193 1222 return rc; … … 1208 1237 va_list args; 1209 1238 va_start(args, aText); 1210 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1211 aResultCode, aIID, C::getComponentName(), aText, args); 1239 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning(aResultCode, 1240 aIID, 1241 C::getComponentName(), 1242 aText, 1243 args); 1212 1244 va_end(args); 1213 1245 return rc; … … 1225 1257 va_list args; 1226 1258 va_start(args, aText); 1227 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1228 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, false /* aLogIt */); 1259 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError(aResultCode, 1260 COM_IIDOF(I), 1261 C::getComponentName(), 1262 aText, 1263 args, 1264 false /* aLogIt */); 1229 1265 va_end(args); 1230 1266 return rc; -
trunk/src/VBox/Main/win/NetIf-win.cpp
r26603 r26753 908 908 if(hr == S_OK) 909 909 { 910 size_t cUnicodeName = wcslen(lpszName) + 1; 911 size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR); 912 Bstr name (uniLen + 1 /* extra zero */); 913 wcscpy((wchar_t *) name.mutableRaw(), lpszName); 910 Bstr name(lpszName); 914 911 915 912 hr = pncc->GetInstanceGuid(&IfGuid); -
trunk/src/VBox/Main/win/svcmain.cpp
r26603 r26753 231 231 232 232 if (*lpszToken != NULL) 233 {234 Bstr str (lpszToken);235 LPCTSTR lpszToken2 = FindOneOf(lpszToken, szTokens);236 if (lpszToken2)237 str.mutableRaw()[lpszToken2 - lpszToken] = '\0';238 233 pipeName = Utf8Str(lpszToken); 239 }240 234 } 241 235
Note:
See TracChangeset
for help on using the changeset viewer.