473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

combining different types into single data structure

I want to make a good design about combining information. Suppose you
have different data types, and each may have semantically same data. I
want to merge these different data types into a single data at run-
time. For example, sonar sensor has two internal data (bearing and
bearing_rate), and Radar has two as well (range, bearing.

struct sonar_data {
float bearing;
float bearing_rate;
};

struct radar_data {
float bearing;
float range;
};

sonar_data sd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;

radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;

I want to combine these two data into a single data structure:

data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; // only comes from sonar_data
data.range = 12.0f; // only comes from radar_data
I don’t know how to make a good design about this problem. Do you have
any template based (or other) suggestions?

Thanks in advance...

---Sgo---
Jun 27 '08 #1
5 4323
On Sun, 20 Apr 2008 11:18:31 -0700, girays wrote:
I want to make a good design about combining information. Suppose you
have different data types, and each may have semantically same data. I
want to merge these different data types into a single data at run-
time. For example, sonar sensor has two internal data (bearing and
bearing_rate), and Radar has two as well (range, bearing.

struct sonar_data {
float bearing;
float bearing_rate;
};

struct radar_data {
float bearing;
float range;
};
+ My humble idea: why not construct only one "data" structure to hold
sonar and radar information.

struct data
{
double sonar_bearing;
double sonar_bearing_rate;
double radar_bearing;
double radar_range;
};

+ Why are you using floats?
sonar_data sd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;

radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;

I want to combine these two data into a single data structure:

data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; // only comes from sonar_data data.range =
12.0f; // only comes from radar_data
I don’t know how to make a good design about this problem. Do you have
any template based (or other) suggestions?

Thanks in advance...

---Sgo---

--
Umut
Jun 27 '08 #2
On Apr 20, 8:18 pm, girays <selcukgi...@gmail.comwrote:
I want to make a good design about combining information.
Suppose you have different data types, and each may have
semantically same data. I want to merge these different data
types into a single data at run- time. For example, sonar
sensor has two internal data (bearing and bearing_rate), and
Radar has two as well (range, bearing.
struct sonar_data {
float bearing;
float bearing_rate;
};
struct radar_data {
float bearing;
float range;
};
sonar_data sd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;
radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;
I want to combine these two data into a single data structure:
data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; // only comes from sonar_data
data.range = 12.0f; // only comes from radar_data
I don?t know how to make a good design about this problem. Do
you have any template based (or other) suggestions?
What's wrong with just:

struct Data
{
sonar_data sonar ;
radar_data radar ;
} ;

?

If you want to enforce the fact that both have the same bearing,
then give the class a constructor.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #3
James Kanze <ja*********@gmail.comwrites:
On Apr 20, 8:18 pm, girays <selcukgi...@gmail.comwrote:
>I want to make a good design about combining information.
Suppose you have different data types, and each may have
semantically same data. I want to merge these different data
types into a single data at run- time. For example, sonar
sensor has two internal data (bearing and bearing_rate), and
Radar has two as well (range, bearing.
>struct sonar_data {
float bearing;
float bearing_rate;
};
>struct radar_data {
float bearing;
float range;
};
>sonar_data sd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;
>radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;
>I want to combine these two data into a single data structure:
>data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; // only comes from sonar_data
data.range = 12.0f; // only comes from radar_data
>I don?t know how to make a good design about this problem. Do
you have any template based (or other) suggestions?

What's wrong with just:

struct Data
{
sonar_data sonar ;
radar_data radar ;
} ;

?

If you want to enforce the fact that both have the same bearing,
then give the class a constructor.
class Detector {
public:
float bearing;
float range;
};

class Radar:public Detector{
public:
float frequency;
};

class Sonar:public Detector{
public:
float rate;
};
Perhaps you need to read some tutorial about Object Oriented Programming?

--
__Pascal Bourguignon__
Jun 27 '08 #4

>
+ My humble idea: why not construct only one "data" structure to hold
sonar and radar information.

struct data
{
double sonar_bearing;
double sonar_bearing_rate;
double radar_bearing;
double radar_range;
};

+ Why are you using floats?
because precision of the float gives enough resolution the represent
all possible bearing values and radar coverage range (I know because
i work on the same project :) ). It also consumes half the space on
the wire (That was the main reason)
>sonar_data sd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;

radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;

I want to combine these two data into a single data structure:

data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; // only comes from sonar_data data.range =
12.0f; // only comes from radar_data
I don’t know how to make a good design about this problem. Do you have
any template based (or other) suggestions?

Thanks in advance...
Since we lack reflection on C++ and cant dynamically create
classes on the fly, a straightforward implementation would be;

struct target_data {
float bearing;
float range ;
float bearing_rate;
};

struct combinator {

target_data
operator() (const sonar_data& snr , const radar_data& rdr)
{
target_data target;
target.bearing = algo_bearing_calc(snr.bearing,
rdr.bearing);
target.range = rdr.range;
target.bearing_rate =snr.bearing_rate;
}
};

and somewhere in your code;

std::transform (sonarvec.begin(), sonarvec.end(), radarvec.begin(),
back_inserter(targetvec), combinator());

--
hurcan


Jun 27 '08 #5
On Apr 21, 12:50*pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
James Kanze <james.ka...@gmail.comwrites:
On Apr 20, 8:18 pm, girays <selcukgi...@gmail.comwrote:
I want to make a good design about combining information.
Suppose you have different data types, and each may have
semantically same data. I want to merge these different *data
types into a single data at run- time. For example, sonar
sensor has two internal data (bearing and bearing_rate), and
Radar has two as well (range, bearing.
structsonar_data{
* float bearing;
* float bearing_rate;
};
struct radar_data {
* * * *float bearing;
* * * *float range;
};
>sonar_datasd;
sd.bearing = 5.0f;
sd.bearing_rate = 0.1f;
radar_data rd;
rd.bearing = 3.0f;
rd.range = 12.0f;
I want to combine these two data into a single data structure:
data.bearing = 4.0f // average of sd(5.0f) and rd(3.0f)
data.bearing_rate = 0.1f; *// only comes fromsonar_data
data.range = 12.0f; // only comes from radar_data
I don?t know how to make a good design about this problem. Do
you have any template based (or other) suggestions?
What's wrong with just:
* * struct Data
* * {
* * * *sonar_datasonar ;
* * * * radar_data radar ;
* * } ;
?
If you want to enforce the fact that both have the same bearing,
then give the class a constructor.

class Detector {
public:
* *float bearing;
* *float range;

};

class Radar:public Detector{
public:
* *float frequency;

};

class Sonar:public Detector{
public:
* *float rate;

};

Perhaps you need to read some tutorial about Object Oriented Programming?

--
__Pascal Bourguignon__- Hide quoted text -

- Show quoted text -
It's not an object oriented question, sorry but I trust my oo
knowledge. I'm pursuing a run-time solution for this.

simple idea: each struct has attribute map, at run time you can
iterate them, same attribute's can be merged (averaged)
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pete Shinners | last post by:
I've been spending the last few night upgrading some 'classic' type objects to the more modern 'newstyle' types. Unless I am not finding some important page, this entire process is almost entirely...
6
by: alg | last post by:
Is it possible to put different types of objects in a single STL list? If not what STL template should be used which will contains various objects of different types? Thanks for your help!
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
9
by: CptDondo | last post by:
I am working on an embedded platform which has a block of battery-backed RAM. I need to store various types of data in this block of memory - for example, bitmapped data for control registers,...
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
5
by: Tristan Miller | last post by:
Greetings. Is it possible using HTML and CSS to represent a combining diacritical mark in a different style from the letter it modifies? For example, say I want to render Å‘ (Latin small letter...
4
by: yugidnu | last post by:
Hi all, I have the following problem. I have to access different types of structures getting passed via a void pointer. I have the code snippet here. ...
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.