edits
[cdsspec-compiler.git] / notes / definition.cc
index bcc01e7b167702a6b062fcaa5d72770643b48b0c..fda4ebac8765b298d3726e669281bf32882f8145 100644 (file)
@@ -32,7 +32,7 @@ typedef set<int> IntSet;
 
 /********** More general specification-related types and operations **********/
 
-#define NewSet new set<Method>
+#define NewMethodSet new set<Method>
 
 #define CAT(a, b) CAT_HELPER(a, b) /* Concatenate two symbols for macros! */
 #define CAT_HELPER(a, b) a ## b
@@ -74,7 +74,7 @@ typedef set<int> IntSet;
 /*
 #define Subset(s, subset, condition) \
        MethodSet original = s; \
-       MethodSet subset = NewSet; \
+       MethodSet subset = NewMethodSet; \
        ForEach (_M, original) { \
                if ((condition)) \
                        subset->insert(_M); \
@@ -127,6 +127,21 @@ inline set<T>* Subset(set<T> *original, std::function<bool(T)> condition) {
        return res;
 }
 
+/**
+       A general set operation that takes a condition and returns if there exists
+       any item for which the boolean guard holds.
+*/
+template <class T>
+inline bool HasItem(set<T> *original, std::function<bool(T)> condition) {
+       ForEach (_M, original) {
+               if (condition(_M))
+                       return true;
+       }
+       return false;
+}
+
+
+
 /**
        A general sublist operation that takes a condition and returns all the item
        for which the boolean guard holds in the same order as in the old list.
@@ -213,7 +228,7 @@ inline MethodSet MakeSet(int count, ...) {
        MethodSet res;
 
        va_start (ap, count);
-       res = NewSet;
+       res = NewMethodSet;
        for (int i = 0; i < count; i++) {
                Method item = va_arg (ap, Method);
                res->insert(item);
@@ -281,7 +296,7 @@ int main() {
        is2->insert(5);
 
 
-       MethodSet ms = NewSet;
+       MethodSet ms = NewMethodSet;
        Method m = new MethodCall;
        m->interfaceName = "Store";
        StateStruct *ss = new StateStruct;
@@ -313,9 +328,10 @@ int main() {
        ms->insert(m);
 
        MakeSet(int, ms, newis, STATE(x));
-       cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl;
+       //cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl;
+       cout << "HasItem=" << HasItem(ms, Guard(STATE(x) == 2)) << endl;
        ForEach (i, newis) {
-               cout << "elem: " << i << endl;
+               //cout << "elem: " << i << endl;
        }