Skip to content

Commit

Permalink
removed redundent requires and modified doxygen file
Browse files Browse the repository at this point in the history
Took 24 minutes
  • Loading branch information
kagurazaka-ayano committed Feb 1, 2024
1 parent 46a8fc4 commit ffaaf59
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 25 deletions.
12 changes: 6 additions & 6 deletions doc/config
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "Message Queue"
PROJECT_NAME = "KawaiiMQ"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand All @@ -54,7 +54,7 @@ PROJECT_NUMBER =
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF = "A simple message queue implementation"
PROJECT_BRIEF = "A simple generic message queue implementation"

# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
Expand Down Expand Up @@ -1047,7 +1047,7 @@ RECURSIVE = YES
# Note that relative paths are relative to the directory from which doxygen is
# run.

EXCLUDE = ./dependencies ./scripts ./build ./cmake-build-debug
EXCLUDE = ./dependencies ./scripts ./src/test

# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
Expand All @@ -1063,7 +1063,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*

EXCLUDE_PATTERNS =
EXCLUDE_PATTERNS = */cmake-build-*/* */build/*

# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the
Expand Down Expand Up @@ -1768,7 +1768,7 @@ FORMULA_MACROFILE =
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

USE_MATHJAX = NO
USE_MATHJAX = YES

# With MATHJAX_VERSION it is possible to specify the MathJax version to be used.
# Note that the different versions of MathJax have different requirements with
Expand Down Expand Up @@ -1976,7 +1976,7 @@ LATEX_MAKEINDEX_CMD = makeindex
# The default value is: NO.
# This tag requires that the tag GENERATE_LATEX is set to YES.

COMPACT_LATEX = NO
COMPACT_LATEX = YES

# The PAPER_TYPE tag can be used to set the paper type that is used by the
# printer.
Expand Down
94 changes: 79 additions & 15 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,103 @@

> All examples assume you included the header file `KawaiiMQ/kawaiiMQ.h`
## 1. Creating a message queue

```c++
## Usage example

To use a message queue, you need to create a queue and a topic.

```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
```
## 2. Relating a message queue with a topic
Then, you need to relate the queue with the topic.
```c++
```cpp
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
```

KawaiiMQ::MessageQueue queue;
After that, you can create a producer and subscribe to the topic.

```cpp
KawaiiMQ::Producer producer;
producer.subscribe(topic);
```

To make a message, use the `makeMessage` function.

```cpp
auto message = KawaiiMQ::makeMessage(0);
```

Then, you can publish the message.

```cpp
producer.publishMessage(topic, message);
```

To consume the message, you need to create a consumer and fetch the message.

```cpp
auto consumer = KawaiiMQ::Consumer({topic});
auto messages = consumer.fetchMessage();
```
The return value is a map of topics and messages. You can use the `getMessage` function to get the message.
```cpp
std::cout << getMessage<int>(messages[topic][0]) << std::endl;
```

You can of course only publish message on a single topic or consume messages from a single topic.

```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
KawaiiMQ::Producer producer;
producer.subscribe(topic);
auto message = KawaiiMQ::makeMessage(0);
producer.publishMessage(topic, message);
auto consumer = KawaiiMQ::Consumer({topic});
consumer.subscribe(topic);
auto messages = consumer.fetchSingleTopic(topic);
std::cout << getMessage<int>(messages[0]) << std::endl;
```
## More examples
### Creating a message queue
```cpp
KawaiiMQ::Queue queue;
```

## 3. Publishing a message
### Relating a message queue with a topic

```cpp

KawaiiMQ::MessageQueue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);

```
```c++
### Publishing a message
```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
KawaiiMQ::Producer producer;
producer.subscribe(topic);
auto message = KawaiiMQ::makeMessage(0);
producer.publishMessage(topic, message);
```

## 4. Consuming a message
### Consuming a message

```c++
```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
Expand All @@ -49,20 +113,20 @@ std::cout << getMessage<int>(messages[topic][0]) << std::endl;
The output will be `0`.
## 5. Unrelate a message queue with a topic
### Unrelate a message queue with a topic
```c++
```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
KawaiiMQ::MessageQueueManager::Instance()->unrelate(topic, queue);
```

> Note this method will wait till the queue is empty before unrelating the queue with the topic.
>
## 6. Unsubscribe a topic, both consumer and producer
```c++
### Unsubscribe a topic, both consumer and producer

```cpp
KawaiiMQ::Queue queue;
KawaiiMQ::Topic topic("topic1");
KawaiiMQ::MessageQueueManager::Instance()->relate(topic, queue);
Expand Down
2 changes: 1 addition & 1 deletion include/KawaiiMQ/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Exceptions.h
* @author ayano
* @date 1/29/24
* @brief
* @brief Exceptions for KawaiiMQ
*/

#ifndef KAWAIIMQ_EXCEPTIONS_H
Expand Down
3 changes: 0 additions & 3 deletions include/KawaiiMQ/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace KawaiiMQ {
* @tparam T type of message content
*/
template<typename T>
requires std::is_convertible_v<T, std::byte> || std::is_fundamental_v<T>
class Message : public MessageData {
public:
explicit Message(T content) : content(std::move(content)) {}
Expand Down Expand Up @@ -54,7 +53,6 @@ namespace KawaiiMQ {
* @exception TypeException Will throw if the type of the message is not the same as the type you are expecting
*/
template<typename T>
requires std::is_convertible_v<T, std::byte> || std::is_fundamental_v<T>
T getMessage(std::shared_ptr<MessageData> in) {
std::shared_ptr<Message<T>> tmp = std::dynamic_pointer_cast<Message<T>>(in);
if (tmp != nullptr) {
Expand All @@ -71,7 +69,6 @@ namespace KawaiiMQ {
* @return message shared ptr
*/
template<typename T>
requires std::is_convertible_v<T, std::byte> || std::is_fundamental_v<T>
std::shared_ptr<Message<T>> makeMessage(T content) {
auto msg = std::make_shared<Message<T>>(content);
return msg;
Expand Down

0 comments on commit ffaaf59

Please sign in to comment.