Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
SliceLoader.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_SLICE_LOADER_H
4#define ICE_SLICE_LOADER_H
5
6#include "Config.h"
7#include "ValueF.h"
8
9#include <exception>
10#include <memory>
11#include <string_view>
12#include <vector>
13
14namespace Ice
15{
16 /// Creates class and exception instances from Slice type IDs.
17 /// @remark The implementation of newClassInstance and newExceptionInstance in the base class always returns
18 /// nullptr.
19 /// @headerfile Ice/Ice.h
20 class ICE_API SliceLoader
21 {
22 public:
23 virtual ~SliceLoader();
24
25 /// Creates an instance of a class mapped from a Slice class based on a Slice type ID.
26 /// @param typeId The Slice type ID or compact type ID.
27 /// @return A new instance of the class identified by @p typeId, or nullptr if the implementation cannot find
28 /// the corresponding class.
29 /// @throws MarshalException Thrown when the corresponding class was found but its instantiation failed.
30 [[nodiscard]] virtual ValuePtr newClassInstance(std::string_view typeId) const;
31
32 /// Creates an instance of a class mapped from a Slice exception based on a Slice type ID.
33 /// @param typeId The Slice type ID.
34 /// @return A new instance of the exception class identified by @p typeId, or nullptr if the implementation
35 /// cannot find the corresponding class.
36 /// @throws MarshalException Thrown when the corresponding class was found but its instantiation failed.
37 [[nodiscard]] virtual std::exception_ptr newExceptionInstance(std::string_view typeId) const;
38
39 protected:
40 SliceLoader() = default;
41 };
42
43 /// A shared pointer to a SliceLoader.
44 using SliceLoaderPtr = std::shared_ptr<SliceLoader>;
45
46 /// Implements SliceLoader by combining multiple SliceLoader instances.
47 class ICE_API CompositeSliceLoader final : public SliceLoader
48 {
49 public:
51
52 /// Adds a SliceLoader instance to this CompositeSliceLoader.
53 /// @param loader The SliceLoader to add.
54 void add(SliceLoaderPtr loader) noexcept;
55
56 [[nodiscard]] ValuePtr newClassInstance(std::string_view typeId) const final;
57 [[nodiscard]] std::exception_ptr newExceptionInstance(std::string_view typeId) const final;
58
59 private:
60 std::vector<SliceLoaderPtr> _loaders;
61 };
62
63 /// A shared pointer to a CompositeSliceLoaderPtr.
64 using CompositeSliceLoaderPtr = std::shared_ptr<CompositeSliceLoader>;
65}
66
67#endif
ValuePtr newClassInstance(std::string_view typeId) const final
Creates an instance of a class mapped from a Slice class based on a Slice type ID.
std::exception_ptr newExceptionInstance(std::string_view typeId) const final
Creates an instance of a class mapped from a Slice exception based on a Slice type ID.
void add(SliceLoaderPtr loader) noexcept
Adds a SliceLoader instance to this CompositeSliceLoader.
Implements SliceLoader by combining multiple SliceLoader instances.
Definition SliceLoader.h:48
virtual std::exception_ptr newExceptionInstance(std::string_view typeId) const
Creates an instance of a class mapped from a Slice exception based on a Slice type ID.
virtual ValuePtr newClassInstance(std::string_view typeId) const
Creates an instance of a class mapped from a Slice class based on a Slice type ID.
std::shared_ptr< SliceLoader > SliceLoaderPtr
A shared pointer to a SliceLoader.
Definition SliceLoader.h:44
std::shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition ValueF.h:13
std::shared_ptr< CompositeSliceLoader > CompositeSliceLoaderPtr
A shared pointer to a CompositeSliceLoaderPtr.
Definition SliceLoader.h:64
The Ice RPC framework.
Definition SampleEvent.h:59