From 5e5a4c9daa1bc9da5ee0d6121e51e067d9017037 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 17 Apr 2010 05:00:18 +0000 Subject: Copy trunk into gcc-4.4 branch before porting to gcc-4.5. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@935127 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp | 178 +++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp (limited to 'sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp') diff --git a/sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp b/sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp new file mode 100644 index 0000000000..531144e219 --- /dev/null +++ b/sca-cpp/branches/gcc-4.4/modules/scdl/scdl.hpp @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_scdl_hpp +#define tuscany_scdl_hpp + +/** + * SCDL read functions. + */ + +#include "string.hpp" +#include "list.hpp" +#include "value.hpp" +#include "monad.hpp" +#include "xml.hpp" + +namespace tuscany { +namespace scdl { + +/** + * Returns a list of components in a composite. + */ +const list components(const value& l) { + const list cs = elementChildren("composite", l); + if (isNil(cs)) + return cs; + return elementChildren("component", car(cs)); +} + +/** + * Returns the name of a component, service or reference. + */ +const value name(const value& l) { + return attributeValue("name", l); +} + +/** + * Convert a list of elements to a name -> element assoc list. + */ +const list nameToElementAssoc(const list& l) { + if (isNil(l)) + return l; + const value e(car(l)); + return cons(mklist(name(e), e), nameToElementAssoc(cdr(l))); +} + +/** + * Returns the scdl declaration with the given name. + */ +struct filterName { + const value n; + filterName(const value& n) : n(n) { + } + const bool operator()(const value& v) const { + return name(v) == n; + } +}; + +const value named(const value& name, const value& l) { + const list c = filter(filterName(name), l); + if (isNil(c)) + return value(); + return car(c); +} + +/** + * Returns the implementation of a component. + */ +const bool filterImplementation(const value& v) { + return isElement(v) && contains(string(cadr(v)), "implementation."); +} + +const value implementation(const value& l) { + const list n = filter(filterImplementation, l); + if (isNil(n)) + return value(); + return car(n); +} + +/** + * Returns the URI of a service, reference or implementation. + */ +const value uri(const value& l) { + return attributeValue("uri", l); +} + +/** + * Returns a list of services in a component. + */ +const list services(const value& l) { + return elementChildren("service", l); +} + +/** + * Returns a list of references in a component. + */ +const list references(const value& l) { + return elementChildren("reference", l); +} + +/** + * Returns the target of a reference. + */ +const value target(const value& l) { + return attributeValue("target", l); +} + +/** + * Convert a list of references to a reference name -> target assoc list. + */ +const list referenceToTargetAssoc(const list& r) { + if (isNil(r)) + return r; + const value ref(car(r)); + return cons(mklist(scdl::name(ref), scdl::target(ref)), referenceToTargetAssoc(cdr(r))); +} + +/** + * Returns a list of bindings in a service or reference. + */ +const bool filterBinding(const value& v) { + return isElement(v) && contains(string(cadr(v)), "binding."); +} + +const list bindings(const value& l) { + return filter(filterBinding, l); +} + +/** + * Returns a list of properties in a component. + */ +const list properties(const value& l) { + return elementChildren("property", l); +} + +/** + * Returns the type of an implementation. + */ +const value implementationType(const value& l) { + return elementName(l); +} + +/** + * Returns the type of a binding. + */ +const value bindingType(const value& l) { + return elementName(l); +} + +/** + * Returns the value of a property. + */ +const value propertyValue(const value& l) { + return elementValue(l); +} + +} +} + +#endif /* tuscany_scdl_hpp */ -- cgit v1.2.3