1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-05 11:24:17 +03:00
occt/src/TDataStd/TDataStd_ByteArray.cxx
dpasukhi a5a7b3185b Coding - Apply .clang-format formatting #286
Update empty method guards to new style with regex (see PR).
Used clang-format 18.1.8.
New actions to validate code formatting is added.
Update .clang-format with disabling of include sorting.
  It is temporary changes, then include will be sorted.
Apply formatting for /src and /tools folder.
The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
2025-01-26 00:43:57 +00:00

312 lines
10 KiB
C++

// Created on: 2007-05-29
// Created by: Vlad Romashko
// Copyright (c) 2007-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <TDataStd_ByteArray.hxx>
#include <Standard_Dump.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Type.hxx>
#include <TDataStd_DeltaOnModificationOfByteArray.hxx>
#include <TDF_Attribute.hxx>
#include <TDF_DefaultDeltaOnModification.hxx>
#include <TDF_DeltaOnModification.hxx>
#include <TDF_Label.hxx>
#include <TDF_RelocationTable.hxx>
IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ByteArray, TDF_Attribute)
//=================================================================================================
const Standard_GUID& TDataStd_ByteArray::GetID()
{
static Standard_GUID TDataStd_ByteArrayID("FD9B918F-2980-4c66-85E0-D71965475290");
return TDataStd_ByteArrayID;
}
//=======================================================================
// function : TDataStd_ByteArray
// purpose : Empty Constructor
//=======================================================================
TDataStd_ByteArray::TDataStd_ByteArray()
: myIsDelta(Standard_False),
myID(GetID())
{
}
//=======================================================================
// function : SetAttr
// purpose : Implements Set functionality
//=======================================================================
static Handle(TDataStd_ByteArray) SetAttr(const TDF_Label& label,
const Standard_Integer lower,
const Standard_Integer upper,
const Standard_Boolean isDelta,
const Standard_GUID& theGuid)
{
Handle(TDataStd_ByteArray) A;
if (!label.FindAttribute(theGuid, A))
{
A = new TDataStd_ByteArray;
A->Init(lower, upper);
A->SetDelta(isDelta);
A->SetID(theGuid);
label.AddAttribute(A);
}
else if (lower != A->Lower() || upper != A->Upper())
{
A->Init(lower, upper);
}
return A;
}
//=================================================================================================
void TDataStd_ByteArray::Init(const Standard_Integer lower, const Standard_Integer upper)
{
Standard_RangeError_Raise_if(upper < lower, "TDataStd_ByteArray::Init");
Backup();
myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
}
//=================================================================================================
Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
const Standard_Integer lower,
const Standard_Integer upper,
const Standard_Boolean isDelta)
{
return SetAttr(label, lower, upper, isDelta, GetID());
}
//=======================================================================
// function : Set
// purpose : Set user defined attribute with specific ID
//=======================================================================
Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
const Standard_GUID& theGuid,
const Standard_Integer lower,
const Standard_Integer upper,
const Standard_Boolean isDelta)
{
return SetAttr(label, lower, upper, isDelta, theGuid);
}
//=================================================================================================
void TDataStd_ByteArray::SetValue(const Standard_Integer index, const Standard_Byte value)
{
if (myValue.IsNull())
return;
if (value == myValue->Value(index))
return;
Backup();
myValue->SetValue(index, value);
}
//=================================================================================================
Standard_Byte TDataStd_ByteArray::Value(const Standard_Integer index) const
{
return myValue->Value(index);
}
//=================================================================================================
Standard_Integer TDataStd_ByteArray::Lower(void) const
{
if (myValue.IsNull())
return 0;
return myValue->Lower();
}
//=================================================================================================
Standard_Integer TDataStd_ByteArray::Upper(void) const
{
if (myValue.IsNull())
return -1;
return myValue->Upper();
}
//=================================================================================================
Standard_Integer TDataStd_ByteArray::Length(void) const
{
if (myValue.IsNull())
return 0;
return myValue->Length();
}
//=======================================================================
// function : ChangeArray
// purpose : If value of <newArray> differs from <myValue>, Backup
// : performed and myValue refers to new instance of HArray1OfByte
// : that holds <newArray>
//=======================================================================
void TDataStd_ByteArray::ChangeArray(const Handle(TColStd_HArray1OfByte)& newArray,
const Standard_Boolean isCheckItems)
{
Standard_Integer aLower = newArray->Lower();
Standard_Integer anUpper = newArray->Upper();
Standard_Boolean aDimEqual = Standard_False;
Standard_Integer i;
if (Lower() == aLower && Upper() == anUpper)
{
aDimEqual = Standard_True;
if (isCheckItems)
{
Standard_Boolean isEqual = Standard_True;
for (i = aLower; i <= anUpper; i++)
{
if (myValue->Value(i) != newArray->Value(i))
{
isEqual = Standard_False;
break;
}
}
if (isEqual)
return;
}
}
Backup();
// Handles of myValue of current and backuped attributes will be different!
if (myValue.IsNull() || !aDimEqual)
myValue = new TColStd_HArray1OfByte(aLower, anUpper);
for (i = aLower; i <= anUpper; i++)
myValue->SetValue(i, newArray->Value(i));
}
//=================================================================================================
const Standard_GUID& TDataStd_ByteArray::ID() const
{
return myID;
}
//=================================================================================================
void TDataStd_ByteArray::SetID(const Standard_GUID& theGuid)
{
if (myID == theGuid)
return;
Backup();
myID = theGuid;
}
//=======================================================================
// function : SetID
// purpose : sets default ID
//=======================================================================
void TDataStd_ByteArray::SetID()
{
Backup();
myID = GetID();
}
//=================================================================================================
Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty() const
{
return new TDataStd_ByteArray();
}
//=================================================================================================
void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With)
{
Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
if (!anArray->myValue.IsNull())
{
const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
myValue = new TColStd_HArray1OfByte(lower, upper);
for (; i <= upper; i++)
myValue->SetValue(i, with_array.Value(i));
myIsDelta = anArray->myIsDelta;
myID = anArray->ID();
}
else
myValue.Nullify();
}
//=================================================================================================
void TDataStd_ByteArray::Paste(const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)&) const
{
if (!myValue.IsNull())
{
Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
if (!anAtt.IsNull())
{
anAtt->ChangeArray(myValue, Standard_False);
anAtt->SetDelta(myIsDelta);
anAtt->SetID(myID);
}
}
}
//=================================================================================================
Standard_OStream& TDataStd_ByteArray::Dump(Standard_OStream& anOS) const
{
anOS << "\nByteArray: ";
Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
myID.ToCString(sguid);
anOS << sguid << std::endl;
return anOS;
}
//=================================================================================================
Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification(
const Handle(TDF_Attribute)& OldAttribute) const
{
if (myIsDelta)
return new TDataStd_DeltaOnModificationOfByteArray(
Handle(TDataStd_ByteArray)::DownCast(OldAttribute));
else
return new TDF_DefaultDeltaOnModification(OldAttribute);
}
//=================================================================================================
void TDataStd_ByteArray::DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth) const
{
OCCT_DUMP_TRANSIENT_CLASS_BEGIN(theOStream)
OCCT_DUMP_BASE_CLASS(theOStream, theDepth, TDF_Attribute)
if (!myValue.IsNull())
{
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myValue->Lower())
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myValue->Upper())
for (TColStd_Array1OfByte::Iterator aValueIt(myValue->Array1()); aValueIt.More();
aValueIt.Next())
{
const Standard_Byte& aValue = aValueIt.Value();
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, aValue)
}
}
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myIsDelta)
}