0023912: TDataStd_ExtStringArray::Value() returns a copy of TCollection_ExtendedStrin...
authorvro <vro@opencascade.com>
Thu, 16 May 2013 07:07:43 +0000 (11:07 +0400)
committervro <vro@opencascade.com>
Thu, 16 May 2013 07:07:43 +0000 (11:07 +0400)
Since now TDataStd_ExtStringArray::Value() returns a constant reference to the string value.
Also, a draw-command GetExtStringArray is modified to manipulate with the string by a constant reference.
Added test case bugs/caf/bug23912

src/DDataStd/DDataStd_BasicCommands.cxx
src/TDataStd/TDataStd_ExtStringArray.cdl
src/TDataStd/TDataStd_ExtStringArray.cxx
tests/bugs/caf/bug23912 [new file with mode: 0644]

index 8174246..2be18b8 100755 (executable)
@@ -952,12 +952,9 @@ static Standard_Integer DDataStd_GetExtStringArray (Draw_Interpretor& di,
     return 1;
   }
   
-  TCollection_ExtendedString anExtendedString;
-  TCollection_AsciiString anAsciiString;
   for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){
-    anExtendedString = A->Value(i);
-    anAsciiString = TCollection_AsciiString (A->Value(i),'?');
-    //cout << anAsciiString.ToCString() << endl;
+    const TCollection_ExtendedString& anExtendedString = A->Value(i);
+    TCollection_AsciiString anAsciiString(A->Value(i),'?');
     di << anAsciiString.ToCString();
     if(i<A->Upper())  
       di<<" ";
index 5809189..693e4bb 100755 (executable)
@@ -64,6 +64,7 @@ is
     Value (me; Index : Integer from Standard)
     ---Purpose: Returns the value of  the  <Index>th element of the array
     --
+    ---C++: return const &
     ---C++: alias operator ()
     returns ExtendedString from TCollection;
 
index fdc7b02..f7478da 100755 (executable)
@@ -99,18 +99,20 @@ void TDataStd_ExtStringArray::SetValue(const Standard_Integer index, const TColl
 
 
 //=======================================================================
-//function : GetValue
+//function : Value
 //purpose  : 
 //=======================================================================
 
-TCollection_ExtendedString TDataStd_ExtStringArray::Value (const Standard_Integer index) const 
+const TCollection_ExtendedString& TDataStd_ExtStringArray::Value (const Standard_Integer index) const 
 {
-  if(myValue.IsNull()) return TCollection_ExtendedString();
-  return myValue->Value(index); 
+    if (myValue.IsNull()) 
+    {
+        static TCollection_ExtendedString staticEmptyValue;
+        return staticEmptyValue;
+    }
+    return myValue->Value(index); 
 }
 
-
-
 //=======================================================================
 //function : Lower
 //purpose  : 
diff --git a/tests/bugs/caf/bug23912 b/tests/bugs/caf/bug23912
new file mode 100644 (file)
index 0000000..6509a82
--- /dev/null
@@ -0,0 +1,24 @@
+puts "============"
+puts "OCC23912"
+puts "============"
+puts ""
+###################################################################################################################
+# TDataStd_ExtStringArray::Value() returns a copy of TCollection_ExtededString, but it might return a reference
+###################################################################################################################
+
+NewDocument D
+SetExtStringArray D 0:1 0 1 5 "A" "B" "C" "D" "E"
+set info [GetExtStringArray D 0:1]
+
+if { [regexp "A B C D E" $info] != 1 } {
+    puts "Error : function returns wrong value"
+} else {
+    puts "OK : function works properly"
+}
+
+
+
+
+
+
+