< prev index next >

src/java.desktop/windows/native/libawt/windows/awt.h

Print this page




 320     ~JLocalRef() {
 321         if (m_localJRef) {
 322             m_env->DeleteLocalRef((jobject)m_localJRef);
 323         }
 324     }
 325 };
 326 
 327 typedef JLocalRef<jobject> JLObject;
 328 typedef JLocalRef<jstring> JLString;
 329 typedef JLocalRef<jclass>  JLClass;
 330 
 331 /*
 332  * Class to encapsulate the extraction of the java string contents
 333  * into a buffer and the cleanup of the buffer
 334  */
 335 class JavaStringBuffer
 336 {
 337 protected:
 338     LPWSTR m_pStr;
 339     jsize  m_dwSize;
 340     LPCWSTR getNonEmptyString() {
 341         return (NULL==m_pStr)
 342                 ? L""
 343                 : m_pStr;
 344     }
 345 
 346 public:
 347     JavaStringBuffer(jsize cbTCharCount) {
 348         m_dwSize = cbTCharCount;
 349         m_pStr = (0 == m_dwSize)
 350             ? NULL
 351             : (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
 352     }
 353 
 354     JavaStringBuffer(JNIEnv *env, jstring text) {
 355         m_dwSize = (NULL == text)
 356             ? 0
 357             : env->GetStringLength(text);
 358         if (0 == m_dwSize) {
 359             m_pStr = NULL;
 360         } else {
 361             m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
 362             env->GetStringRegion(text, 0, m_dwSize, reinterpret_cast<jchar *>(m_pStr));
 363             m_pStr[m_dwSize] = 0;
 364         }
 365     }
 366 
 367 
 368     ~JavaStringBuffer() {
 369         free(m_pStr);
 370     }
 371 
 372     void Resize(jsize cbTCharCount) {
 373         m_dwSize = cbTCharCount;
 374         //It is ok to have non-null terminated string here.
 375         //The function is used only for space reservation in staff buffer for
 376         //followed data copying process. And that is the reason why we ignore
 377         //the special case m_dwSize==0 here.
 378         m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc, m_pStr, m_dwSize+1, sizeof(WCHAR) );
 379     }
 380     //we are in UNICODE now, so LPWSTR:=:LPTSTR
 381     operator LPCWSTR() { return getNonEmptyString(); }
 382     operator LPARAM() { return (LPARAM)getNonEmptyString(); }
 383     const void *GetData() { return (const void *)getNonEmptyString(); }
 384     jsize  GetSize() { return m_dwSize; }
 385 };
 386 
 387 
 388 #endif  /* _AWT_H_ */


 320     ~JLocalRef() {
 321         if (m_localJRef) {
 322             m_env->DeleteLocalRef((jobject)m_localJRef);
 323         }
 324     }
 325 };
 326 
 327 typedef JLocalRef<jobject> JLObject;
 328 typedef JLocalRef<jstring> JLString;
 329 typedef JLocalRef<jclass>  JLClass;
 330 
 331 /*
 332  * Class to encapsulate the extraction of the java string contents
 333  * into a buffer and the cleanup of the buffer
 334  */
 335 class JavaStringBuffer
 336 {
 337 protected:
 338     LPWSTR m_pStr;
 339     jsize  m_dwSize;
 340     LPWSTR getNonEmptyString() {
 341         return (NULL==m_pStr)
 342                 ? L""
 343                 : m_pStr;
 344     }
 345 
 346 public:
 347     JavaStringBuffer(jsize cbTCharCount) {
 348         m_dwSize = cbTCharCount;
 349         m_pStr = (0 == m_dwSize)
 350             ? NULL
 351             : (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
 352     }
 353 
 354     JavaStringBuffer(JNIEnv *env, jstring text) {
 355         m_dwSize = (NULL == text)
 356             ? 0
 357             : env->GetStringLength(text);
 358         if (0 == m_dwSize) {
 359             m_pStr = NULL;
 360         } else {
 361             m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (m_dwSize+1), sizeof(WCHAR) );
 362             env->GetStringRegion(text, 0, m_dwSize, reinterpret_cast<jchar *>(m_pStr));
 363             m_pStr[m_dwSize] = 0;
 364         }
 365     }
 366 
 367 
 368     ~JavaStringBuffer() {
 369         free(m_pStr);
 370     }
 371 
 372     void Resize(jsize cbTCharCount) {
 373         m_dwSize = cbTCharCount;
 374         //It is ok to have non-null terminated string here.
 375         //The function is used only for space reservation in staff buffer for
 376         //followed data copying process. And that is the reason why we ignore
 377         //the special case m_dwSize==0 here.
 378         m_pStr = (LPWSTR)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc, m_pStr, m_dwSize+1, sizeof(WCHAR) );
 379     }
 380     //we are in UNICODE now, so LPWSTR:=:LPTSTR
 381     operator LPWSTR() { return getNonEmptyString(); }
 382     operator LPARAM() { return (LPARAM)getNonEmptyString(); }
 383     void *GetData() { return (void *)getNonEmptyString(); }
 384     jsize  GetSize() { return m_dwSize; }
 385 };
 386 
 387 
 388 #endif  /* _AWT_H_ */
< prev index next >