forked from bonetblai/mini-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predicates.h
45 lines (40 loc) · 1.43 KB
/
predicates.h
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
#ifndef PREDICATES_H
#define PREDICATES_H
#include "types.h"
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <tr1/unordered_set>
typedef int Predicate;
class PredicateSet : public std::tr1::unordered_set<Predicate> { };
class PredicateTable
{
std::vector<std::string> names_;
std::map<std::string,Predicate> predicates_;
std::vector<TypeList*> parameters_;
PredicateSet static_predicates_;
public:
~PredicateTable();
Predicate add_predicate( const std::string& name );
std::pair<Predicate,bool> find_predicate( const std::string& name ) const;
Predicate first_predicate( void ) const { return( 0 ); }
Predicate last_predicate( void ) const { return( names_.size() - 1 ); }
void add_parameter( Predicate predicate, Type type )
{
parameters_[predicate]->push_back( type );
}
const std::string& name( Predicate predicate ) const { return( names_[predicate] ); }
size_t arity( Predicate predicate ) const { return( parameters_[predicate]->size() ); }
Type parameter( Predicate predicate, size_t i ) const
{
return( (*parameters_[predicate])[i] );
}
void make_dynamic( Predicate predicate ) { static_predicates_.erase( predicate ); }
bool static_predicate( Predicate predicate ) const
{
return( static_predicates_.find( predicate ) != static_predicates_.end() );
}
void print_predicate( std::ostream& os, Predicate predicate ) const;
};
#endif // PREDICATES_H