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 lemunozm committed Aug 2, 2019
1 parent b830e26 commit 3aacd60
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 0 deletions.
101 changes: 101 additions & 0 deletions include/dds/core/xtypes/CollectionTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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/detail/CollectionTypes.hpp>

namespace dds{
namespace core{
namespace xtypes{


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

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


typedef TCollectionType<detail::CollectionType> CollectionType;




template <typename DELEGATE>
class TMapType : public TCollectionType<DELEGATE>
{
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);
public:
const DynamicType& key_type();
const DynamicType& value_type();
};

template <typename DELEGATE>
class TSequenceType : public TCollectionType<DELEGATE>
{
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);
public:
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>
class TStringType;

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

#endif /* OMG_DDS_CORE_XTYPES_COLLECTION_TYPES_HPP_ */
57 changes: 57 additions & 0 deletions include/dds/core/xtypes/UnionCase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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
*/

/*
* TUnionCase.hpp
*
* Created on: Oct 24, 2012
* Author: angelo
*/

#ifndef OMG_DDS_CORE_XTYPES_UNION_CASE_HPP_
#define OMG_DDS_CORE_XTYPES_UNION_CASE_HPP_

#include <dds/core/Reference.hpp>
#include <dds/core/xtypes/MemberType.hpp>
#include <dds/core/xtypes/detail/UnionCase.hpp>

namespace dds{
namespace core{
namespace xtypes{

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

};

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_ */
88 changes: 88 additions & 0 deletions include/dds/core/xtypes/UnionType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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_

#include <dds/core/xtypes/DynamicType.hpp>
#include <dds/core/xtypes/UnionCase.hpp>
#include <dds/core/xtypes/PrimitiveTypes.hpp>
#include <dds/core/xtypes/detail/UnionType.hpp>
#include <vector>

namespace dds{
namespace core{
namespace xtypes{

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

template <typename T, typename DELEGATE>
class TUnionType : public TDynamicType< DELEGATE >
{
public:

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

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

TUnionType(
const std::string& name,
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 std::vector<Annotation>& annotations() const;

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

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

};

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 3aacd60

Please sign in to comment.