Skip to content

Commit

Permalink
added UnionCase, UnionType and CollectionTypes (#3)
Browse files Browse the repository at this point in the history
* added UnionCase, UnionType and CollectionTypes

* Update include/dds/core/xtypes/CollectionTypes.hpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* Update include/dds/core/xtypes/UnionCase.hpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* Update include/dds/core/xtypes/UnionCase.hpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* Update src/main.cpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* Update include/dds/core/xtypes/UnionCase.hpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* Update include/dds/core/xtypes/UnionCase.hpp

Co-Authored-By: Luis Enrique Muñoz Martín <lemunozm@gmail.com>

* replied to Pull Request notes
  • Loading branch information
franava authored and LauraMartin committed Aug 5, 2019
1 parent 9ce274c commit 8375e97
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 119 deletions.
125 changes: 98 additions & 27 deletions include/dds/core/xtypes/CollectionTypes.hpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,113 @@
/* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* All rights reserved.
*
* Licensed 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.
*/
/*
* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* Copyright 2019, Proyectos y Sistemas de Mantenimiento SL (eProsima).
*
* Licensed 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.
*/

#ifndef OMG_DDS_CORE_XTYPES_COLLECTION_TYPES_HPP_
#define OMG_DDS_CORE_XTYPES_COLLECTION_TYPES_HPP_

#include <dds/core/xtypes/TCollectionTypes.hpp>
#include <dds/core/xtypes/detail/CollectionTypes.hpp>

namespace dds
namespace dds{
namespace core{
namespace xtypes{


template<typename DELEGATE>
class TCollectionType : public TDynamicType<DELEGATE>
{
namespace core
public:
const uint32_t UNBOUNDED = 0xFFFFFFFF;

uint32_t bounds() const;

protected:
TCollectionType(
const std::string& name, TypeKind kind);
};


typedef TCollectionType<detail::CollectionType> CollectionType;

template<typename DELEGATE>
class TMapType : public TCollectionType<DELEGATE>
{
namespace xtypes
public:
/**
* Create an unbounded Map with the given key/value type.
*/
TMapType(
const DynamicType& key_type,
const DynamicType& value_type);

/**
* Create an bounded Map with the given key/value type.
*/
TMapType(
const DynamicType& key_type,
const DynamicType& value_type,
uint32_t bounds);

const DynamicType& key_type();

const DynamicType& value_type();
};

template<typename DELEGATE>
class TSequenceType : public TCollectionType<DELEGATE>
{
typedef TCollectionType<detail::CollectionType> CollectionType;
public:
/**
* Create an unbounded sequence for the given type.
*/
TSequenceType(
const DynamicType& type);

/**
* Create a bounded sequence for the given type.
*/
TSequenceType(
const DynamicType& type,
uint32_t bounds);

const DynamicType& key_type() const;
};

template<
typename CHAR_T,
template <typename C> class DELEGATE>
class TStringType : public TCollectionType<detail::CollectionType>
{
public:
TStringType(
uint32_t bounds);
};

typedef TMapType<detail::MapType> MapType;

typedef TSequenceType<detail::SequenceType> SequenceType;

template <typename CHAR_T, template <typename C> class DELEGATE = detail::StringType>
template<
typename CHAR_T,
template <typename C> class DELEGATE = detail::StringType>
class TStringType;
}
}
}

#endif /* OMG_DDS_CORE_XTYPES_COLLECTION_TYPES_HPP_ */
} //namespace xtypes
} //namespace core
} //namespace dds

#endif //OMG_DDS_CORE_XTYPES_COLLECTION_TYPES_HPP_
79 changes: 38 additions & 41 deletions include/dds/core/xtypes/UnionCase.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* All rights reserved.
*
* Licensed 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.
*/
/*
* TUnionCase.hpp
* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* Copyright 2019, Proyectos y Sistemas de Mantenimiento SL (eProsima).
*
* Created on: Oct 24, 2012
* Author: angelo
* Licensed 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
*/

#ifndef OMG_DDS_CORE_XTYPES_UNION_CASE_HPP_
Expand All @@ -29,31 +23,34 @@
#include <dds/core/xtypes/MemberType.hpp>
#include <dds/core/xtypes/detail/UnionCase.hpp>

/** @cond */
namespace dds
{
namespace core
{
namespace xtypes
{
template <typename T, template <typename Q> class DELEGATE = detail::UnionCase>
class UnionCase;
}
}
}
/** @endcond */

template <typename T, template <typename Q> class DELEGATE>
class dds::core::xtypes::UnionCase : public dds::core::Reference< DELEGATE<T> >
namespace dds{
namespace core{
namespace xtypes{

template<
typename T,
template <typename Q> class DELEGATE>
class TUnionCase : public Reference< DELEGATE<T> >
{
public:
// Nil case
UnionCase();
public:
UnionCase(T discriminator, const MemberType& member);
public:
TUnionCase();

TUnionCase(
T discriminator,
const MemberType& member);

T discriminator();

const MemberType& member();

};

#endif /* OMG_DDS_CORE_XTYPES_T_UNION_CASE_HPP_ */
template<typename T>
struct UnionCase : public TUnionCase <T, detail::UnionCase> {} ;

}//namespace xtypes
}//namespace core
}//namespace dds

#endif //OMG_DDS_CORE_XTYPES_T_UNION_CASE_HPP_
110 changes: 59 additions & 51 deletions include/dds/core/xtypes/UnionType.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* All rights reserved.
*
* Licensed 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.
*/
/*
* Copyright 2010, Object Management Group, Inc.
* Copyright 2010, PrismTech, Corp.
* Copyright 2010, Real-Time Innovations, Inc.
* Copyright 2019, Proyectos y Sistemas de Mantenimiento SL (eProsima).
*
* Licensed 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.
*/

#ifndef OMG_DDS_CORE_XTYPES_T_UNION_TYPE_HPP_
#define OMG_DDS_CORE_XTYPES_T_UNION_TYPE_HPP_

Expand All @@ -24,67 +26,73 @@
#include <dds/core/xtypes/detail/UnionType.hpp>
#include <vector>

namespace dds
{
namespace core
{
namespace xtypes
{
template <typename DELEGATE>
class TUnionForwardDeclaration;

template <typename T, template <typename Q> class DELEGATE = detail::UnionType >
class UnionType;
}
}
}
namespace dds{
namespace core{
namespace xtypes{

/**
* Declares a forward declaration for a union type.
*/
template <typename DELEGATE>
class dds::core::xtypes::TUnionForwardDeclaration : public dds::core::xtypes::DynamicType<DELEGATE>
template<typename DELEGATE>
class TUnionForwardDeclaration : public TDynamicType<DELEGATE>
{
public:
TUnionForwardDeclaration(const std::string& name);
TUnionForwardDeclaration(
const std::string& name);
};

template <typename T, typename DELEGATE>
class dds::core::xtypes::UnionType : public dds::core::xtypes::DynamicType<DELEGATE<T> >
template<
typename T,
typename DELEGATE>
class TUnionType : public TDynamicType< DELEGATE >
{
public:

UnionType(
TUnionType(
const std::string& name,
const TPrimitiveType<T>& discriminator_type,
const PrimitiveType<T>& discriminator_type,
const std::vector<UnionCase<T> >& cases);

UnionType(
TUnionType(
const std::string& name,
const TPrimitiveType<T>& discriminator_type,
const PrimitiveType<T>& discriminator_type,
const std::vector<UnionCase<T> >& cases,
const Annotation& annotation);

UnionType(
TUnionType(
const std::string& name,
const TPrimitiveType<T>& discriminator_type,
const PrimitiveType<T>& discriminator_type,
const std::vector<UnionCase<T> >& cases,
const std::vector<Annotation>& annotations);

public:

const std::vector<UnionCase<T> >& members() const;
const MemberType& member(uint32_t id) const;
const MemberType& member(const std::string& name) const;

const MemberType& member(
uint32_t id) const;

const MemberType& member(
const std::string& name) const;

const std::vector<Annotation>& annotations() const;

UnionType add_member(const UnionCase<T>& member) const;
UnionType remove_member(const UnionCase<T>& member) const;
TUnionType add_member(
const UnionCase<T>& member) const;

TUnionType remove_member(
const UnionCase<T>& member) const;

UnionType add_annotation(const Annotation& annotation) const;
UnionType remove_annotation(const Annotation& annotation) const;
TUnionType add_annotation(
const Annotation& annotation) const;

TUnionType remove_annotation(
const Annotation& annotation) const;

};

#endif /* OMG_DDS_CORE_XTYPES_T_STRUCT_TYPE_HPP_ */
typedef TUnionType <TypeKind_def::Type, DynamicType> UnionType ;

}//namespace xtypes
}//namespace core
}//namespace dds

#endif //OMG_DDS_CORE_XTYPES_T_STRUCT_TYPE_HPP_
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <dds/core/xtypes/DynamicType.hpp>
#include <dds/core/xtypes/MemberType.hpp>
#include <dds/core/xtypes/PrimitiveTypes.hpp>
#include <dds/core/xtypes/UnionCase.hpp>
#include <dds/core/xtypes/UnionType.hpp>
#include <dds/core/xtypes/CollectionTypes.hpp>

int main()
{
Expand Down

0 comments on commit 8375e97

Please sign in to comment.