Esempio n. 1
0
void expect_matrix_eq(const Eigen::Matrix<T1,Eigen::Dynamic,Eigen::Dynamic>& a,
                      const Eigen::Matrix<T2,Eigen::Dynamic,Eigen::Dynamic>& b) {
  EXPECT_EQ(a.rows(), b.rows());
  EXPECT_EQ(a.cols(), b.cols());
  for (int i = 0; i < a.rows(); ++i)
    for (int j = 0; j < a.cols(); ++j)
      EXPECT_FLOAT_EQ(value_of(a(i,j)), value_of(b(i,j)));
}
Esempio n. 2
0
void
I18nModeInit()
{
    char *i18nuser = value_of(VarUser);
    FILE *i18nspool;

    if (i18n_initialize() != 0)
	return;

    if (!i18nuser)
	i18nuser = zmMainName();

    real_spoolfile =
	ftrack_CreateStat(spoolfile, NULL, i18n_mirror_spool, NULL);
    if (!real_spoolfile)
	error(SysErrFatal,
	    catgets( catalog, CAT_SHELL, 819, "Cannot create monitor for mailbox." ));

    i18nspool = open_tempfile(i18nuser, &spoolfile);
    if (!i18nspool)
	error(SysErrFatal,
	    catgets( catalog, CAT_SHELL, 820, "Cannot create copy of spoolfile for translation." ));
    else
	(void) fclose(i18nspool);

    fake_spoolfile = ftrack_Create(spoolfile, NULL, NULL);
    if (!fake_spoolfile) {
	error(SysErrFatal,
	    catgets( catalog, CAT_SHELL, 821, "Cannot create monitor for mailbox update." ));
    }
    ftrack_Init(fake_spoolfile, NULL, i18n_update_spool,
		vaptr((char *) fake_spoolfile, (char *) real_spoolfile, NULL));

    ftrack_Add(global_ftlist, real_spoolfile);
}
Esempio n. 3
0
/*
 * stm is top of template. Create a new parse-tree and copy to it.
 */
static int
traverse(struct xml_node *st, struct xml_node *xt, struct xml_node *rtop)
{
    struct xml_node *rt;
    int i;

    if (st->xn_namespace && strcmp(st->xn_namespace, "xsl") == 0){ 
	/* do intelligent stuff */
	if (strcmp(st->xn_name, "value-of")==0)
	    value_of(st, xt, rtop);
	else
	if (strcmp(st->xn_name, "for-each")==0)
	    for_each(st, xt, rtop);
	else
	if (strcmp(st->xn_name, "if")==0)
	    ifelement(st, xt, rtop);
	else
	if (strcmp(st->xn_name, "choose")==0)
	    choose(st, xt, rtop);
    }
    else{ /* just copy */
	if ((rt = xml_new(st->xn_name, rtop)) == NULL)
	    return -1;
	xml_cp1(st, rt);
	for (i=0; i<st->xn_nrchildren; i++)
	    if (traverse(st->xn_children[i], xt, rt) < 0)
		return -1;
    }
    return 0;
}
Esempio n. 4
0
static int mk_ins_attrs(NODE *list, ATTR_VAL ins_attrs[])
{
  int i, type, len;
  NODE *attr;
  
  // add the attributes to the list
  for(i = 0; list != NULL && i < MAXATTRS; ++i, list = list->u.LIST.next) {
    attr = list->u.LIST.self;
    
    // make sure string attributes aren't too long
    type = type_of(attr->u.ATTRVAL.value);
    len = length_of(attr->u.ATTRVAL.value);
    if (type == STRING && len > MAXSTRINGLEN)
      return E_STRINGTOOLONG;
    
    ins_attrs[i].attrName = attr->u.ATTRVAL.attrname;
    ins_attrs[i].valType = type;
    ins_attrs[i].valLength = len;
    ins_attrs[i].value = value_of(attr->u.ATTRVAL.value);
  }
  
  // if list is too long then error
  if (i == MAXATTRS)
    return E_TOOMANYATTRS;
  
  return i;
}
Esempio n. 5
0
 inline std::vector<typename child_type<T>::type>
 value_of(const std::vector<T>& x) {
   size_t size = x.size();
   std::vector<typename child_type<T>::type> result(size);
   for (size_t i=0; i < size; i++)
     result[i] = value_of(x[i]);
   return result;
 }
Esempio n. 6
0
/*
 * Check, if the value of a node cannot represent a NULL pointer.
 *
 * - Sels are skipped
 * - A SymConst(entity) is NEVER a NULL pointer
 * - Confirms are evaluated
 */
int value_not_null(const ir_node *n, const ir_node **confirm)
{
	ir_tarval *tv;

	*confirm = NULL;

	tv = value_of(n);
	if (tarval_is_constant(tv) && ! tarval_is_null(tv))
		return 1;

	assert(mode_is_reference(get_irn_mode(n)));
	/* skip all Sel nodes */
	while (is_Sel(n)) {
		n = get_Sel_ptr(n);
	}
	while (1) {
		if (is_Proj(n)) { n = get_Proj_pred(n); continue; }
		break;
	}

	if (is_SymConst_addr_ent(n)) {
		/* global references are never NULL */
		return 1;
	} else if (n == get_irg_frame(get_irn_irg(n))) {
		/* local references are never NULL */
		return 1;
	} else if (is_Alloc(n)) {
		/* alloc never returns NULL (it throws an exception instead) */
		return 1;
	} else {
		/* check for more Confirms */
		for (; is_Confirm(n); n = get_Confirm_value(n)) {
			if (get_Confirm_relation(n) == ir_relation_less_greater) {
				ir_node   *bound = get_Confirm_bound(n);
				ir_tarval *tv    = value_of(bound);

				if (tarval_is_null(tv)) {
					*confirm = n;
					return 1;
				}
			}
		}
	}
	return 0;
}
flt_type IceBRG::tNFW_sig_cache::_calculate( const flt_type & in_param_1, const flt_type & in_param_2,
		const flt_type & in_param_3 ) const
{
	const auto mass = units_cast<mass_type>(std::exp(in_param_1));
	const auto z = in_param_2;
	const auto R = units_cast<distance_type>(std::exp(in_param_3));
	IceBRG::lensing_tNFW_profile profile(mass,z);
	return value_of(profile.Delta_Sigma( R ));
}
flt_type IceBRG::tNFW_group_Sigma_cache::_calculate( const flt_type & in_param_1, const flt_type & in_param_2,
		const flt_type & in_param_3, const flt_type & in_param_4 ) const
{
	const auto mass = units_cast<mass_type>(std::exp(in_param_1));
	const auto z = in_param_2;
	const auto R = units_cast<distance_type>(std::exp(in_param_3));
	const auto group_c = in_param_4;
	IceBRG::lensing_tNFW_profile profile(mass,z);
	return value_of(profile.semiquick_group_Sigma( R, group_c ));
}
Esempio n. 9
0
static int value_of(lua_State * L) {
    auto it = value_of(to_token_table(L, 1));
    if (it) {
        push_boolean(L, it->is_command());
        push_name(L, it->value());
        push_integer(L, it->expr_precedence());
        return 3;
    } else {
        push_nil(L);
        return 1;
    }
}
Esempio n. 10
0
uint32 IDbConnection::value_of(shared_ptr<DbSqlICommand> command)
{
	try
	{
		String sql;
		_parse(command, sql);

		return value_of(sql);
	}
	catch(std::exception &e)
	{
		OS_LOG_ERROR(e.what());
	}

	return 0;
}
Esempio n. 11
0
// Calculates whether or not the breakpoint condition has been met for
// the BPoint data structure.
bool BPoint::isBreak() {
        if(!isEnab)     return false;    // Is breakpoint valid to check?

        // Give the benefit of the doubt, but change final condition
        // to false if any of the break conditions fail
        bool finalCondition = true;

        long * curEA;

        if(type == PC_REG_TYPE && typeId != PC_TYPE_ID) {
                // Get the effective address for one of the registers.
                if(typeId >= D0_TYPE_ID && typeId <= D7_TYPE_ID)
                        curEA = &D[typeId];
                else
                        curEA = &A[typeId - A0_TYPE_ID];
        }
        else if(type == ADDR_TYPE) {
                // Get the effective address for a memory location.
                curEA = (long *)&memory[typeId];

                // Is the readWrite condition met?
                bool write = false;
                bool read = false;

                // At the end of this section of code, either read or write will be
                // true, or neither will be true (not both true).
                if(bpRead && curEA == readEA)
                        read = true;
                else if(bpWrite && curEA == writeEA)
                        write = true;

                switch(readWrite) {
                case RW_TYPE:   finalCondition = read || write;
                                break;
                case READ_TYPE: finalCondition = read;
                                break;
                case WRITE_TYPE:finalCondition = write;
                                break;
                case NA_TYPE:   // We don't care if currently reading or writing
                                finalCondition = true;
                                break;
                default:        // Invalid readWrite type specified.  No break.
                                finalCondition = false;
                                break;
                }
        }

        // Don't bother to continue testing condition if already failed.
        if(!finalCondition) return false;

        // Is the value in the correct range?
        long valueFound;
        long curSize;
        if(size == BYTE_SIZE)
                curSize = BYTE_MASK;
        else if(size == WORD_SIZE)
                curSize = WORD_MASK;
        else if(size == LONG_SIZE)
                curSize = LONG_MASK;

        // Compute the value for the PC
        if(type == PC_REG_TYPE && typeId == PC_TYPE_ID) {
                valueFound = PC & curSize;
        }
        // Compute the value for effective addresses (registers or memory)
        else {
                value_of(curEA, &valueFound, curSize);
        }

        // The finalCondition is now determined by whether the value is
        // relationally equivalent to the valueFound.
        switch(op) {
                case EQUAL_OP:          finalCondition = (valueFound == value);
                                        break;
                case NOT_EQUAL_OP:      finalCondition = (valueFound != value);
                                        break;
                case GT_OP:             finalCondition = (valueFound > value);
                                        break;
                case GT_EQUAL_OP:       finalCondition = (valueFound >= value);
                                        break;
                case LT_OP:             finalCondition = (valueFound < value);
                                        break;
                case LT_EQUAL_OP:       finalCondition = (valueFound <= value);
                                        break;
                case NA_OP:             // Value does not matter.
                                        finalCondition = true;
                                        break;
                default:                // Invalid op type specified.  No break.
                                        finalCondition = false;
                                        break;
        }
        
        return finalCondition;
}
Esempio n. 12
0
/**
 * Return the value of a Cmp if one or both predecessors
 * are Confirm nodes.
 *
 * @param cmp      the Cmp node
 * @param left     the left operand of the Cmp
 * @param right    the right operand of the Cmp
 * @param relation the compare relation
 */
ir_tarval *computed_value_Cmp_Confirm(const ir_node *cmp, ir_node *left, ir_node *right, ir_relation relation)
{
	ir_node    *l_bound;
	ir_relation l_relation, res_relation, neg_relation;
	interval_t  l_iv, r_iv;
	ir_tarval  *tv;

	if (is_Confirm(right)) {
		/* we want the Confirm on the left side */
		ir_node *t = right;
		right = left;
		left  = t;

		relation = get_inversed_relation(relation);
	} else if (! is_Confirm(left)) {
		/* nothing more found */
		tv = tarval_bad;
		goto check_null_case;
	}

	/* ok, here at least left is a Confirm, right might be */
	l_bound    = get_Confirm_bound(left);
	l_relation = get_Confirm_relation(left);

	if (is_Confirm(right)) {
		/*
		 * both sides are Confirm's. Check some rare cases first.
		 */
		ir_node    *r_bound    = get_Confirm_bound(right);
		ir_relation r_relation = get_Confirm_relation(right);

		/*
		 * some check can be made WITHOUT constant bounds
		 */
		if (r_bound == l_bound) {
			if (is_transitive(l_relation)) {
				ir_relation r_inc_relation = get_inversed_relation(r_relation);

				/*
				 * triangle inequality:
				 *
				 * a CMP B && B CMP b => a CMP b, !(a ~CMP b)
				 *
				 * We handle correctly cases with some <=/>= here
				 */
				if ((l_relation & ~ir_relation_equal) == (r_inc_relation & ~ir_relation_equal)) {
					res_relation = (l_relation & ~ir_relation_equal) | (l_relation & r_inc_relation & ir_relation_equal);

					if ((relation == res_relation) || ((relation & ~ir_relation_equal) == res_relation)) {
						DBG_OUT_TR(l_relation, l_bound, r_relation, r_bound, relation, "true");
						DBG_EVAL_CONFIRM(cmp);
						return tarval_b_true;
					} else {
						ir_relation neg_relation = get_negated_relation(relation);

						if ((neg_relation == res_relation) || ((neg_relation & ~ir_relation_equal) == res_relation)) {
							DBG_OUT_TR(l_relation, l_bound, r_relation, r_bound, relation, "false");
							DBG_EVAL_CONFIRM(cmp);
							return tarval_b_false;
						}
					}
				}
			}
		}

		/*
		 * Here, we check only the right Confirm, as the left Confirms are
		 * checked later anyway.
		 */
		if (left == r_bound) {
			/*
			 * l == bound(r) AND relation(r) == relation:
			 *
			 * We know that a CMP b and check for that
			 */
			if ((r_relation == relation) || (r_relation == (relation & ~ir_relation_equal))) {
				DBG_OUT_R(r_relation, r_bound, left, relation, right, "true");
				DBG_EVAL_CONFIRM(cmp);
				return tarval_b_true;
			}
			/*
			 * l == bound(r) AND relation(r) != relation:
			 *
			 * We know that a CMP b and check for a ~CMP b
			 */
			else {
				neg_relation = get_negated_relation(relation);

				if ((r_relation == neg_relation) || (r_relation == (neg_relation & ~ir_relation_equal))) {
					DBG_OUT_R(r_relation, r_bound, left, relation, right, "false");
					DBG_EVAL_CONFIRM(cmp);
					return tarval_b_false;
				}
			}
		}

		/* now, try interval magic */
		tv = compare_iv(
			get_interval(&l_iv, l_bound, l_relation),
			get_interval(&r_iv, r_bound, r_relation),
			relation);

		if (tv != tarval_bad) {
			DBG_EVAL_CONFIRM(cmp);
			return tv;
		}
	}

	/* from Here, check only left Confirm */

	/*
	 * some checks can be made WITHOUT constant bounds
	 */
	if (right == l_bound) {
		/*
		 * r == bound(l) AND relation(l) == relation:
		 *
		 * We know that a CMP b and check for that
		 */
		if ((l_relation == relation) || (l_relation == (relation & ~ir_relation_equal))) {
			DBG_OUT_L(l_relation, l_bound, left, relation, right, "true");
			DBG_EVAL_CONFIRM(cmp);
			return tarval_b_true;
		}
		/*
		 * r == bound(l) AND relation(l) is Not(relation):
		 *
		 * We know that a CMP b and check for a ~CMP b
		 */
		else {
			neg_relation = get_negated_relation(relation);

			if ((l_relation == neg_relation) || (l_relation == (neg_relation & ~ir_relation_equal))) {
				DBG_OUT_L(l_relation, l_bound, left, relation, right, "false");
				DBG_EVAL_CONFIRM(cmp);
				return tarval_b_false;
			}
		}
	}

	/* now, only right == Const can help */
	tv = value_of(right);

	if (tv != tarval_bad) {
		tv = compare_iv(
			get_interval(&l_iv, l_bound, l_relation),
			get_interval_from_tv(&r_iv, tv),
			relation);
	} else {
check_null_case:
		/* check some other cases */
		if ((relation == ir_relation_equal || relation == ir_relation_less_greater) &&
			is_Const(right) && is_Const_null(right)) {
			/* for == 0 or != 0 we have some special tools */
			ir_mode       *mode = get_irn_mode(left);
			const ir_node *dummy;
			if (mode_is_reference(mode)) {
				if (value_not_null(left, &dummy)) {
					tv = relation == ir_relation_equal ? tarval_b_false : tarval_b_true;
				}
			} else {
				if (value_not_zero(left, &dummy)) {
					tv = relation == ir_relation_equal ? tarval_b_false : tarval_b_true;
				}
			}
		}
	}

	if (tv != tarval_bad)
		DBG_EVAL_CONFIRM(cmp);

	return tv;
}
Esempio n. 13
0
/*
 * Check, if the value of a node is != 0.
 *
 * This is a often needed case, so we handle here Confirm
 * nodes too.
 */
int value_not_zero(const ir_node *n, const ir_node **confirm)
{
#define RET_ON(x)  if (x) { *confirm = n; return 1; } break

	ir_tarval *tv;
	ir_mode *mode = get_irn_mode(n);
	ir_relation relation;

	*confirm = NULL;

	/* there might be several Confirms one after other that form an interval */
	for (;;) {
		if (is_Minus(n)) {
			/* we can safely skip Minus when checking for != 0 */
			n = get_Minus_op(n);
			continue;
		}
		if (! is_Confirm(n))
			break;

		/*
		 * Note: A Confirm is never after a Const. So,
		 * we simply can check the bound for being a Const
		 * without the fear that is might be hidden by a further Confirm.
		 */
		tv = value_of(get_Confirm_bound(n));
		if (tv == tarval_bad) {
			n = get_Confirm_value(n);
			continue;
		}

		relation = tarval_cmp(tv, get_mode_null(mode));

		/*
		 * Beware: C might by a NaN. It is not clear, what we should do
		 * than. Of course a NaN is != 0, but we might use this function
		 * to remove up Exceptions, and NaN's might generate Exception.
		 * So, we do NOT handle NaNs here for safety.
		 *
		 * Note that only the C != 0 case need additional checking.
		 */
		switch (get_Confirm_relation(n)) {
		case ir_relation_equal: /* n == C /\ C != 0 ==> n != 0 */
			RET_ON(relation != ir_relation_equal && relation != ir_relation_unordered);
		case ir_relation_less_greater: /* n != C /\ C == 0 ==> n != 0 */
			RET_ON(relation == ir_relation_equal);
		case ir_relation_less: /* n <  C /\ C <= 0 ==> n != 0 */
			RET_ON(relation == ir_relation_less || relation == ir_relation_equal);
		case ir_relation_less_equal: /* n <= C /\ C <  0 ==> n != 0 */
			RET_ON(relation == ir_relation_less);
		case ir_relation_greater_equal: /* n >= C /\ C >  0 ==> n != 0 */
			RET_ON(relation == ir_relation_greater);
		case ir_relation_greater: /* n >  C /\ C >= 0 ==> n != 0 */
			RET_ON(relation == ir_relation_greater || relation == ir_relation_equal);
		default:
			break;
		}
		n = get_Confirm_value(n);
	}
	/* global entities are never NULL */
	if (is_SymConst_addr_ent(n))
		return true;

	tv = value_of(n);
	if (tv == tarval_bad)
		return false;

	relation = tarval_cmp(tv, get_mode_null(mode));

	/* again, need check for NaN */
	return (relation != ir_relation_equal) && (relation != ir_relation_unordered);

#undef RET_ON
}
Esempio n. 14
0
/*
 * Check, if the value of a node can be confirmed >= 0 or <= 0,
 * If the mode of the value did not honor signed zeros, else
 * check for >= 0 or < 0.
 */
ir_value_classify_sign classify_value_sign(ir_node *n)
{
	ir_tarval *tv, *c;
	ir_mode *mode;
	ir_relation cmp, ncmp;
	int negate = 1;

	for (;;) {
		unsigned code = get_irn_opcode(n);

		switch (code) {
		case iro_Minus:
			negate *= -1;
			n = get_Minus_op(n);
			continue;
		case iro_Confirm:
			break;
		default:
			return value_classified_unknown;
		}
		break;
	}
	if (!is_Confirm(n))
		return value_classified_unknown;

	tv  = value_of(get_Confirm_bound(n));
	if (tv == tarval_bad)
		return value_classified_unknown;

	mode = get_irn_mode(n);

	/*
	 * We can handle only >=, >, <, <= cases.
	 * We could handle == too, but this will be optimized into
	 * a constant either.
	 *
	 * Note that for integer modes we have a slightly better
	 * optimization possibilities, so we handle this
	 * different.
	 */
	cmp = get_Confirm_relation(n);

	switch (cmp) {
	case ir_relation_less:
		/*
		 * must be x < c <= 1 to be useful if integer mode and -0 = 0
		 *         x < c <= 0 to be useful else
		 */
	case ir_relation_less_equal:
		/*
		 * must be x <= c < 1 to be useful if integer mode and -0 = 0
		 *         x <= c < 0 to be useful else
		 */
		c = mode_is_int(mode) && mode_honor_signed_zeros(mode) ?
			get_mode_one(mode) : get_mode_null(mode);

		ncmp = tarval_cmp(tv, c);
		if (ncmp == ir_relation_equal)
			ncmp = ir_relation_less_equal;

		if (cmp != (ncmp ^ ir_relation_equal))
			return value_classified_unknown;

		/* yep, negative */
		return value_classified_negative * negate;

	case ir_relation_greater_equal:
		/*
		 * must be x >= c > -1 to be useful if integer mode
		 *         x >= c >= 0 to be useful else
		 */
	case ir_relation_greater:
		/*
		 * must be x > c >= -1 to be useful if integer mode
		 *         x > c >= 0 to be useful else
		 */
		if (mode_is_int(mode)) {
			c = get_mode_minus_one(mode);

			ncmp = tarval_cmp(tv, c);
			if (ncmp == ir_relation_equal)
				ncmp = ir_relation_greater_equal;

			if (cmp != (ncmp ^ ir_relation_equal))
				return value_classified_unknown;
		} else {
			c = get_mode_minus_one(mode);

			ncmp = tarval_cmp(tv, c);

			if (ncmp != ir_relation_equal && ncmp != ir_relation_greater)
				return value_classified_unknown;
		}

		/* yep, positive */
		return value_classified_positive * negate;

	default:
		return value_classified_unknown;
	}
}
Esempio n. 15
0
/**
 * construct an interval from a Confirm
 *
 * @param iv       an empty interval, will be filled
 * @param bound    the bound value
 * @param relation the Confirm compare relation
 *
 * @return the filled interval or NULL if no interval
 *         can be created (happens only on floating point
 */
static interval_t *get_interval(interval_t *iv, ir_node *bound, ir_relation relation)
{
	ir_mode   *mode = get_irn_mode(bound);
	ir_tarval *tv   = value_of(bound);

	if (tv == tarval_bad) {
		/* There is nothing we could do here. For integer
		 * modes we could return [-oo, +oo], but there is
		 * nothing we could deduct from such an interval.
		 * So, speed things up and return unknown.
		 */
		iv->min   = tarval_bad;
		iv->max   = tarval_bad;
		iv->flags = MIN_EXCLUDED | MAX_EXCLUDED;
		return NULL;
	}

	if (mode_is_float(mode)) {
		if (tv == get_mode_NAN(mode)) {
			/* arg, we cannot handle NaN's. */
			iv->min   = tarval_bad;
			iv->max   = tarval_bad;
			iv->flags = MIN_EXCLUDED | MAX_EXCLUDED;

			return NULL;
		}
	}

	/* check which side is known */
	switch (relation) {
	case ir_relation_equal:
		/* [tv, tv] */
		iv->min   =
			iv->max   = tv;
		iv->flags = MIN_INCLUDED | MAX_INCLUDED;
		break;

	case ir_relation_less_equal:
		/* [-oo, tv] */
		iv->min   = get_mode_min(mode);
		iv->max   = tv;
		iv->flags = MIN_INCLUDED | MAX_INCLUDED;
		break;

	case ir_relation_less:
		/* [-oo, tv) */
		iv->min   = get_mode_min(mode);
		iv->max   = tv;
		iv->flags = MIN_INCLUDED | MAX_EXCLUDED;
		break;

	case ir_relation_greater:
		/* (tv, +oo] */
		iv->min   = tv;
		iv->max   = get_mode_max(mode);
		iv->flags = MIN_EXCLUDED | MAX_INCLUDED;
		break;

	case ir_relation_greater_equal:
		/* [tv, +oo] */
		iv->min   = tv;
		iv->max   = get_mode_max(mode);
		iv->flags = MIN_INCLUDED | MAX_INCLUDED;
		break;

	case ir_relation_less_equal_greater:
		/*
		 * Ordered means, that at least neither
		 * our bound nor our value ara NaN's
		 */
		/* [-oo, +oo] */
		iv->min   = get_mode_min(mode);
		iv->max   = get_mode_max(mode);
		iv->flags = MIN_INCLUDED | MAX_INCLUDED;
		break;

	default:
		/*
		 * We do not handle UNORDERED, as a NaN
		 * could be included in the interval.
		 */
		iv->min   = tarval_bad;
		iv->max   = tarval_bad;
		iv->flags = MIN_EXCLUDED | MAX_EXCLUDED;
		return NULL;
	}

	if (iv->min != tarval_bad && iv->max != tarval_bad)
		return iv;
	return NULL;
}
Esempio n. 16
0
bool NodeListT::FollowToNode(const std::vector<StationID>::const_iterator &itr,
	std::multimap<UnitID, NodeListT::SuperInfoT> &supersets,
	const std::vector<StationID>::const_iterator &itr_1,
	bool neg) const
{
	const auto node_itr = nodes.find(*itr);
	if(node_itr == nodes.end())
		return false;
	const NodeInfoT* info = &node_itr->second;

	auto next = supersets.begin();
	for(auto sitr = supersets.begin(); sitr != supersets.end(); sitr = next)
	{
		++(next = sitr);

		UnitID cur_line = sitr->first;
		std::size_t& last_station_no = sitr->second.last_station_no;
		std::size_t new_last_station_no = std::numeric_limits<std::size_t>::max();

		const auto in_nodes = info->equal_range(cur_line);
		std::size_t tmp = lengths.at(cur_line);
		for(auto in_node = in_nodes.first;
			in_node != in_nodes.second; ++in_node)
		{
			tmp = value_of(supersets, cur_line, in_node->second, neg);
			if(tmp == 0)
				tmp = lengths.at(cur_line);
			if(tmp >= last_station_no && // is it a future node?
				tmp < new_last_station_no /* better than previous result? */ )
			{
				new_last_station_no = tmp;
			}
		}

		if(new_last_station_no == std::numeric_limits<std::size_t>::max())
			supersets.erase(sitr);
		else
		{
			// was the last node visited twice before we got here?
			// if so, this train can still be a short train
			const auto& last_in_nodes =
					nodes.at(*itr_1).equal_range(cur_line);

			bool no_express = true;
			if(last_station_no < new_last_station_no - 1) // some nodes between...
			{
				no_express = false;
				for(auto last_in_node = last_in_nodes.first;
					(!no_express) && last_in_node != last_in_nodes.second;
					++last_in_node)
				{
					std::size_t value_found_in_last = value_of(supersets, cur_line, last_in_node->second, neg);
					if(last_station_no < value_found_in_last
							&& value_found_in_last == (new_last_station_no-1))
					{
						// ok, it was just a slope we've left out
						no_express = true;
					}
				}
			}

			sitr->second.can_be_short_train =
					sitr->second.can_be_short_train && no_express;

			// advance
			last_station_no = new_last_station_no;
		}
	}
	return true;
}
Esempio n. 17
0
std::shared_ptr<type> type::operator<=(type& another)
{
    return value_of((*this < another)->to_bool() || (*this == another)->to_bool());
}
Esempio n. 18
0
int
optionsEditor(dialogMenuItem *self)
{
    int i, optcol, optrow, key;
    static int currOpt = 0;

    dialog_clear_norefresh();
    clear();

    while (1) {
	/* Whap up the header */
	attrset(A_REVERSE); mvaddstr(0, 0, "Options Editor"); attrset(A_NORMAL);
	for (i = 0; i < 2; i++) {
	    mvaddstr(OPT_START_ROW - 2, OPT_NAME_COL + (i * GROUP_OFFSET), "Name");
	    mvaddstr(OPT_START_ROW - 1, OPT_NAME_COL + (i * GROUP_OFFSET), "----");

	    mvaddstr(OPT_START_ROW - 2, OPT_VALUE_COL + (i * GROUP_OFFSET), "Value");
	    mvaddstr(OPT_START_ROW - 1, OPT_VALUE_COL + (i * GROUP_OFFSET), "-----");
	}
	/* And the footer */
	mvprintw(OPT_END_ROW + 1, 0, "Use SPACE to select/toggle an option, arrow keys to move,");
	mvprintw(OPT_END_ROW + 2, 0, "? or F1 for more help.  When you're done, type Q to Quit.");

	optrow = OPT_START_ROW;
	optcol = OPT_NAME_COL;
	for (i = 0; Options[i].name; i++) {
	    /* Names are painted somewhat gratuitously each time, but it's easier this way */
	    mvprintw(optrow, OPT_NAME_COL + optcol, Options[i].name);
	    if (currOpt == i)
		attrset(ATTR_SELECTED);
	    mvprintw(optrow++, OPT_VALUE_COL + optcol, value_of(Options[i]));
	    if (currOpt == i)
		attrset(A_NORMAL);
	    if (optrow == OPT_END_ROW) {
		optrow = OPT_START_ROW;
		optcol += GROUP_OFFSET;
	    }
	    clrtoeol();
	}
	attrset(ATTR_TITLE);
	mvaddstr(OPT_END_ROW + 4, 0, Options[currOpt].desc);
	attrset(A_NORMAL);
	clrtoeol();
	move(0, 14);
        refresh();

	/* Start the edit loop */
	key = toupper(getch());
	switch (key) {
	case KEY_F(1):
	case '?':
	    systemDisplayHelp("options");
	    clear();
	    break;

	case '\020':	/* ^P */
	case KEY_UP:
	    if (currOpt)
		--currOpt;
	    else
		for (currOpt = 0; Options[currOpt + 1].name; currOpt++);
	    continue;

	case '\016':	/* ^N */
	case KEY_DOWN:
	    if (Options[currOpt + 1].name)
		++currOpt;
	    else
		currOpt = 0;
	    continue;

	case KEY_HOME:
	    currOpt = 0;
	    continue;

	case KEY_END:
	    while (Options[currOpt + 1].name)
		++currOpt;
	    continue;

	case ' ':
	    if (fire(Options[currOpt]))
	    	clear();
	    continue;

	case '\033':	/* ESC */
	case 'Q':
	    clear();
	    dialog_clear();
	    return DITEM_SUCCESS | DITEM_RESTORE;

	default:
	    beep();
	}
    }
    /* NOTREACHED */
    return DITEM_SUCCESS | DITEM_RESTORE;
}
Esempio n. 19
0
	const Array::Temp Interpreter::eval_list(const char* string) const {
		return eval_list(value_of(string));
	}
Esempio n. 20
0
	Package Interpreter::use(const char* package_name, double version) const {
		load_module(PERL_LOADMOD_NOIMPORT, value_of(package_name).get_SV(true), value_of(version).get_SV(true), NULL);
		return package(package_name);
	}
Esempio n. 21
0
 string entry()
 {
  array<string> lines;
  
  //sequences
  
  while(!is_empty())
  {
   array<atom> atoms=sequence();
   
   log(atoms);
   log();
   
   for(int i=0;i<atoms.count();i++)
   {
    auto& current=atoms[i];
    
    //lf
    
    if(current.is_lf())
    {
     lines.push();
     lines.push(concat("//",current.line()));
     
     continue;
    }
    
    //value
    
    string value=value_of(current);
    string location=location_of(current);
    
    //identifier
    
    if(current.is_identifier())
    {
     lines.push(concat("vm.evaluate",pack(value,location).join(",").parens(),";"));
     
     continue;     
    }
    
    //push
    
    lines.push(concat("vm.push",pack(value,location).join(",").parens(),";"));
   }
  }
  
  //format
  
  array<string> result;
  
  result.push("//entry");
    
  //prototype
  
  result.push();
  result.push("void entry(vm& vm)");
  
  //body

  result.append(lines.text().braces().lines());  
  
  return result.text();
 }
Esempio n. 22
0
void interp(NODE *n)
{
  int nattrs;				// number of attributes 
  int type;				// attribute type
  int len;				// attribute length
  int op;				// comparison operator
  NODE *temp, *temp1, *temp2;		// temporary node pointers
  char *attrname;			// temp attribute names
  void *value;			        // temp value	
  int nbuckets;			        // temp number of buckets
  int errval;				// returned error value
  RelDesc relDesc;
  Status status;
  int attrCnt, i, j;
  AttrDesc *attrs;
  string resultName;
  static int counter = 0;

  // if input not coming from a terminal, then echo the query

  if (!isatty(0))
    echo_query(n);

  switch(n->kind) {
  case N_QUERY:

    // First check if the result relation is specified

    if (n->u.QUERY.relname)
      {
	resultName = n->u.QUERY.relname;

	// Check if the result relation exists.
	status = attrCat->getRelInfo(resultName, attrCnt, attrs);
	if (status != OK && status != RELNOTFOUND)
	  {
	    error.print(status);
	    return;
	  }
      }
    else
      {
	resultName = "Tmp_Minirel_Result";

	status = relCat->getInfo(resultName, relDesc);
	if (status != OK && status != RELNOTFOUND)
	  {
	    error.print(status);
	    return;
	  }

	if (status == OK)
	  {
	    error.print(TMP_RES_EXISTS);
	    return;
	  }
      }


    // if no qualification then this is a simple select
    temp = n->u.QUERY.qual;
    if (temp == NULL) {

      // make a list of attribute names suitable for passing to select
      nattrs = mk_attrnames(temp1 = n->u.QUERY.attrlist, names, NULL);
      if (nattrs < 0) {
	print_error("select", nattrs);
	break;
      }

      for(int acnt = 0; acnt < nattrs; acnt++) {
	strcpy(attrList[acnt].relName, names[nattrs]);
	strcpy(attrList[acnt].attrName, names[acnt]);
	attrList[acnt].attrType = -1;
	attrList[acnt].attrLen = -1;
	attrList[acnt].attrValue = NULL;
      }
      
      if (status == RELNOTFOUND)
	{
	  // Create the result relation
	  attrInfo *createAttrInfo = new attrInfo[nattrs];
	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      strcpy(createAttrInfo[i].relName, resultName.c_str());
	      strcpy(createAttrInfo[i].attrName, attrList[i].attrName);
	      
	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}
	      createAttrInfo[i].attrType = attrDesc.attrType;
	      createAttrInfo[i].attrLen = attrDesc.attrLen;
	    }

	  status = relCat->createRel(resultName, nattrs, createAttrInfo);
	  delete []createAttrInfo;

	  if (status != OK)
	    {
	      error.print(status);
	      return;
	    }
	}
      else
	{
	  // Check to see that the attribute types match
	  if (nattrs != attrCnt)
	    {
	      error.print(ATTRTYPEMISMATCH);
	      return;
	    }

	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}

	      if (attrDesc.attrType != attrs[i].attrType || 
		  attrDesc.attrLen != attrs[i].attrLen)
		{
		  error.print(ATTRTYPEMISMATCH);
		  return;
		}
	    }
	  free(attrs);
	}

      // make the call to QU_Select

      errval = QU_Select(resultName,
			 nattrs,
			 attrList,
			 NULL,
			 (Operator)0,
			 NULL);

      if (errval != OK)
	error.print((Status)errval);
    }

    // if qual is `attr op value' then this is a regular select
    else if (temp->kind == N_SELECT) {
	  
      temp1 = temp->u.SELECT.selattr;

      // make a list of attribute names suitable for passing to select
      nattrs = mk_attrnames(n->u.QUERY.attrlist, names,
			    temp1->u.QUALATTR.relname);
      if (nattrs < 0) {
	print_error("select", nattrs);
	break;
      }

      for(int acnt = 0; acnt < nattrs; acnt++) {
	strcpy(attrList[acnt].relName, names[nattrs]);
	strcpy(attrList[acnt].attrName, names[acnt]);
	attrList[acnt].attrType = -1;
	attrList[acnt].attrLen = -1;
	attrList[acnt].attrValue = NULL;
      }
      
      strcpy(attr1.relName, names[nattrs]);
      strcpy(attr1.attrName, temp1->u.QUALATTR.attrname);
      attr1.attrType = type_of(temp->u.SELECT.value);
      attr1.attrLen = -1;
      attr1.attrValue = (char *)value_of(temp->u.SELECT.value);

      if (status == RELNOTFOUND)
	{
	  // Create the result relation
	  attrInfo *createAttrInfo = new attrInfo[nattrs];
	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      strcpy(createAttrInfo[i].relName, resultName.c_str());
	      strcpy(createAttrInfo[i].attrName, attrList[i].attrName);
	      
	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}
	      createAttrInfo[i].attrType = attrDesc.attrType;
	      createAttrInfo[i].attrLen = attrDesc.attrLen;
	    }

	  status = relCat->createRel(resultName, nattrs, createAttrInfo);
	  delete []createAttrInfo;

	  if (status != OK)
	    {
	      error.print(status);
	      return;
	    }
	}
      else
	{
	  // Check to see that the attribute types match
	  if (nattrs != attrCnt)
	    {
	      error.print(ATTRTYPEMISMATCH);
	      return;
	    }

	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}

	      if (attrDesc.attrType != attrs[i].attrType || 
		  attrDesc.attrLen != attrs[i].attrLen)
		{
		  error.print(ATTRTYPEMISMATCH);
		  return;
		}
	    }
	  free(attrs);
	}

      // make the call to QU_Select
      char * tmpValue = (char *)value_of(temp->u.SELECT.value);

      errval = QU_Select(resultName,
			 nattrs,
			 attrList,
			 &attr1,
			 (Operator)temp->u.SELECT.op,
			 tmpValue);

      delete [] tmpValue;
      delete [] attr1.attrValue;

      if (errval != OK)
	error.print((Status)errval);
    }

    // if qual is `attr1 op attr2' then this is a join
    else {

      temp1 = temp->u.JOIN.joinattr1;
      temp2 = temp->u.JOIN.joinattr2;

      // make an attribute list suitable for passing to join
      nattrs = mk_qual_attrs(n->u.QUERY.attrlist,
			     qual_attrs,
			     temp1->u.QUALATTR.relname,
			     temp2->u.QUALATTR.relname);
      if (nattrs < 0) {
	print_error("select", nattrs);
	break;
      }

      // set up the joined attributes to be passed to Join
      qual_attrs[nattrs].relName = temp1->u.QUALATTR.relname;
      qual_attrs[nattrs].attrName = temp1->u.QUALATTR.attrname;
      qual_attrs[nattrs + 1].relName = temp2->u.QUALATTR.relname;
      qual_attrs[nattrs + 1].attrName = temp2->u.QUALATTR.attrname;
      
      for(int acnt = 0; acnt < nattrs; acnt++) {
	strcpy(attrList[acnt].relName, qual_attrs[acnt].relName);
	strcpy(attrList[acnt].attrName, qual_attrs[acnt].attrName);
	attrList[acnt].attrType = -1;
	attrList[acnt].attrLen = -1;
	attrList[acnt].attrValue = NULL;
      }
      
      strcpy(attr1.relName, qual_attrs[nattrs].relName);
      strcpy(attr1.attrName, qual_attrs[nattrs].attrName);
      attr1.attrType = -1;
      attr1.attrLen = -1;
      attr1.attrValue = NULL;

      strcpy(attr2.relName, qual_attrs[nattrs+1].relName);
      strcpy(attr2.attrName, qual_attrs[nattrs+1].attrName);
      attr2.attrType = -1;
      attr2.attrLen = -1;
      attr2.attrValue = NULL;

      if (status == RELNOTFOUND)
	{
	  // Create the result relation
	  attrInfo *createAttrInfo = new attrInfo[nattrs];
	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      strcpy(createAttrInfo[i].relName, resultName.c_str());

	      // Check if there is another attribute with same name
	      for (j = 0; j < i; j++)
		if (!strcmp(createAttrInfo[j].attrName, attrList[i].attrName))
		  break;

	      strcpy(createAttrInfo[i].attrName, attrList[i].attrName);

	      if (j != i)
		sprintf(createAttrInfo[i].attrName, "%s_%d", 
			createAttrInfo[i].attrName, counter++);
	      
	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}
	      createAttrInfo[i].attrType = attrDesc.attrType;
	      createAttrInfo[i].attrLen = attrDesc.attrLen;
	    }

	  status = relCat->createRel(resultName, nattrs, createAttrInfo);
	  delete []createAttrInfo;

	  if (status != OK)
	    {
	      error.print(status);
	      return;
	    }
	}
      else
	{
	  // Check to see that the attribute types match
	  if (nattrs != attrCnt)
	    {
	      error.print(ATTRTYPEMISMATCH);
	      return;
	    }

	  for (i = 0; i < nattrs; i++)
	    {
	      AttrDesc attrDesc;

	      status = attrCat->getInfo(attrList[i].relName,
					attrList[i].attrName,
					attrDesc);
	      if (status != OK)
		{
		  error.print(status);
		  return;
		}

	      if (attrDesc.attrType != attrs[i].attrType || 
		  attrDesc.attrLen != attrs[i].attrLen)
		{
		  error.print(ATTRTYPEMISMATCH);
		  return;
		}
	    }
	  free(attrs);
	}

      // make the call to QU_Join

      errval = QU_Join(resultName,
		       nattrs,
		       attrList,
		       &attr1,
		       (Operator)temp->u.JOIN.op,
		       &attr2);

      if (errval != OK)
	error.print((Status)errval);
    }

    if (resultName == string( "Tmp_Minirel_Result"))
      {
	// Print the contents of the result relation and destroy it
	status = UT_Print(resultName);
	if (status != OK)
	  error.print(status);

	status = relCat->destroyRel(resultName);
	if (status != OK)
	  error.print(status);
      }

    break;

  case N_INSERT:

    // make attribute and value list to be passed to QU_Insert
    nattrs = mk_ins_attrs(n->u.INSERT.attrlist, ins_attrs);
    if (nattrs < 0) {
      print_error("insert", nattrs);
      break;
    }
    
    // make the call to QU_Insert
    int acnt;
    for(acnt = 0; acnt < nattrs; acnt++) {
      strcpy(attrList[acnt].relName, n->u.INSERT.relname);
      strcpy(attrList[acnt].attrName, ins_attrs[acnt].attrName);
      attrList[acnt].attrType = (Datatype)ins_attrs[acnt].valType;
      attrList[acnt].attrLen = -1;
      attrList[acnt].attrValue = ins_attrs[acnt].value;
    }
      
    errval = QU_Insert(n->u.INSERT.relname,
		       nattrs,
		       attrList);

    for (acnt = 0; acnt < nattrs; acnt++)
      delete [] attrList[acnt].attrValue;

    if (errval != OK)
      error.print((Status)errval);
    
    break;

  case N_DELETE:

    // set up the name of deletion relation
    qual_attrs[0].relName = n->u.DELETE.relname;
    
    // if qualification given...
    if ((temp1 = n->u.DELETE.qual) != NULL) {
      // qualification must be a select, not a join
      if (temp1->kind != N_SELECT) {
	cerr << "Syntax Error" << endl;
	break;
      }
	    
      temp2 = temp1->u.SELECT.selattr;
/*      
      // make sure attribute in qualification is from deletion rel
      if (strcmp(n->u.DELETE.relname, temp2->u.QUALATTR.relname)) {
	print_error("delete", E_INCOMPATIBLE);
	break;
      }
*/      
      // set up qualification
      attrname = temp2->u.QUALATTR.attrname;
      op = temp1->u.SELECT.op;
      type = type_of(temp1->u.SELECT.value);
      len = length_of(temp1->u.SELECT.value);
      value = value_of(temp1->u.SELECT.value);
    }
    
    // otherwise, set up for no qualification
    else {
      attrname = NULL;
      op = (Operator)0;
      type = 0;
      len = 0;
      value = NULL;
    }

    // make the call to QU_Delete

    if (attrname)
      errval = QU_Delete(n -> u.DELETE.relname,
			 attrname,
			 (Operator)op,
			 (Datatype)type,
			 (char *)value);
    else
      errval = QU_Delete(n -> u.DELETE.relname,
			 "",
			 (Operator)op,
			 (Datatype)type,
			 (char *)value);

    delete [] value;

    if (errval != OK)
      error.print((Status)errval);

    break;

  case N_CREATE:

    // make a list of ATTR_DESCRS suitable for sending to UT_Create
    nattrs = mk_attr_descrs(n->u.CREATE.attrlist, attr_descrs);
    if (nattrs < 0) {
      print_error("create", nattrs);
      break;
    }

    // get info about primary attribute, if there is one
    if ((temp = n->u.CREATE.primattr) == NULL) {
      attrname = NULL;
      nbuckets = 1;
    } else {
      attrname = temp->u.PRIMATTR.attrname;
      nbuckets = temp->u.PRIMATTR.nbuckets;
    }

    for(acnt = 0; acnt < nattrs; acnt++) {
      strcpy(attrList[acnt].relName, n -> u.CREATE.relname);
      strcpy(attrList[acnt].attrName, attr_descrs[acnt].attrName);
      attrList[acnt].attrType = attr_descrs[acnt].attrType;
      attrList[acnt].attrLen = attr_descrs[acnt].attrLen;
      attrList[acnt].attrValue = NULL;
    }
      
    // make the call to UT_Create
    errval = relCat->createRel(n -> u.CREATE.relname,
			       nattrs,
			       attrList);

    if (errval != OK)
      error.print((Status)errval);


    break;

  case N_DESTROY:

    errval = relCat->destroyRel(n -> u.DESTROY.relname);
    if (errval != OK)
      error.print((Status)errval);

    break;

  case N_LOAD:

    errval = UT_Load(n -> u.LOAD.relname, n -> u.LOAD.filename);

    if (errval != OK)
      error.print((Status)errval);

    break;

  case N_PRINT:

    errval = UT_Print(n -> u.PRINT.relname);

    if (errval != OK)
      error.print((Status)errval);

    break;
    
  case N_HELP:

    if (n -> u.HELP.relname)
      errval = relCat->help(n -> u.HELP.relname);
    else
      errval = relCat->help("");

    if (errval != OK)
      error.print((Status)errval);

    break;

  default:                              // so that compiler won't complain
    assert(0);
  }
}
Esempio n. 23
0
	const Scalar::Temp Interpreter::eval(const char* string) const {
		return eval(value_of(string));
	}
Esempio n. 24
0
int NodeListT::Traverse(const comm::OrderList &ol, std::map<UnitID, NodeListT::SupersetType> *matches, bool neg, bool ignore_cargo) const
{
	if(matches)
		matches->clear();

	std::vector<StationID> stations;
	for(const auto& pr : ol.stations.Get())
		if(pr.second)
			stations.push_back(pr.first);

	UnitID train = ol.unit_number;

	enum class Masks
	{
		M_SAME = 1,
		M_OPPOSITE = 2,
		M_REMOVE = 4,
		M_TWO_DIRECTIONS = 3
	};

	std::multimap<UnitID, SuperInfoT> supersets;

	// find first node where the train stops
	const NodeInfoT* station_0;
	const auto itr_0 = nodes.find(stations[0]);
	if(itr_0 == nodes.end())
		return NO_SUPERSETS;
	else
		station_0 = &itr_0->second;

	// fill map for the first node
	for(const auto& pr : *station_0)
	if(pr.first != train)
	{
		const auto& c_oth = cargo.at(pr.first);
		const auto& c_this = cargo.at(train);
		if(ignore_cargo
			|| std::includes(c_oth.begin(), c_oth.end(), c_this.begin(), c_this.end()))
			supersets.emplace(pr.first, SuperInfoT { pr.second, DIR_NONE, 0, true, lengths.find(pr.first)->second });
	}

	const auto& c_this = cargo.at(train);

	for(const auto& pr : *station_0)
	if(pr.first != train)
	{
		const auto& c_oth = cargo.at(pr.first);
		if(ignore_cargo
			|| std::includes(c_oth.begin(), c_oth.end(), c_this.begin(), c_this.end()))
		if(value_of(supersets, pr.first, station_0->find(pr.first)->second, neg) != 0)
		 throw "Internal error: invalid value computation";
	}

	// follow the order list, find monotonically increasing superset line
	for(auto itr = stations.begin() + 1; itr != stations.end(); ++itr)
	if(! FollowToNode(itr, supersets, itr-1, neg) )
	 return NO_SUPERSETS;
	// last node: (end-1) -> (begin)
	FollowToNode(stations.begin(), supersets, stations.end() - 1, neg);

	int result = NO_SUPERSETS;
	std::size_t m_length = lengths.find(ol.unit_number)->second;
	for(const auto& pr : supersets)
	{
#ifdef DEBUG_EXPRESS_TRAINS
		std::cerr << "train " << train
			  << ", other: " << pr.first
			  << " -> short? " << pr.second.can_be_short_train << std::endl;
#endif
		int tmp_mask = (pr.second.can_be_short_train
				? IS_SHORT_TRAIN : IS_EXPRESS_TRAIN);
		if(pr.second.length == m_length) {
			const auto& c_oth = cargo.at(pr.first);
			if(ignore_cargo ||
				std::includes(c_this.begin(), c_this.end(), c_oth.begin(), c_oth.end()))
			 tmp_mask |= IS_SAME_TRAIN;
		}

		if(tmp_mask)
		{
			if(matches)
				(*matches)[pr.first] = (SupersetType)tmp_mask;
			result |= tmp_mask;
		}
	}

	return result;
}
Esempio n. 25
0
	const Regex Interpreter::regex(Raw_string regexp, Raw_string flags) const {
		return regex(value_of(regexp), flags);
	}
// Print data for all bins
void pair_bins_summary::print_bin_data(std::ostream &out,
		const unitconv_map & u_map)
{

	// Set up the data and header to be printed
	table_t<flt_type> data;
	header_t header;

	header.push_back("R_min");
	header.push_back("R_max");
	header.push_back("m_min");
	header.push_back("m_max");
	header.push_back("z_min");
	header.push_back("z_max");
	header.push_back("mag_min");
	header.push_back("mag_max");

	header.push_back("shear_R_mean");
	header.push_back("shear_lens_m_mean");
	header.push_back("shear_lens_z_mean");
	header.push_back("shear_lens_mag_mean");

	header.push_back("shear_source_z_mean");

	header.push_back("shear_N_pair");
	header.push_back("shear_N_pair_eff");

	header.push_back("shear_Sigma_crit");

	header.push_back("dS_t_mean");
	header.push_back("dS_t_stddev");
	header.push_back("dS_t_stderr");
	header.push_back("dS_x_mean");
	header.push_back("dS_x_stddev");
	header.push_back("dS_x_stderr");

	header.push_back("gamma_t_mean");
	header.push_back("gamma_t_stderr");
	header.push_back("gamma_x_mean");
	header.push_back("gamma_x_stderr");

	header.push_back("model_dS_t");
	header.push_back("model_gamma_t");

	header.push_back("model_1h_dS_t");
	header.push_back("model_1h_gamma_t");

	header.push_back("model_group_dS_t");
	header.push_back("model_group_gamma_t");

	header.push_back("magf_R_mean");
	header.push_back("magf_lens_m_mean");
	header.push_back("magf_lens_z_mean");
	header.push_back("magf_lens_mag_mean");

	header.push_back("magf_source_z_mean");

	header.push_back("magf_N_lens");
	header.push_back("magf_area");

	header.push_back("magf_Sigma_crit");

	header.push_back("mu");
	header.push_back("mu_stderr");
	header.push_back("kappa");
	header.push_back("kappa_stderr");
	header.push_back("Sigma");
	header.push_back("Sigma_stderr");

	header.push_back("model_mu");
	header.push_back("model_kappa");
	header.push_back("model_Sigma");

	header.push_back("model_1h_mu");
	header.push_back("model_1h_kappa");
	header.push_back("model_1h_Sigma");

	header.push_back("model_group_mu");
	header.push_back("model_group_kappa");
	header.push_back("model_group_Sigma");

	ssize_t num_columns = ssize(header);

	data.resize(num_columns);
	for(const auto & R_bins : pair_bin_summaries())
	{
		for(const auto & Rm_bins : R_bins)
		{
			for(const auto & Rmz_bins : Rm_bins)
			{
				for(const auto & bin : Rmz_bins)
				{

					// Check if this bin is good
					if(bin.shear_effective_pair_count()>=std::numeric_limits<flt_type>::max()) continue;
					if(isbad(bin.shear_effective_pair_count())) continue;
					// It's possible we'll get bins with no shear information like this, but this
					// prunes out at least those without any info

					ssize_t col_i = -1;

					data[++col_i].push_back(value_of(bin.R_min()));
					data[++col_i].push_back(value_of(bin.R_max()));
					data[++col_i].push_back(value_of(bin.m_min()));
					data[++col_i].push_back(value_of(bin.m_max()));
					data[++col_i].push_back(bin.z_min());
					data[++col_i].push_back(bin.z_max());
					data[++col_i].push_back(bin.mag_min());
					data[++col_i].push_back(bin.mag_max());

					data[++col_i].push_back(value_of(bin.shear_R_mean()));
					data[++col_i].push_back(value_of(bin.shear_lens_m_mean()));
					data[++col_i].push_back(bin.shear_lens_z_mean());
					data[++col_i].push_back(bin.shear_lens_mag_mean());

					data[++col_i].push_back(bin.shear_source_z_mean());

					data[++col_i].push_back(bin.shear_pair_count());
					data[++col_i].push_back(bin.shear_effective_pair_count());

					data[++col_i].push_back(value_of(bin.shear_sigma_crit()));

					data[++col_i].push_back(value_of(bin.delta_Sigma_t_mean()));
					data[++col_i].push_back(value_of(bin.delta_Sigma_t_std()));
					data[++col_i].push_back(value_of(bin.delta_Sigma_t_stderr()));
					data[++col_i].push_back(value_of(bin.delta_Sigma_x_mean()));
					data[++col_i].push_back(value_of(bin.delta_Sigma_x_std()));
					data[++col_i].push_back(value_of(bin.delta_Sigma_x_stderr()));

					data[++col_i].push_back(bin.gamma_t_mean());
					data[++col_i].push_back(bin.gamma_t_stderr());
					data[++col_i].push_back(bin.gamma_x_mean());
					data[++col_i].push_back(bin.gamma_x_stderr());

					data[++col_i].push_back(value_of(bin.model_delta_Sigma_t()));
					data[++col_i].push_back(bin.model_gamma_t());

					data[++col_i].push_back(value_of(bin.model_1h_delta_Sigma_t()));
					data[++col_i].push_back(bin.model_1h_gamma_t());

					data[++col_i].push_back(value_of(bin.model_offset_delta_Sigma_t()));
					data[++col_i].push_back(bin.model_offset_gamma_t());

					data[++col_i].push_back(value_of(bin.magf_R_mean()));
					data[++col_i].push_back(value_of(bin.magf_lens_m_mean()));
					data[++col_i].push_back(bin.magf_lens_z_mean());
					data[++col_i].push_back(bin.magf_lens_mag_mean());

					data[++col_i].push_back(bin.magf_source_z_mean());

					data[++col_i].push_back(bin.magf_num_lenses());
					data[++col_i].push_back(value_of(bin.area()));

					data[++col_i].push_back(value_of(bin.magf_sigma_crit()));

					data[++col_i].push_back(bin.mu_hat());
					data[++col_i].push_back(bin.mu_stderr());
					data[++col_i].push_back(bin.kappa());
					data[++col_i].push_back(bin.kappa_stderr());
					data[++col_i].push_back(value_of(bin.Sigma()));
					data[++col_i].push_back(value_of(bin.Sigma_stderr()));

					data[++col_i].push_back(bin.model_mu());
					data[++col_i].push_back(bin.model_kappa());
					data[++col_i].push_back(value_of(bin.model_Sigma()));

					data[++col_i].push_back(bin.model_1h_mu());
					data[++col_i].push_back(bin.model_1h_kappa());
					data[++col_i].push_back(value_of(bin.model_1h_Sigma()));

					data[++col_i].push_back(bin.model_offset_mu());
					data[++col_i].push_back(bin.model_offset_kappa());
					data[++col_i].push_back(value_of(bin.model_offset_Sigma()));
				}
			}
		}
	}

	assert(ssize(data.back())==ssize(data.front())); // Check we didn't miss a column to add to the table

	table_map_t<flt_type> table_map = get_table_after_unitconv(make_table_map(data,header),u_map);

	// And now print it out
	print_table_map<flt_type>(out,table_map);

}