Logo Search packages:      
Sourcecode: jaula version File versions

Value * JAULA::Value::duplicate ( Value const &  orig  )  [static, inherited]

Creates a duplicate of a value.

orig Original instance to duplicate.
a pointer to memory taken from the heap (by means of the new operator) and containing a deep copy of the original value.
As this method returns a pointer to memory allocated from the heap, it is up to the caller to release once it is no longer needed in order to avoid leaks.

Definition at line 85 of file jaula_value.cc.

References JAULA::Exception::addOrigin(), JAULA::Value_Object::getData(), JAULA::Value_Array::getData(), JAULA::Value_Number::getData(), JAULA::Value_Number_Int::getData(), getData(), and JAULA::Value_Boolean::getData().

Referenced by JAULA::Value_Array::addItem(), JAULA::Value_Object::insertItem(), JAULA::Value_Object::set(), JAULA::Value_Array::set(), JAULA::Value_Array::Value_Array(), and JAULA::Value_Object::Value_Object().


      {                          // Null Value
        Value_Null const *pOrg = dynamic_cast<Value_Null const *>(&orig);
        if (pOrg)
          return new Value_Null();
      }                          // Null Value

      {                          // Boolean Value
        Value_Boolean const *pOrg =
          dynamic_cast<Value_Boolean const *>(&orig);
        if (pOrg)
          return new Value_Boolean(pOrg->getData());
      }                          // Boolean Value

      {                          // String Value
        Value_String const *pOrg = dynamic_cast<Value_String const *>(&orig);
        if (pOrg)
          return new Value_String(pOrg->getData());
      }                          // String Value

      {                          // Number (Int) Value
        Value_Number_Int const *pOrg =
          dynamic_cast<Value_Number_Int const *>(&orig);
        if (pOrg)
          return new Value_Number_Int(pOrg->getData());
      }                          // Number (Int) Value

      {                          // Number Value
        Value_Number const *pOrg = dynamic_cast<Value_Number const *>(&orig);
        if (pOrg)
          return new Value_Number(pOrg->getData());
      }                          // Number Value

      {                          // Array Value
        Value_Array const *pOrg = dynamic_cast<Value_Array const *>(&orig);
        if (pOrg)
          return new Value_Array(pOrg->getData());
      }                          // Array Value

      {                          // Object Value
        Value_Object const *pOrg = dynamic_cast<Value_Object const *>(&orig);
        if (pOrg)
          return new Value_Object(pOrg->getData());
      }                          // Object Value

      throw Bad_Data_Type("Unsupported data type detected"
        , "generating a deep copy of a value");
    catch(Exception &ex)
      // This should never happen unless there is a serious
      // bug in the code so exceptions will be only display
      // in extended debugging mode
      ex.addOrigin("Value::duplicate(Value const &)");
      std::cout << ex;
      return new Value_Null();

Generated by  Doxygen 1.6.0   Back to index