#ifndef LIBREV__SYMBOL_H
#define LIBREV__SYMBOL_H

/*
 * Copyright (c) 2003  Petr Baudis.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials
 *     provided with the distribution.
 *   * Neither the name of the author nor the names of the product's
 *     contributors may be used to endorse or promote products
 *     derived from this software without specific prior written
 *     permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifdef __cplusplus
extern "C" {
#endif


#include <librev/librev.h>
#include <librev/objid.h>


/* This header file contains the symbol object. Symbol is an association beween
 * a revision or branch and a string identifier. In CVS context, revision
 * symbol is called 'tag', branch symbol is called 'branch tag'. We abide
 * rather the RCS terminology, though. */

/* Each symbol structure is tied to only one object. So in the CVS environment,
 * you will have one symbol per each tag and inode. In the smarter environments
 * (like PaVS), the symbol objects will probably usually be tied only to the
 * changeset inodes. */


rev_object (symbol,
	/* Public attributes */

	/* Member of symbols-of-the-inode chain. */
	struct rev_list_item symbol; /* rev_inode.symbols */

	/* Identification of the symbol. That is its name. */
	/* {rev_symbol_get_name()},{rev_symbol_set_name()} */
	char *name;

	/* Identification of the associated object - pair of type and pointer.
	 * Usually, you always work with the pair as a whole. */
	/* XXX? Perhaps a separate object? (Could be reused in rcS_revnum.) */
	/* {rev_symbol_get_objid()},{rev_symbol_set_objid()} */
	struct rev_objid *objid;


	/* Backend data : */

	void *data; /* Backend data. */

	struct rev_symbol_dataops {
		/* Release obj->data. */
		void (*done) (struct rev_symbol *obj);
	} *dataops;


	/* User's data (just in case ;) : */

	void *udata; /* User's data. */

	struct rev_symbol_userops {
		/* Release obj->udata. */
		void (*done) (struct rev_symbol *obj);
	} *userops;
);

/* Constructor */

/* This creates the symbol. */
/* Returns the pointer on success, NULL otherwise. */
struct rev_symbol *rev_symbol_init (char *name, struct rev_objid *objid);

/* Attributes */

#include <assert.h>
#include <stdlib.h>
#include <string.h>

/* This returns the name. */
static inline char *
rev_symbol_get_name (struct rev_symbol *obj)
{
	assert (obj);
	return obj->name;
}

/* This sets the name. */
static inline void
rev_symbol_set_name (struct rev_symbol *obj, char *name)
{
	assert (obj);
	if (obj->name) free (obj->name);
	obj->name = name ? strdup (name) : NULL;
}

/* This returns the obj. */
static inline struct rev_objid *
rev_symbol_get_objid (struct rev_symbol *obj)
{
	assert (obj);
	if (obj->objid) rev_objid_tie (obj->objid); /* Should we? --pasky */
	return obj->objid;
}

/* This sets the obj. */
static inline void
rev_symbol_set_objid (struct rev_symbol *obj, struct rev_objid *objid)
{
	assert (obj);
	if (obj->objid) {
		rev_objid_untie (obj->objid);
		free (obj->objid);
	}
	obj->objid = objid;
	if (obj->objid) rev_objid_tie (obj->objid);
}

	
#ifdef __cplusplus
}
#endif

#endif
