summaryrefslogtreecommitdiff
path: root/sim/src/pattern.h
blob: d2eeb6e7b6abd828769499e90412b287ac3fb905 (plain)
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
55
56
57
58
59
60
61
// Copyright 2007 Nanorex, Inc.  See LICENSE file for details. 
#ifndef PATTERN_H_INCLUDED
#define PATTERN_H_INCLUDED

#define RCSID_PATTERN_H  "$Id$"

struct compiledPatternAtom
{
  struct atomType *type;
  int idInPattern;
};

struct compiledPatternTraversal
{
  struct compiledPatternAtom *a;
  struct compiledPatternAtom *b;
  char bondOrder[4];
};

struct patternMatch 
{
  struct part *p;
  char *patternName;
  int numberOfAtoms;
  int *atomIndices;
  int *introducedAtTraversal;
  int sequenceNumber;
};

struct compiledPattern
{
  char *name;
  void (*matchFunction)(struct patternMatch *match);
  int numberOfAtoms;
  int numberOfTraversals;

  // non-zero if pattern is allowed to match same atoms more than one way
  int allowDuplicates;
  
  struct compiledPatternTraversal **traversals;
};

extern void printMatch(struct patternMatch *match);

extern void traceMatch(struct patternMatch *match);

extern int atomIsType(struct atom *a, struct atomType *type);

extern struct compiledPatternAtom *makePatternAtom(int id, char *type);

extern struct compiledPatternTraversal *makeTraversal2(struct compiledPatternAtom *a, struct compiledPatternAtom *b, char *bondOrders);

extern struct compiledPatternTraversal *makeTraversal(struct compiledPatternAtom *a, struct compiledPatternAtom *b, char bondOrder);

extern struct compiledPattern *makePattern(char *name, void (*matchFunction)(struct patternMatch *match), int numAtoms, int numTraversals, struct compiledPatternTraversal **traversals);

extern void matchPartToAllPatterns(struct part *part);

extern void createPatterns(void);

#endif