File: Lex.h

package info (click to toggle)
pymol 1.8.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,248 kB
  • ctags: 24,095
  • sloc: cpp: 474,635; python: 75,034; ansic: 22,888; sh: 236; makefile: 78; csh: 21
file content (54 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * This file contains source code for the PyMOL computer program
 * Copyright (c) Schrodinger, LLC.
 *
 * Handling of "interned" strings in PyMOLGlobals::Lexicon
 */

#pragma once

#include "PyMOLGlobals.h"
#include "OVLexicon.h"

#define LexDec(G, i) OVLexicon_DecRef(G->Lexicon, i)
#define LexInc(G, i) OVLexicon_IncRef(G->Lexicon, i)

/*
 * Get the pointer to the internal string storage for reference `i`.
 */
inline const char * LexStr(PyMOLGlobals * G, const lexidx_t & i) {
  return (i) ? OVLexicon_FetchCString(G->Lexicon, i) : "";
}

/*
 * Lookup or insert new string `s` into the global lexicon and return
 * it's numerical reference. Will always return 0 for the empty string.
 */
inline lexidx_t LexIdx(PyMOLGlobals * G, const char * s) {
  return (s && s[0]) ? OVLexicon_GetFromCString(G->Lexicon, s).word : 0;
}

/*
 * Assignment (i = j) with reference count update for old and new value.
 */
inline void LexAssign(PyMOLGlobals * G, lexidx_t& i, const lexidx_t& j) {
  if (i != j) {
    LexDec(G, i);
    i = j;
    LexInc(G, i);
  }
}

inline void LexAssign(PyMOLGlobals * G, lexidx_t& i, const char * s) {
  LexDec(G, i);
  i = LexIdx(G, s);
}

/*
 * Lookup string `s` without inserting or incrementing the ref count. If
 * `s` is not in the lexicon, return -1.
 */
inline lexidx_t LexBorrow(PyMOLGlobals * G, const char * s) {
  auto result = OVLexicon_BorrowFromCString(G->Lexicon, s);
  return (result.status == OVstatus_SUCCESS) ? result.word : -1;
}