<commit_before>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


#include "mitkPropertyList.h"
#include <mitkXMLWriter.h>
#include <mitkXMLReader.h>

const std::string mitk::PropertyList::XML_NODE_NAME = "propertyList";
const std::string mitk::PropertyList::XML_ALREADY_SEEN = "PROPERTY_REFERENCE";

// static maps for XML reading/writing
mitk::UIDGenerator mitk::PropertyList::m_UIDGenerator;
std::map<std::string, mitk::BaseProperty*> mitk::PropertyList::m_AlreadyReadFromXML;
std::map<mitk::BaseProperty*, std::string> mitk::PropertyList::m_AlreadyWrittenToXML;

//##ModelId=3D6A0E9E0029
mitk::BaseProperty::Pointer mitk::PropertyList::GetProperty(const char *propertyKey) const
{
    PropertyMap::const_iterator it;
    
    it=m_Properties.find( propertyKey );
    if(it!=m_Properties.end() &&  it->second.second )
      return it->second.first;
    else 
        return NULL;
}

//##ModelId=3D78B966005F
void mitk::PropertyList::SetProperty(const char* propertyKey, BaseProperty* property)
{
  if (!property) return;
  //make sure that BaseProperty*, which may have just been created and never been 
  //assigned to a SmartPointer, is registered/unregistered properly. If we do not
  //do that, it will a) not deleted in case it is identical to the old one or
  //b) possibly deleted when temporarily added to a smartpointer somewhere below.
  BaseProperty::Pointer tmpSmartPointerToProperty = property;

  PropertyMap::iterator it( m_Properties.find( propertyKey ) );
  
  // Is a property with key @a propertyKey contained in the list?
  if( it != m_Properties.end() )
  {
    // yes
    //is the property contained in the list identical to the new one?
    if( it->second.first == property) 
    {
      // yes? do nothing and return.
      return;
    }

    // compatible? then use operator= to assign value
    if (it->second.first->Assignable( *property ))
    {
      *(static_cast<BaseProperty*>(it->second.first.GetPointer())) = *property;
      this->Modified();
      return;
    }
    
    if ( typeid( *(it->second.first.GetPointer()) ) != typeid( *property ) )
    {<commit_msg>COMP: Removed this->Modified(); the properties are marked as modified when their value changes, which is enough (cf. bug #522)<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Module:    $RCSfile$
Language:  C++
Date:      $Date$
Version:   $Revision$

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


#include "mitkPropertyList.h"
#include <mitkXMLWriter.h>
#include <mitkXMLReader.h>

const std::string mitk::PropertyList::XML_NODE_NAME = "propertyList";
const std::string mitk::PropertyList::XML_ALREADY_SEEN = "PROPERTY_REFERENCE";

// static maps for XML reading/writing
mitk::UIDGenerator mitk::PropertyList::m_UIDGenerator;
std::map<std::string, mitk::BaseProperty*> mitk::PropertyList::m_AlreadyReadFromXML;
std::map<mitk::BaseProperty*, std::string> mitk::PropertyList::m_AlreadyWrittenToXML;

//##ModelId=3D6A0E9E0029
mitk::BaseProperty::Pointer mitk::PropertyList::GetProperty(const char *propertyKey) const
{
    PropertyMap::const_iterator it;
    
    it=m_Properties.find( propertyKey );
    if(it!=m_Properties.end() &&  it->second.second )
      return it->second.first;
    else 
        return NULL;
}

//##ModelId=3D78B966005F
void mitk::PropertyList::SetProperty(const char* propertyKey, BaseProperty* property)
{
  if (!property) return;
  //make sure that BaseProperty*, which may have just been created and never been 
  //assigned to a SmartPointer, is registered/unregistered properly. If we do not
  //do that, it will a) not deleted in case it is identical to the old one or
  //b) possibly deleted when temporarily added to a smartpointer somewhere below.
  BaseProperty::Pointer tmpSmartPointerToProperty = property;

  PropertyMap::iterator it( m_Properties.find( propertyKey ) );
  
  // Is a property with key @a propertyKey contained in the list?
  if( it != m_Properties.end() )
  {
    // yes
    //is the property contained in the list identical to the new one?
    if( it->second.first == property) 
    {
      // yes? do nothing and return.
      return;
    }

    // compatible? then use operator= to assign value
    if (it->second.first->Assignable( *property ))
    {
      *(static_cast<BaseProperty*>(it->second.first.GetPointer())) = *property;
      return;
    }
    
    if ( typeid( *(it->second.first.GetPointer()) ) != typeid( *property ) )
    {
{'fraction_non_alphanumeric': 0.15908679108534154, 'fraction_numerical': 0.006704113063960863, 'mean_word_length': 4.4816285998013905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '962473', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1535, 'n_words': 479}