-
Botond Baranyi authored
Change-Id: Ic61f177b598933eb0227e34561410521ce45a29b Signed-off-by:
Botond Baranyi <botond.baranyi@ericsson.com>
Botond Baranyi authoredChange-Id: Ic61f177b598933eb0227e34561410521ce45a29b Signed-off-by:
Botond Baranyi <botond.baranyi@ericsson.com>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Objid.cc 32.27 KiB
/******************************************************************************
* Copyright (c) 2000-2016 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Balasko, Jeno
* Baranyi, Botond
* Beres, Szabolcs
* Delic, Adam
* Forstner, Matyas
* Kovacs, Ferenc
* Raduly, Csaba
* Szabados, Kristof
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Szalai, Gabor
* Tatarka, Gabor
*
******************************************************************************/
#include "Objid.hh"
#include "../common/dbgnew.hh"
#include <errno.h>
#include <limits.h>
#include "../common/static_check.h"
#include "Integer.hh"
static const size_t MIN_COMPONENTS = 2;
struct OBJID::objid_struct {
unsigned int ref_count;
int n_components; ///< number of elements in \a components_ptr (min. 2)
int overflow_idx; ///< index of the first overflow, or -1
objid_element components_ptr[MIN_COMPONENTS];
};
#define OBJID_FMT "%u"
//#define OBJID_FMT "%lu"
void OBJID::init_struct(int n_components)
{
if (n_components < 0) {
val_ptr = NULL;
TTCN_error("Initializing an objid value with a negative number of "
"components.");
}
// TODO check n_components >= 2
val_ptr = (objid_struct*)Malloc(sizeof(objid_struct)
+ (n_components - MIN_COMPONENTS) * sizeof(objid_element));
val_ptr->ref_count = 1;
val_ptr->n_components = n_components;
val_ptr->overflow_idx = -1;
}
void OBJID::copy_value()
{
if (val_ptr != NULL && val_ptr->ref_count > 1) {
objid_struct *old_ptr = val_ptr;
old_ptr->ref_count--;
init_struct(old_ptr->n_components); // val_ptr reallocated
memcpy(val_ptr->components_ptr, old_ptr->components_ptr,
old_ptr->n_components * sizeof(objid_element));
val_ptr->overflow_idx = old_ptr->overflow_idx;
}
}
void OBJID::clean_up()