//*-- Author : Valeriy Onuchin 11/09/2000 
//
//
////////////////////////////////////////////////////////////////////////////////
//
// rooStringValue corresponds to String_Value class
//
// The class rooStringValue is a self-describing data type for string values. 
// An instance of this class is called a string value.
//
//______________________________________________________________________________
//  
//             About String Values
//
// A string value provides access to a string object embedded in the data of 
// some persistent object. You obtain a string value for a particular string 
// attribute of a particular persistent object from a class object for that 
// persistent object. To obtain the string value, you call the class object's
// get_string member function, specifying the string attribute of interest.
// Member functions allow you to determine what kind of string object the
// string value contains. Once you know the string type, you can convert the 
// string value to an object that lets you access the string data.
//
//    If a string value contains an instance of an internal string class, 
//    conversion operators allow you to convert it to an instance of the 
//    appropriate class: ooVString, ooUtf8String, or ooSTString. 
//    You can view or modify the persistent string data using the member 
//    functions of the internal class.
//
//    If a string value contains an instance of an application-defined 
//    optimized string class ooString( N), the Optimized_String_Value 
//    constructor allows you to convert the string value to an optimized 
//    string value. You can view or modify the string data with member functions
//    of the optimized string value.

#include "rooObjy.h"
#include <ooas.h>
#include <oo.h>

ClassImp(rooStringValue)

////////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
 rooStringValue::rooStringValue()
{
   // for internal use only

   fImp = 0;
}

//______________________________________________________________________________
 rooStringValue::~rooStringValue()
{
   //  for internal use only
   
//   if(fImp) delete ((String_Value*)fImp);
   fImp = 0;
}

//______________________________________________________________________________
 rooStringValue::rooStringValue(const rooStringValue & str)
{
   // Constructs a string value that is a copy of the specified string value
   // 
   // The copy constructor creates a new string value with the same persistent 
   // string data as the specified string value. Both copies access the same 
   // persistent data. Any change to the string made with one string value will
   // be seen by the other string value.

   String_Value* imp = (String_Value*)str.getImp();
   fImp = new String_Value(*imp);   
}

//______________________________________________________________________________
rooStringValue::operator const char*()
{
   //

   if(!fImp) return 0;

   String_Value strVal = *((String_Value*)fImp);

   switch (strVal.type()) {
      case ooAsStringVSTRING: {
         ooVString vStr = strVal;
         return (const char *)vStr;
         }
      case ooAsStringUTF8: {
         ooUtf8String utf8Str = strVal;
         return (const char *)utf8Str;
      }
      case ooAsStringOPTIMIZED: {
         Optimized_String_Value optStr(strVal);
         return optStr.get_copy();
      }
      default: 
         return 0;
   }
}

//______________________________________________________________________________
 Int_t rooStringValue::type() const
{
   // Returns the type of string object; one of the following:
   //
   // kooAsStringOPTIMIZED indicates an optimized string of class ooString( N).
   // kooAsStringST indicates a Smalltalk string of class ooSTString.
   // kooAsStringUTF8 indicates a Unicode string of class ooUtf8String.
   // kooAsStringVSTRING indicates an ASCII string of class ooVString.
  
   return fImp ? ((String_Value*)fImp)->type() : 0;
}

//______________________________________________________________________________
 Bool_t rooStringValue::is_vstring() const
{
   // Returns kTRUE if this string value contains an ASCII string of class 
   // ooVString; otherwise, kFALSE. 

   return fImp ? ((String_Value*)fImp)->is_vstring() : 0;
}

//______________________________________________________________________________
 Bool_t rooStringValue::is_utf8string() const
{
   // Returns kTRUE if this string value contains a Unicode string of class 
   // ooUtf8String; otherwise, kFALSE. 
   
   return fImp ? ((String_Value*)fImp)->is_utf8string() : 0;
}

//______________________________________________________________________________
 Bool_t rooStringValue::is_ststring() const
{
   // Returns kTRUE if this string value contains a Smalltalk string of class 
   // ooSTString; otherwise, kFALSE.
   
   return fImp ? ((String_Value*)fImp)->is_ststring() : 0;
}

//______________________________________________________________________________
 Bool_t rooStringValue::is_optimized_string() const
{
   // Returns kTRUE if this string value contains an optimized string of class 
   // ooString( N); otherwise, kFALSE. 
   
   return fImp ? ((String_Value*)fImp)->is_optimized_string() : 0;
}

//______________________________________________________________________________
rooStringValue & rooStringValue::operator=(const rooStringValue & str)
{
   // Assignment operator; 
   // sets this string value to a copy of the specified string value.
   //
   // Both copies access the same persistent data. Any change to the string 
   // made with one string value will be seen by the other string value.

   String_Value* strimp = (String_Value*)str.getImp();
   if(fImp) *((String_Value*)fImp) = *strimp;
   else fImp = new String_Value(*strimp);
   return *this;   
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.