How to show collaboration diagram in Doxygen only for objects/classes related to a specific group tag - scripting

I have created a markdown file as part of a c++ project intended to describe a specific functionality in the project.
In this markdown file, I have defined a group using '\defgroup myGroup Explanation of group'
I've also tagged all objects related to this group by including the \ingroup tag for the group in question.
The question is on how to render UML diagrams only for the context for this specific group in the detailed section of the module for this functionality?
I have read through the doxygen documentation and have not found any information on how to define the group context boundaries for rendering a specific group of objects/classes using graphviz.
#include <string>
#include <iostream>
/**
* #ingroup markingsgroup
* #brief This class defines a base class
*/
class BaseClass
{
public:
BaseClass() {}
virtual bool getStatus(void) const = 0;
virtual void setStatus(const bool status) = 0;
};
/**
* #ingroup markingsgroup
* This class defines Class1
*/
class Class1 : public BaseClass
{
public:
Class1() {}
bool getStatus() const
{
return m_status;
}
void setStatus(const bool status)
{
m_status = status;
}
private:
bool m_status;
};
/**
* #ingroup markingsgroup
* This class defines a Class2
*/
class Class2 : public BaseClass
{
public:
Class2() {}
bool getStatus() const
{
return m_status;
}
void setStatus(const bool status)
{
m_status = status;
}
private:
bool m_status;
};
/**
* #ingroup markingsgroup
* #brief Main function
*/
int main(int argc, char *argv[])
{
Class1 myClass1;
Class2 myClass2;
myClass1.setStatus(true);
myClass2.setStatus(myClass1.getStatus());
std::cout << "Class1: " << myClass1.getStatus() << " Class2: " << myClass2.getStatus() << std::endl;
}
Doxyfile changes form default:
PROJECT_NAME = "My Project"
PROJECT_NAME = "Marking Project"
OUTPUT_DIRECTORY = /home/fblidner/doxgentest/documentation
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_PACKAGE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_METHODS = YES
INPUT = project
RECURSIVE = YES
GENERATE_XML = YES
XML_PROGRAMLISTING = NO
UML_LOOK = YES
CALLER_GRAPH = YES
PLANTUML_JAR_PATH = /home/fblidner/puppet-manifests/devvm/files/generated/plantuml.jar
MAX_DOT_GRAPH_DEPTH = 10
HAVE_DOT = YES
CALLER_GRAPH = YES

Related

Arduino - passing values by reference from lamda to singleton

Hello i am bigginer in programing and i have specific problem.
I have been learning a new ways to write a code in small Arduino project.
that project have multiple objects like distance measuring Senzor, led diods , temperature senzor, etc. And all this objects have its own menu where you can, for example, start a calibration or just get values.
What i need is singleton class that has a function enter_esc() that need a int (*funct)() parameter basically function pointer.
That enter_esc(int (*funct)()) function just looping function until you press escape pin which is defined.
function Calibration() have inside some private: object data types like value or cali_value.
so i tried to insert function Calibration() right into enter_esc(Calibration) but it won't compile becouse i didnt pass that vlaues by reference or copy.
but what i found is lambda.
i made a lamda similar to a Calibration() function and i passed values by reference &{//domething;}
but i had to use enter_esc(std::function<int()>& funct) whitch is only int C++ standard library and not in Arduino C/C++ so my qestion is:
[is there some way how to pass values by reference by using lambda to a singleton class in Arduino ?]
(i konw it can be done differently but like i said i want to learn some new ways to program, also if you have some different way to make it i will by very happy to see it)
10Q for your time :)
//Class.h
#pragma once
class events {
private:
static events e_instance;
int p_menu, p_enter, p_esc, p_up, p_down;
int menuValue;
events();
public:
events(const events&) = delete;
static events& Get();
int ArrowUpDown(int maxVal);
int ArrowUpDown(int p_up, int p_down, int maxVal);
int enter_esc(const std::function<int()>& funct);
};
events events::e_instance;
class deviceBase : public Printables
{
public:
const char* a_pin;
int d_pin;
String type;
String deviceName;
bool inUse;
int actualCount;
public:
String getType() override;
int getActualCount() override;
String getName() override;
String getInUse() override;
};
class senzor : public deviceBase
{
private:
int Value;
int triggValue;
public:
int p_triggValue = 10;
static int allSenzors;
friend events;
senzor();
~senzor();
public:
int getValue();
int Calibration();
void changeTriggVal(int x);
void Reset();
void nullCalibration();
void Menu(int x);
void setName(String deviceName);
void setInUse(bool x);
int getPin();
};
int senzor::allSenzors = 0;
if you have some good advice to my code writing i will be also very glad
//Class.cpp
#include <iostream>
#include <string>
#include <functional>
#define LOG(x) std::cout << x << std::endl;
#define PINMENU 12
#define PINENTER 8
#define PINESC 9
#define PINUP 11
#define PINDOWN 13
using String = std::string;
struct Printables
{
virtual String getType() = 0;
virtual int getActualCount() = 0; ;
virtual String getName() = 0;
virtual String getInUse() = 0;
};
#include "Class.h"
events& events::Get() {
return e_instance;
}
int events::ArrowUpDown(int maxVal) {
if (maxVal) {
menuValue = menuValue < maxVal ? menuValue++ : menuValue;
}
if (maxVal) {
menuValue = menuValue > 0 ? menuValue-- : menuValue;
}
return menuValue;
}
int events::enter_esc(const std::function<int()>&funct) {
if (1) {
while (!p_esc) {
auto f = funct;
}
}
return 1;
}
int events::ArrowUpDown(int p_up, int p_down, int maxVal) { return 666; }
events::events() {};
String deviceBase::getType() { return type; }
int deviceBase::getActualCount() { return actualCount; }
String deviceBase::getName() { return deviceName; }
String deviceBase::getInUse() {
String Status;
Status = inUse == 1 ? "Active" : "Deactive";
return Status;
}
senzor::senzor() : Value(0), triggValue(1) {
a_pin = "xx";
type = "[SENZOR]";
deviceName = "[UNKNOWN]";
inUse = 0;
allSenzors++;
actualCount = allSenzors;
a_pin = 0;
}
senzor::~senzor() {
allSenzors = 0;
}
int senzor::getValue() {
Value = 4;
return Value;
}
int senzor::Calibration() {
triggValue = triggValue < getValue() ? getValue() : triggValue;
p_triggValue = triggValue;
return p_triggValue;
}
void senzor::changeTriggVal(int x) {
p_triggValue = x;
}
void senzor::Reset() {
p_triggValue = triggValue;
}
void senzor::nullCalibration() {
triggValue = 1;
}
void senzor::setName(String deviceName) {
this->deviceName = deviceName;
}
void senzor::setInUse(bool x) {
inUse = x;
}
int senzor::getPin() {
return 4;
}
int printsss() {
return 1;
}
////////////////////////////////this what i was writing about//////////////////////////////
void senzor::Menu(int x) {
events::Get().enter_esc([&]() { triggValue = triggValue < getValue() ? getValue() : triggValue;
p_triggValue = triggValue;
return p_triggValue; });
}
but if i use lambda in arduino with enter_esc(int (*funct)()) i get this kind of error
no matching function for call to 'events::enter_esc(senzor::Menu(int)::<lambda()>)'

SystemC - How can I get the module name to which sc_signal connected?

I'd like to print out the name of sc_module to which sc_signal connected.
How can I get the module name, "module_a" in the following code, from "sig_out"?
#include "systemc.h"
class sig_if : virtual public sc_interface
{
};
class my_sig : public sc_module, public sig_if
{
public:
my_sig(sc_module_name nm) : sc_module(nm)
{
}
};
SC_MODULE(test_module)
{
sc_port<sig_if> out;
SC_CTOR(test_module)
{
}
};
int sc_main(int argc, char* argv[]) {
test_module module_a("module_a");
my_sig sig_out("sig_out");
module_a.out(sig_out);
// std::cout << sig_out.get_parent() << std::endl;
sc_start();
return 0;
}
You could override sc_interface::register_port() in the my_sig class to save a reference to the bound port. The parent of the bound port is the module that contains the port.
#include <iostream>
#include <cassert>
#include "systemc.h"
class sig_if : virtual public sc_interface
{
};
class my_sig : public sc_module, public sig_if
{
public:
my_sig(sc_module_name nm) : sc_module(nm), bound_port(NULL)
{
}
void register_port(sc_port_base& port, const char*) {
bound_port = &port;
}
sc_object* get_bound_module() const {
assert(bound_port);
return bound_port->get_parent_object();
};
sc_port_base* bound_port;
};
SC_MODULE(test_module)
{
sc_port<sig_if> out;
SC_CTOR(test_module)
{
}
};
int sc_main(int argc, char* argv[]) {
test_module module_a("module_a");
my_sig sig_out("sig_out");
module_a.out(sig_out);
sc_start(0, SC_NS);
std::cout << sig_out.get_bound_module()->name() << std::endl;
return 0;
}
The above code prints the name of module_a. Note that sig::get_bound_module() can only be called after elaboration, that is, after sc_start() has been called, because sc_interface::register_port() is only called during elaboration.

Qml define custom property group [duplicate]

This question already has answers here:
How to create grouped/nested properties?
(3 answers)
Closed 7 years ago.
How can I define custom property groups in qml, equal to the anchors property?
Example usage:
Item {
anchors {
leftMargin: 5
rightMargin: 5
}
}
I'm afraid this is not as simple as you are thinking it might be.
As far as I know, you have two options:
1.- Follow the recommendation you will see in the link provided by #BaCaRoZzo and implement your own object type.
2.- Write a more complex QML type in C++ and use it in your QML file. More or less the idea pointed out by #folibis. Example:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include "customitem.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<CustomItem>("CustomItem", 1,0, "CustomItem");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
customitem.h
#ifndef CUSTOMITEM_H
#define CUSTOMITEM_H
#include <QObject>
class CustomItem: public QObject
{
Q_OBJECT
/*
* Any property that is writable should have an associated NOTIFY signal.
* Ref: http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-properties
*/
Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
public:
CustomItem(QObject *parent = 0);
int x() const;
void setX(int);
int y() const;
void setY(int);
private:
int m_x;
int m_y;
signals:
void xChanged();
void yChanged();
public slots:
};
#endif // CUSTOMITEM_H
customitem.cpp
#include "customitem.h"
CustomItem::CustomItem(QObject *parent)
: QObject(parent), m_x(0), m_y(0)
{
}
int CustomItem::x() const
{
return m_x;
}
void CustomItem::setX(int x)
{
m_x = x;
}
int CustomItem::y() const
{
return m_y;
}
void CustomItem::setY(int y)
{
m_y = y;
}
main.qml
import QtQuick 2.5
import QtQuick.Window 2.2
import CustomItem 1.0
Window {
visible: true
CustomItem {
id: customItem
x: 50
y: 50
}
Rectangle {
id: rect
x: customItem.x
y: customItem.y
width: 100; height: 100
color: "red"
}
}

serialize/deserialize user defined class variable?

Suppose I have two classes:
class1 {
int m_i;
std::string m_s;
};
class2 {
int m_i2;
class1 *m_ptr;
};
Now, I want to send a class2 variable over network, and want to use any of the libraries that does serialization.(Protocol-buffers, Thrift, MessagePack..)
Which one can I use?(note the class1* m_ptr)
You could use thrift for this.
the definition would look something like
struct class1 {
1: required i32 m_i;
2: required string m_s;
}
struct class2 {
1: required i32 m_i2;
2: optional class1 m_ptr;
}
You would like to read this excellent guide
http://diwakergupta.github.com/thrift-missing-guide/
and to get clarity on concern about the "pointer" issue that you mentioned in the question,read the section on "How are nested structs initialized?" in the above guide.
Using google protocol buffers, you would need a .proto file (say test.proto) like:
package serialisation; // puts this in namespace serialisation
message class1 {
required int32 m_i = 1;
required bytes m_s = 2;
}
message class2 {
required int32 m_i2 = 1;
optional class1 m_ptr = 2;
}
Using C++, once you run the protoc compiler against this, you end up with test.pb.cc and test.pb.h
You can then use these like:
#include <string>
#include "test.pb.h"
struct class1 {
int m_i;
std::string m_s;
};
struct class2 {
int m_i2;
class1 *m_ptr;
};
int main() {
class2 second_class;
second_class.m_i2 = 2;
second_class.m_ptr = new class1;
second_class.m_ptr->m_i = 1;
second_class.m_ptr->m_s = "one";
// Serialise class 2
serialisation::class2 serialisable_second_class;
serialisable_second_class.set_m_i2(second_class.m_i2);
if (second_class.m_ptr) {
serialisation::class1* serialisable_first_class = serialisable_second_class.mutable_m_ptr();
serialisable_first_class->set_m_i(second_class.m_ptr->m_i);
serialisable_first_class->set_m_s(second_class.m_ptr->m_s);
}
std::string serialised(serialisable_second_class.SerializeAsString());
// Parse class 2
serialisation::class2 parsed_second_class;
parsed_second_class.ParseFromString(serialised);
class2 retrieved_second_class;
retrieved_second_class.m_i2 = parsed_second_class.m_i2();
if (parsed_second_class.has_m_ptr()) {
retrieved_second_class.m_ptr = new class1;
retrieved_second_class.m_ptr->m_i = parsed_second_class.m_ptr().m_i();
retrieved_second_class.m_ptr->m_s = parsed_second_class.m_ptr().m_s();
} else {
retrieved_second_class.m_ptr = nullptr;
}
return 0;
}
Note, for the sake of brevity I'm not doing any error checking or exception handling here - this would be needed in production code. I'm also not managing the lifetime of the class1 pointer.

Best way of structuring methods to handle derived types

I have an inheritance hierarchy similar to below and I want to write my DAL to persist these objects but am unsure as to the best way of structuring it?
Pet <- Dog <- Alsation and Labrador
Pet <- Cat <- Persian and Tabby
Although all classes inherit from Pet, each method will need to call a different stored procedure and add different sql parameters. There will be some common parameters though.
A few ideas:
(1) PetDal with overloaded save method that takes in each derived type.
(2) PetDal with separate SaveLabrador, SaveTabby methods.
(3) Base PetDal plus inherited LabradorDal, TabbyDal classes, one per dervied type with a common interface. eg void Save(Pet pet) which would need to cast the pet to the derived type within each method (strategy method).
(4) Some other way.
(1) and (2) are really the same, just syntactically different. One problem with (4) is that if you want to deal with different persistent types (flat files, databases etc) then you will have to have a class for each permutation (AlsationToFileDAL, AlsationToSybaseDAL, etc).
You could use (1)/(2) with double dispatch, e.g.:
// pets.h
#include <string>
#include <iostream>
class Alsation;
class Persian;
class PetDAL
{
public:
virtual ~PetDAL () {}
virtual void save (const Alsation* alsation) = 0;
virtual void save (const Persian* persian) = 0;
};
class Pet
{
std::string name_;
public:
Pet (const std::string& name) : name_ (name)
{}
virtual ~Pet () {}
std::string getName () const
{
return name_;
}
virtual void save (PetDAL* dal) const = 0;
};
class Dog : public Pet
{
bool sleepWalks_;
public:
Dog (const std::string& name, bool sleepWalks) : Pet (name), sleepWalks_ (sleepWalks)
{}
bool getSleepWalks () const {return sleepWalks_;}
};
class Alsation : public Dog
{
public:
Alsation (const std::string& name, bool sleepWalks) : Dog (name, sleepWalks)
{}
virtual void save (PetDAL* dal) const
{
dal->save (this);
}
};
class Cat : public Pet
{
int purrsPerMinute_;
public:
Cat (const std::string& name, int purrsPerMinute) : Pet (name), purrsPerMinute_ (purrsPerMinute)
{}
int getPurrsPerMinute () const {return purrsPerMinute_;}
};
class Persian : public Cat
{
public:
Persian (const std::string& name, int purrsPerMinute) : Cat (name, purrsPerMinute)
{}
virtual void save (PetDAL* dal) const
{
dal->save (this);
}
};
class PetDALCoutImpl : public PetDAL
{
public:
virtual void save (const Alsation* alsation)
{
std::cout << "Saving alsation " << std::endl
<< "\tname=" << alsation->getName () << std::endl
<< "\tsleepwalks=" << alsation->getSleepWalks () << std::endl;
}
virtual void save (const Persian* persian)
{
std::cout << "Saving persian " << std::endl
<< "\tname=" << persian->getName () << std::endl
<< "\tpurrsPerMinute=" << persian->getPurrsPerMinute () << std::endl;
}
};
int test (int argc, char* argv[])
{
Dog* dog = new Alsation ("fido", true);
Cat* cat = new Persian ("dave", 10);
PetDAL* petDAL = new PetDALCoutImpl ();
dog->save (petDAL);
cat->save (petDAL);
delete cat;
delete dog;
return 0;
};
I.e. the Pet base class knows its subclasses can be saved to a DAL, but it has no dependency on the DAL implementations.
Have you thought about using a pattern like the strategy pattern? It might fit your needs as you can have different strategies for different implementations, whilst still using properties/methods from the abstract class?