fold group specific query functions into the more generic ID query functions
This commit is contained in:
@ -15,9 +15,6 @@ This section documents the following functions:
|
|||||||
- :cpp:func:`lammps_has_style`
|
- :cpp:func:`lammps_has_style`
|
||||||
- :cpp:func:`lammps_style_count`
|
- :cpp:func:`lammps_style_count`
|
||||||
- :cpp:func:`lammps_style_name`
|
- :cpp:func:`lammps_style_name`
|
||||||
- :cpp:func:`lammps_has_group`
|
|
||||||
- :cpp:func:`lammps_group_count`
|
|
||||||
- :cpp:func:`lammps_group_name`
|
|
||||||
- :cpp:func:`lammps_has_id`
|
- :cpp:func:`lammps_has_id`
|
||||||
- :cpp:func:`lammps_id_count`
|
- :cpp:func:`lammps_id_count`
|
||||||
- :cpp:func:`lammps_id_name`
|
- :cpp:func:`lammps_id_name`
|
||||||
@ -132,21 +129,6 @@ a safer approach.
|
|||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
.. doxygenfunction:: lammps_has_group
|
|
||||||
:project: progguide
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
.. doxygenfunction:: lammps_group_count
|
|
||||||
:project: progguide
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
.. doxygenfunction:: lammps_group_name
|
|
||||||
:project: progguide
|
|
||||||
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
.. doxygenfunction:: lammps_has_id
|
.. doxygenfunction:: lammps_has_id
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
|||||||
@ -4049,86 +4049,12 @@ int lammps_style_name(void *handle, const char *category, int idx,
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
/** Check if a group with a given name has been defined
|
|
||||||
*
|
|
||||||
\verbatim embed:rst
|
|
||||||
This function checks if a group with the provided *name* is defined
|
|
||||||
in the current LAMMPS instance.
|
|
||||||
\endverbatim
|
|
||||||
*
|
|
||||||
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
|
|
||||||
* \param name name of the style
|
|
||||||
* \return 1 if defined, 0 if not.
|
|
||||||
*/
|
|
||||||
int lammps_has_group(void *handle, const char *name)
|
|
||||||
{
|
|
||||||
LAMMPS *lmp = (LAMMPS *)handle;
|
|
||||||
|
|
||||||
int ngroup = lmp->group->ngroup;
|
|
||||||
char **groups = lmp->group->names;
|
|
||||||
|
|
||||||
for (int i=0; i < ngroup; ++i)
|
|
||||||
if (strcmp(groups[i],name) == 0) return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/** Count the number of currently defined groups
|
|
||||||
*
|
|
||||||
* This function counts how many groups are defined in the
|
|
||||||
* current LAMMPS instance.
|
|
||||||
*
|
|
||||||
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
|
|
||||||
* \return number of styles in category
|
|
||||||
*/
|
|
||||||
int lammps_group_count(void *handle)
|
|
||||||
{
|
|
||||||
LAMMPS *lmp = (LAMMPS *)handle;
|
|
||||||
|
|
||||||
return lmp->group->ngroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/** Look up the name of a group by index in the list of groups.
|
|
||||||
*
|
|
||||||
* This function copies the name of the group with the index *idx* into
|
|
||||||
* the provided C-style string buffer. The length of the buffer must be
|
|
||||||
* provided as *buf_size* argument. If the name of the group exceeds the
|
|
||||||
* length of the buffer, it will be truncated accordingly. If the index
|
|
||||||
* is out of range, the function returns 0 and *buffer* is set to an empty
|
|
||||||
* string, otherwise 1 is returned.
|
|
||||||
*
|
|
||||||
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
|
|
||||||
* \param idx index of the group in the list of groups (0 <= idx < group count)
|
|
||||||
* \param buffer string buffer to copy the name of the style to
|
|
||||||
* \param buf_size size of the provided string buffer
|
|
||||||
* \return 1 if successful, otherwise 0
|
|
||||||
*/
|
|
||||||
int lammps_group_name(void *handle, int idx, char *buffer, int buf_size) {
|
|
||||||
LAMMPS *lmp = (LAMMPS *)handle;
|
|
||||||
|
|
||||||
int ngroup = lmp->group->ngroup;
|
|
||||||
char **groups = lmp->group->names;
|
|
||||||
if ((idx >=0) && (idx < ngroup)) {
|
|
||||||
strncpy(buffer, groups[idx], buf_size);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer[0] = '\0';
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/** Check if a specific ID exists in the current LAMMPS instance
|
/** Check if a specific ID exists in the current LAMMPS instance
|
||||||
*
|
*
|
||||||
\verbatim embed:rst
|
\verbatim embed:rst
|
||||||
This function checks if the current LAMMPS instance a *category* ID of
|
This function checks if the current LAMMPS instance a *category* ID of
|
||||||
the given *name* exists. Valid categories are: *compute*\ , *dump*\ ,
|
the given *name* exists. Valid categories are: *compute*\ , *dump*\ ,
|
||||||
*fix*\ , *molecule*\ , *region*\ , and *variable*\ .
|
*fix*\ , *group*\ , *molecule*\ , *region*\ , and *variable*\ .
|
||||||
\endverbatim
|
\endverbatim
|
||||||
*
|
*
|
||||||
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
|
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
|
||||||
@ -4157,6 +4083,12 @@ int lammps_has_id(void *handle, const char *category, const char *name) {
|
|||||||
for (int i=0; i < nfix; ++i) {
|
for (int i=0; i < nfix; ++i) {
|
||||||
if (strcmp(name,fix[i]->id) == 0) return 1;
|
if (strcmp(name,fix[i]->id) == 0) return 1;
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(category,"group") == 0) {
|
||||||
|
int ngroup = lmp->group->ngroup;
|
||||||
|
char **groups = lmp->group->names;
|
||||||
|
for (int i=0; i < ngroup; ++i) {
|
||||||
|
if (strcmp(groups[i],name) == 0) return 1;
|
||||||
|
}
|
||||||
} else if (strcmp(category,"molecule") == 0) {
|
} else if (strcmp(category,"molecule") == 0) {
|
||||||
int nmolecule = lmp->atom->nmolecule;
|
int nmolecule = lmp->atom->nmolecule;
|
||||||
Molecule **molecule = lmp->atom->molecules;
|
Molecule **molecule = lmp->atom->molecules;
|
||||||
@ -4202,6 +4134,8 @@ int lammps_id_count(void *handle, const char *category) {
|
|||||||
return lmp->output->ndump;
|
return lmp->output->ndump;
|
||||||
} else if (strcmp(category,"fix") == 0) {
|
} else if (strcmp(category,"fix") == 0) {
|
||||||
return lmp->modify->nfix;
|
return lmp->modify->nfix;
|
||||||
|
} else if (strcmp(category,"group") == 0) {
|
||||||
|
return lmp->group->ngroup;
|
||||||
} else if (strcmp(category,"molecule") == 0) {
|
} else if (strcmp(category,"molecule") == 0) {
|
||||||
return lmp->atom->nmolecule;
|
return lmp->atom->nmolecule;
|
||||||
} else if (strcmp(category,"region") == 0) {
|
} else if (strcmp(category,"region") == 0) {
|
||||||
@ -4249,6 +4183,11 @@ int lammps_id_name(void *handle, const char *category, int idx,
|
|||||||
strncpy(buffer, lmp->modify->fix[idx]->id, buf_size);
|
strncpy(buffer, lmp->modify->fix[idx]->id, buf_size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
} else if (strcmp(category,"group") == 0) {
|
||||||
|
if ((idx >=0) && (idx < lmp->group->ngroup)) {
|
||||||
|
strncpy(buffer, lmp->group->names[idx], buf_size);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
} else if (strcmp(category,"molecule") == 0) {
|
} else if (strcmp(category,"molecule") == 0) {
|
||||||
if ((idx >=0) && (idx < lmp->atom->nmolecule)) {
|
if ((idx >=0) && (idx < lmp->atom->nmolecule)) {
|
||||||
strncpy(buffer, lmp->atom->molecules[idx]->id, buf_size);
|
strncpy(buffer, lmp->atom->molecules[idx]->id, buf_size);
|
||||||
|
|||||||
@ -183,10 +183,6 @@ int lammps_has_style(void *, const char *, const char *);
|
|||||||
int lammps_style_count(void *, const char *);
|
int lammps_style_count(void *, const char *);
|
||||||
int lammps_style_name(void *, const char *, int, char *, int);
|
int lammps_style_name(void *, const char *, int, char *, int);
|
||||||
|
|
||||||
int lammps_has_group(void *, const char *);
|
|
||||||
int lammps_group_count(void *);
|
|
||||||
int lammps_group_name(void *, int, char *, int);
|
|
||||||
|
|
||||||
int lammps_has_id(void *, const char *, const char *);
|
int lammps_has_id(void *, const char *, const char *);
|
||||||
int lammps_id_count(void *, const char *);
|
int lammps_id_count(void *, const char *);
|
||||||
int lammps_id_name(void *, const char *, int, char *, int);
|
int lammps_id_name(void *, const char *, int, char *, int);
|
||||||
|
|||||||
@ -357,12 +357,12 @@ char *group_generator(const char *text, int state)
|
|||||||
static int idx, num, len;
|
static int idx, num, len;
|
||||||
if (!state) {
|
if (!state) {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
num = lammps_group_count(lmp);
|
num = lammps_id_count(lmp, "group");
|
||||||
len = strlen(text);
|
len = strlen(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (idx < num) {
|
while (idx < num) {
|
||||||
lammps_group_name(lmp, idx, buf, buflen);
|
lammps_id_name(lmp, "group", idx, buf, buflen);
|
||||||
++idx;
|
++idx;
|
||||||
if ((len == 0) || (strncmp(text, buf, len) == 0)) return dupstring(buf);
|
if ((len == 0) || (strncmp(text, buf, len) == 0)) return dupstring(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user