コード例 #1
0
void generalization_expander::
populate_generalizable_properties(const type_group& tg,
    const std::unordered_set<std::string>& parent_ids,
    intermediate_model& im) const {

    for (auto& pair : im.objects()) {
        const auto& id(pair.first);
        BOOST_LOG_SEV(lg, debug) << "Processing type: " << id;

        auto& o(pair.second);

        /*
         * We are a child if we have a parent (double-bang by design).
         */
         o.is_child(!!o.parent());

         /*
          * We are a parent if someone else declared us as their parent.
          */
         const auto i(parent_ids.find(id));
         o.is_parent(i != parent_ids.end());

         /*
          * Handle the case where the user decided to override final.
          */
         const auto is_final(make_is_final(tg, o.annotation()));
         if (is_final) {
             if (*is_final && o.is_parent()) {
                 BOOST_LOG_SEV(lg, error) << incompatible_is_final << id;
                 BOOST_THROW_EXCEPTION(
                     expansion_error(incompatible_is_final + id));
             }
             o.is_final(*is_final);
         } else {
             /*
              * By default we setup all childless types and leaf types
              * as final, unless the user tells us otherwise.
              */
             o.is_final(!o.is_parent());
         }

         /*
          * We are in an inheritance (generalisation) relationship if
          * we are either a parent or a child (or both).
          */
         o.in_inheritance_relationship(o.is_parent() || o.is_child());

         /*
          * We are a leaf if we are not a parent but we are a child.
          */
         o.is_leaf(!o.is_parent() && o.is_child());

         if (!o.is_leaf())
             continue;

         populate_properties_up_the_generalization_tree(tg, o.name(), im, o);
    }
}
コード例 #2
0
void generalization_expander::populate_properties_up_the_generalization_tree(
    const type_group& tg, const yarn::name& leaf,
    intermediate_model& im, yarn::object& o) const {

    /*
     * Add the leaf to all nodes of the tree except for the leaf node
     * itself.
     */
    if (!o.is_leaf())
        o.leaves().push_back(leaf);

    /*
     * If we do not have a parent we have reached the top of the
     * generalisation tree.
     */
    if (!o.parent()) {
        /*
         * If the leaf name belongs to the target model, add it to
         * the model's list of leaves. Ignore non-target leaves.
         */
        const auto& ll(leaf.location());
        const auto& ml(im.name().location());
        if (ll.model_modules() == ml.model_modules())
            im.leaves().insert(leaf);

        return;
    }

    const auto pid(o.parent()->id());
    auto j(im.objects().find(pid));
    if (j == im.objects().end()) {
        BOOST_LOG_SEV(lg, error) << parent_not_found << pid;
        BOOST_THROW_EXCEPTION(expansion_error(parent_not_found + pid));
    }

    auto& parent(j->second);
    populate_properties_up_the_generalization_tree(tg, leaf, im, parent);

    if (!parent.parent()) {
        /*
         * If our parent does not have a parent then it is our root
         * parent.
         */
        o.root_parent(parent.name());
    } else {
        /*
         * On all other cases, inherit the root parent properties for
         * our direct parent; these would have been populated from the
         * root parent as per above.
         */
        o.root_parent(parent.root_parent());
    }
}
コード例 #3
0
void file_path_and_guard_expander::
expand(const formatters::repository& frp, const locator& l, model& fm) const {

    const auto safba(frp.stock_artefact_formatters_by_archetype());
    for (auto& pair : fm.formattables()) {
        const auto id(pair.first);
        auto& formattable(pair.second);

        /*
         * It doesn't really matter which segment we choose here since
         * they are both mapped to the same name.
         */
        const auto& e(*formattable.master_segment());
        const auto n(e.name());
        auto& eprops(formattable.element_properties());

        /*
         * Go thorough all the artefact properties and, for each, find
         * the associated formatter.
         */
        for (auto& pair : eprops.artefact_properties()) {
            const auto arch(pair.first);
            auto& art_props(pair.second);

            const auto i(safba.find(arch));
            if (i == safba.end()) {
                BOOST_LOG_SEV(lg, error) << missing_archetype << arch;
                BOOST_THROW_EXCEPTION(
                    expansion_error(missing_archetype + arch));
            }

            /*
             * Ask the formatter to generate the full path for the
             * artefact.
             */
            const auto& fmt(i->second);
            art_props.file_path(fmt->full_path(l, n));

            /*
             * If the formatter supports inclusion, we need to compute
             * the header guard as well.
             */
            const auto ns(formatters::inclusion_support_types::not_supported);
            if (fmt->inclusion_support_type() != ns) {
                const auto ip(fmt->inclusion_path(l, n));
                art_props.header_guard(to_header_guard(ip));
            }
        }
    }
}
コード例 #4
0
ファイル: modules_expander.cpp プロジェクト: Niam99/dogen
inline void update_containing_module(model& m,
    AssociativeContainerOfContainable& c) {
    for (auto& pair : c) {
        auto& s(pair.second);
        s.containing_module(containing_module(m, s.name()));

        if (!s.containing_module())
            continue;

        auto i(m.modules().find(*s.containing_module()));
        if (i == m.modules().end()) {
            const auto sn(s.containing_module()->simple());
            BOOST_LOG_SEV(lg, error) << missing_module << sn;
            BOOST_THROW_EXCEPTION(expansion_error(missing_module + sn));
        }

        BOOST_LOG_SEV(lg, debug) << "Adding type to module. Type: '"
                                 << s.name().qualified()
                                 << "' Module: '" << i->first.qualified();
        i->second.members().push_back(s.name());
    }
}
コード例 #5
0
ファイル: fftsub.cpp プロジェクト: SpiritsThief/mifit
void read_sf(float *x, int nx, int ny, int nz, float scale, float temp, CREFL *refl, int nrefl, int usepsi)
{
    int count, p, q, r, used;
    float dsq, fh, fk, fl, s, t;
    fcomplex f, /*ww,*/ fsym;
    int nsymop = 0;
    char buf[100];

    int i, k;         /* k = 3, quadratic splines */
    double psi;
    int /*n_i[3],*/ N[4];

    k = usepsi + 2;
    N[1] = 2*nx;
    N[2] = ny;
    N[3] = nz;

    /*      nextf is a logical function used to read structure factors.
     *      If nextf is true, the arguments have returned the indices and
     *      value of the next structure factor in the input list.
     *      If nextf is false, there are no more structure factors.
     *
     *      xpnd is a logical function used to apply symmetry relations
     *      to structure factors.  If xpnd is true, a symmetry operator
     *      has been applied and the indices and value of the related
     *      structure factor have been returned.  If xpnd is false, there
     *      are no more symmetry operators to apply for this hkl.
     */
    s = (float)scale;
    t = (float)(temp/4.0);
    used = count = 0;

    while (nextf(hin, &f, count, refl, nrefl))
    {
        count++;
        fh = (float)hin[0];
        fk = (float)hin[1];
        fl = (float)hin[2];
        dsq = fh*(fh*g11+fk*g12+fl*g13) + fk*(fk*g22+fl*g23) + g33*fl*fl;


        if ((dsq <= dsqmax) && (dsq >= dsqmin))
        {
            used++;
            f.re = (float)(s*exp(-t*dsq)*f.re);
            f.im = (float)(s*exp(-t*dsq)*f.im);
            if (usepsi)
            {
                psi = 1.;
                for (i = 0; i < 3; ++i)
                {
                    psi *= psi_(hin[i], N[i + 1], k);
                }
                f.re /= (float)psi;
                f.im /= (float)psi;
            }

            /*
             *                        the following is a complex exponent
             *                        it is different from the above which is correct
             *			  summer-1990
             *			cexp (&ww, -t*dsq);
             *			c_mul(f,ww,f);
             *			f.re *= s;
             *			f.im *= s;
             */
            nsymop = 0;
            while (xpnd(hin, hout, &f, &fsym, nsymop))
            {
                p = hout[0];
                if (p < 0)
                {
                    sprintf(buf, "Error in symmetry expansion\n");
                    Logger::log(buf);
                    sprintf(buf, "position %d hin= %d %d %d hout= %d %d %d\n",
                            nsymop+1, hin[0], hin[1], hin[2], hout[0], hout[1], hout[2]);
                    Logger::log(buf);
                    return;
                }
                q = hout[1];
                r = hout[2];
                if (p >= nx)
                {
                    if (nx != 1)
                    {
                        expansion_error(nsymop);
                    }
                    return;
                }
                else
                if (abs(q) >= ny)
                {
                    if (ny != 1)
                    {
                        expansion_error(nsymop);
                    }
                    return;
                }
                else
                if (abs(r) >= nz)
                {
                    if (nz != 1)
                    {
                        expansion_error(nsymop);
                    }
                    return;
                }
                else
                {
                    if (q < 0)
                    {
                        q += ny;
                    }
                    if (r < 0)
                    {
                        r += nz;
                    }
                    x[2*(r*nx*ny + q*nx + p)] = fsym.re;
                    x[2*(r*nx*ny + q*nx + p)+1] = fsym.im;
                    if (p <= 0)
                    {

                        /*      Fill in the 0,-k,-l reflections by conjugate symmetry */

                        q = -hout[1];
                        r = -hout[2];
                        if (q < 0)
                        {
                            q += ny;
                        }
                        if (r < 0)
                        {
                            r += nz;
                        }
                        x[2*(r*nx*ny + q*nx)] =  fsym.re;
                        x[2*(r*nx*ny + q*nx)+1] = -fsym.im;
                    }
                }
                nsymop++;
            }
        }
    }
    sprintf(buf, "  %d structure factors used out of %d in input.\n\n", used, count);
    Logger::log(buf);
}