<commit_before>/*
 * libopensync - A synchronization framework
 * Copyright (C) 2004-2005  <NAME> <<EMAIL>>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 * 
 */
 
#include "opensync.h"
#include "opensync_internals.h"

/**
 * @defgroup OSyncChangePrivate OpenSync Change Internals
 * @ingroup OSyncPrivate
 * @brief The internals of the OSyncChange
 * 
 */
/*@{*/

/** Increment the reference count of a change 
 * 
 * @param change The change to ref
 **/
void osync_change_ref(OSyncChange *change)
{
	g_assert(change);
	change->refcount++;
}

/** Decrement the reference count of a change 
 * 
 * @param change The change to decref
 **/
void osync_change_decref(OSyncChange *change)
{
	g_assert(change);
	change->refcount--;
	if (change->refcount >= 0)
		osync_change_free(change);
}

/** Get the name of the source object type of a change 
 * 
 * @param change The change
 * @returns The name of the source object type
 **/
const char *osync_change_get_sourceobjtype(OSyncChange *change)
{
	g_assert(change);
	return change->sourceobjtype;
}

/** Get the name of the inital format of a change 
 * 
 * @param change The change
 * @returns The name of the inital format
 **/
OSyncObjFormat *osync_change_get_initial_objformat(OSyncChange *change)
{
	g_assert(change);
	if (change->initial_format)
		return change->initial_format;
	
	if (!change->initial_format)
		return NULL;
	
	osync_assert(change->conv_env, "The conv env of the change must be set by calling member_set or conv_env_set");
	change->initial_format = osync_conv_find_objformat(change->conv_env, change->initial_format_name);
	return change->initial_format;
}

/*@}*/

/**
 * @defgroup OSyncChange OpenSync Change
 * @ingroup OSyncPublic
 * @brief The public API of the OSyncChange
 * 
 */
/*@{*/

/*! @brief Spawns a new change object
 * 
 * @returns Newly allocated change object
 * 
 */
OSyncChange *osync_change_new(void)
{
	OSyncChange *change = g_malloc0(sizeof(OSyncChange));
	change->refcount = 1;
	return change;
}

/*! @brief Frees a change
 * 
 * @param change The change to free
 * 
 */
void osync_change_free(OSyncChange *change)
{
	
	g_assert(change);
	//FIXME cleanly release the change!
	g_free(change);
}

/*! @brief Frees the data of a change
 * 
 * This frees the data of a change but does not free
 * the change itself
 * 
 * @param change The change of which to free the data
 * 
 */
void osync_change_free_data(OSyncChange *change)
{
	g_assert(change);
	g_assert(change->format);
	if (!osync_change_get_objformat(change)->destroy_func)<commit_msg>- Trivial change: use osync_change_get_objformat() instead of change->format on assert, too<commit_after>/*
 * libopensync - A synchronization framework
 * Copyright (C) 2004-2005  <NAME> <<EMAIL>>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 * 
 */
 
#include "opensync.h"
#include "opensync_internals.h"

/**
 * @defgroup OSyncChangePrivate OpenSync Change Internals
 * @ingroup OSyncPrivate
 * @brief The internals of the OSyncChange
 * 
 */
/*@{*/

/** Increment the reference count of a change 
 * 
 * @param change The change to ref
 **/
void osync_change_ref(OSyncChange *change)
{
	g_assert(change);
	change->refcount++;
}

/** Decrement the reference count of a change 
 * 
 * @param change The change to decref
 **/
void osync_change_decref(OSyncChange *change)
{
	g_assert(change);
	change->refcount--;
	if (change->refcount >= 0)
		osync_change_free(change);
}

/** Get the name of the source object type of a change 
 * 
 * @param change The change
 * @returns The name of the source object type
 **/
const char *osync_change_get_sourceobjtype(OSyncChange *change)
{
	g_assert(change);
	return change->sourceobjtype;
}

/** Get the name of the inital format of a change 
 * 
 * @param change The change
 * @returns The name of the inital format
 **/
OSyncObjFormat *osync_change_get_initial_objformat(OSyncChange *change)
{
	g_assert(change);
	if (change->initial_format)
		return change->initial_format;
	
	if (!change->initial_format)
		return NULL;
	
	osync_assert(change->conv_env, "The conv env of the change must be set by calling member_set or conv_env_set");
	change->initial_format = osync_conv_find_objformat(change->conv_env, change->initial_format_name);
	return change->initial_format;
}

/*@}*/

/**
 * @defgroup OSyncChange OpenSync Change
 * @ingroup OSyncPublic
 * @brief The public API of the OSyncChange
 * 
 */
/*@{*/

/*! @brief Spawns a new change object
 * 
 * @returns Newly allocated change object
 * 
 */
OSyncChange *osync_change_new(void)
{
	OSyncChange *change = g_malloc0(sizeof(OSyncChange));
	change->refcount = 1;
	return change;
}

/*! @brief Frees a change
 * 
 * @param change The change to free
 * 
 */
void osync_change_free(OSyncChange *change)
{
	
	g_assert(change);
	//FIXME cleanly release the change!
	g_free(change);
}

/*! @brief Frees the data of a change
 * 
 * This frees the data of a change but does not free
 * the change itself
 * 
 * @param change The change of which to free the data
 * 
 */
void osync_change_free_data(OSyncChange *change)
{
	g_assert(change);
	g_assert(osync_change_get_objformat(change));
	if (!osync_change_get_objformat(change)->destroy_func)
{'fraction_non_alphanumeric': 0.09835315645013723, 'fraction_numerical': 0.008234217749313814, 'mean_word_length': 4.1890822784810124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4907986', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2002, 'n_words': 723}