1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00
libpsyc/include/psyc/variable.h

124 lines
3 KiB
C
Raw Normal View History

2013-07-16 14:53:51 +00:00
/*
This file is part of libpsyc.
Copyright (C) 2011,2012 Carlo v. Loesch, Gabor X Toth, Mathias L. Baumann,
and other contributing authors.
libpsyc is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version. As a special exception, libpsyc is distributed with additional
permissions to link libpsyc libraries with non-AGPL works.
libpsyc 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 Affero General Public License for more
details.
You should have received a copy of the GNU Affero General Public License and
the linking exception along with libpsyc in a COPYING file.
*/
2011-10-31 19:04:16 +00:00
/**
* @file psyc/variable.h
*/
2011-11-28 13:00:41 +00:00
#ifndef PSYC_VARIABLE_H
#define PSYC_VARIABLE_H
#include "match.h"
2011-11-28 13:00:41 +00:00
#include "packet.h"
2011-10-31 19:04:16 +00:00
/// Routing variables in alphabetical order.
extern const PsycMapInt psyc_rvars[];
2011-10-31 19:04:16 +00:00
1984-04-04 00:44:05 +00:00
/// Variable types in alphabetical order.
extern const PsycMapInt psyc_var_types[];
2011-10-31 19:04:16 +00:00
2011-11-30 12:51:50 +00:00
/// Method names in alphabetical order.
extern const PsycMapInt psyc_methods[];
2011-11-30 12:51:50 +00:00
extern const size_t psyc_rvars_num;
2011-10-31 19:04:16 +00:00
extern const size_t psyc_var_types_num;
2011-11-30 12:51:50 +00:00
extern const size_t psyc_methods_num;
2011-10-31 19:04:16 +00:00
typedef enum {
PSYC_RVAR_UNKNOWN,
PSYC_RVAR_AMOUNT_FRAGMENTS,
PSYC_RVAR_CONTEXT,
PSYC_RVAR_COUNTER,
PSYC_RVAR_FRAGMENT,
PSYC_RVAR_SOURCE,
PSYC_RVAR_SOURCE_RELAY,
PSYC_RVAR_TAG,
PSYC_RVAR_TAG_RELAY,
PSYC_RVAR_TARGET,
PSYC_RVAR_TARGET_RELAY,
PSYC_RVARS_NUM,
} PsycRoutingVar;
/**
* Variable types.
*
* This enum lists PSYC variable types that
* this library is capable of checking for
* validity. Other variable types are treated
* as opaque data.
*/
typedef enum {
PSYC_TYPE_UNKNOWN,
PSYC_TYPE_AMOUNT,
PSYC_TYPE_COLOR,
PSYC_TYPE_COUNTER,
PSYC_TYPE_DATE,
PSYC_TYPE_DEGREE,
PSYC_TYPE_DICT,
PSYC_TYPE_ENTITY,
PSYC_TYPE_FLAG,
PSYC_TYPE_LANGUAGE,
PSYC_TYPE_LIST,
PSYC_TYPE_NICK,
PSYC_TYPE_PAGE,
PSYC_TYPE_STRUCT,
PSYC_TYPE_TIME,
PSYC_TYPE_UNIFORM,
} PsycType;
2011-10-31 19:04:16 +00:00
/**
* Look up routing variable.
2011-10-31 19:04:16 +00:00
*/
inline PsycRoutingVar
psyc_var_routing (const char *name, size_t len)
2012-01-09 10:52:09 +00:00
{
return (PsycRoutingVar)
2012-02-21 02:00:52 +00:00
psyc_map_lookup_int((PsycMapInt*)psyc_rvars, psyc_rvars_num, name, len,
PSYC_NO);
2012-01-09 10:52:09 +00:00
}
2011-10-31 19:04:16 +00:00
/**
* Get the type of variable name.
*/
inline PsycType
2012-01-09 10:52:09 +00:00
psyc_var_type (const char *name, size_t len)
{
return (PsycType)
2012-02-21 02:00:52 +00:00
psyc_map_lookup_int((PsycMapInt*)psyc_var_types, psyc_var_types_num,
name, len, PSYC_YES);
2012-01-09 10:52:09 +00:00
}
2011-10-31 19:04:16 +00:00
/**
* Is this a list variable name?
*/
inline PsycBool
2011-11-11 21:18:24 +00:00
psyc_var_is_list (const char *name, size_t len)
2011-10-31 19:04:16 +00:00
{
2011-11-11 21:18:24 +00:00
return len < 5 || memcmp(name, "_list", 5) != 0 || (len > 5 && name[5] != '_')
? PSYC_FALSE : PSYC_TRUE;
2011-10-31 19:04:16 +00:00
}
2011-11-28 13:00:41 +00:00
PsycMethod
2011-11-30 12:51:50 +00:00
psyc_method (char *method, size_t methodlen, PsycMethod *family, unsigned int *flag);
2011-11-28 13:00:41 +00:00
2011-10-31 19:04:16 +00:00
#endif