http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Help finding appropriate design pattern for event loggin - 2 messages, 2
authors
http://groups.google.com/group/comp.lang.c++/t/77600894bf052491?hl=en
* Can std::copy be used to copy to an empty container? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/f47a63e5d9ea8656?hl=en
* (WWW.EdHardy4Sale.COM) whole sale Ed Hardy Swimwear bikinis - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/25872df21fa3193b?hl=en
* is this guy for real? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/ba1889767ce49899?hl=en
* delete[] - 6 messages, 5 authors
http://groups.google.com/group/comp.lang.c++/t/53798a6cfd1056e2?hl=en
* this by rvalue - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/95d234deae2a3409?hl=en
* hi... - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/77fa390e3bf2a1df?hl=en
* Intel's Atom processors exposed - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/16637f8039fb3264?hl=en
* C++ Gurus - Is C++ a good choice for public API(s)??? Are there clean ways
to solve known problems there? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/faaac8999a2ece5e?hl=en
==============================================================================
TOPIC: Help finding appropriate design pattern for event loggin
http://groups.google.com/group/comp.lang.c++/t/77600894bf052491?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Jun 1 2009 11:59 am
From: "AnonMail2005@gmail.com"
On Jun 1, 11:30 am, Greg Dharma <tottenham.co...@googlemail.com>
wrote:
> Hello,
>
> I am using C++ for about a year now and am comfortable with the basics
> of the language but need some help here with finding a design pattern
> for a problem I am trying to solve.
>
> Basically I am trying to log events happening in different classes
> (spread across different .cxx files). The events are in most cases
> certain checks being done before accessing data from a database. I
> need to log which check was done, whether it passed/failed, why it
> passed/failed etc.
>
> I am thinking of having a "event collector" class. I will then create
> a single object of this class in my program. Then from the various
> parts of my code I will call a function like eventCollector-
>
> >pushEventInfo(.....)
>
> Now from different parts of the code I would be passing in different
> amounts of information (e.g. a couple of strings from one function, a
> bunch of int values from another etc). So I would overload the
> pushEventInfo function to accept structs of the different types of
> info I will be passing to the "event collector" class.
>
> I am wondering if there is any design patten which closely matches
> what I am trying to do here. If so, I could read it and clear up any
> issues that might occur before I get into implementing my solution to
> this problem.
>
> Any other ideas about the general theme of "sending information from
> different classes/files to a central location for data collection"
> would also be appreciated.
>
> Thanks a lot guys!
> Greg.
Take a look at various logging classes (e.g. log4cpp) or write your
own. The logger doesn't have to log to a file, it can output it's
"stuff" to where ever - a file, network, terminal, etc.
The key point is that the outputting is left to that class and the
users of your class do not need to know about those details. Other
key points are the logger is typically a singleton.
Another typical feature is that users of this type of class use
std::ostream operators to format their output. This way, your logging
class doesn't need to know about how to output the various things your
client code has to deal with. The logger typically deals with already
formatted output like a std::string.
HTH
== 2 of 2 ==
Date: Mon, Jun 1 2009 12:08 pm
From: Marcel Müller
Hi,
Greg Dharma wrote:
> I do not need to log to a file...the utility needs to print out all
> information right away to a screen and I do not want many couts/prints
> cluttering up the code in various places. I would like to be able to
> send event information to a central location and this could then
> format the data appropriately and then output it (to the screen for
> now) but possibly to a DB or file later (in which case having all data
> being collected in a central place would be definitely useful).
since you have to serialize the information anyway all event classes
should provide a common interface for this job. Furthermore it is
helpful to have some common properties like a severity level. That might
control e.g. coloring in case of screen visualization. And the
collection might calculate some aggregate information like total success
from that. If you want to support filters, more common properties like a
time stamp and context information about the event source, e.g. the
logical component of the application. Individual structures for each
type of event are only useful if there is someone who needs this kind
information in machine readable format. And this is rather unlikely to
happen outside your event classes because it would require RTTI dispatching.
If you do not want to pass a reference to your event collector anywhere
around, you could use thread local storage. For the time of a service
request the TLS could point to your individual request collector. And
once the request is completed the collector is detached from the current
thread. This is an easy and usually high-performance solution.
Unfortunately it requires platform dependencies until C++0x.
Marcel
==============================================================================
TOPIC: Can std::copy be used to copy to an empty container?
http://groups.google.com/group/comp.lang.c++/t/f47a63e5d9ea8656?hl=en
==============================================================================
== 1 of 3 ==
Date: Mon, Jun 1 2009 1:28 pm
From: "JD"
Hi,
I have used following similar pieces of code for many years. However, I
just found out that the document says that copy should be used to copy items
to an empty container. Is copying to an empty container serious? Please
advise.
vector<int> v;
....
set<int> s;
copy(v.begin(), v.end(), inserter(s, s.begin())); // copy v to an empty
container s
Thanks.
JD
== 2 of 3 ==
Date: Mon, Jun 1 2009 1:34 pm
From: Juha Nieminen
JD wrote:
> vector<int> v;
> ....
> set<int> s;
> copy(v.begin(), v.end(), inserter(s, s.begin())); // copy v to an empty
> container s
I don't see the problem there, even though I would usually just use:
s.insert(v.begin(), v.end());
There are other situation where using an inserter iterator and an
algorithm like std::copy can be useful, though.
== 3 of 3 ==
Date: Mon, Jun 1 2009 5:34 pm
From: Pete Becker
JD wrote:
> Hi,
>
> I have used following similar pieces of code for many years. However, I
> just found out that the document says that copy should be used to copy items
> to an empty container. Is copying to an empty container serious? Please
> advise.
>
> vector<int> v;
> ....
> set<int> s;
> copy(v.begin(), v.end(), inserter(s, s.begin())); // copy v to an empty
> container s
>
Think of it as inserting into an empty container. That's what the insert
iterator does.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
==============================================================================
TOPIC: (WWW.EdHardy4Sale.COM) whole sale Ed Hardy Swimwear bikinis
http://groups.google.com/group/comp.lang.c++/t/25872df21fa3193b?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jun 1 2009 1:32 pm
From: edhardy4sale
Discount (WWW.EdHardy4Sale.COM) Ed Hardy Swimwear bikinis,we retail
and whole sale sell buy ed hardy Swimwear bikini included:
Ed Hardy Dedicated Rhinstone Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Anchor Of Love Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy KIO Kisses Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy KIO Kisses Rhinstone Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Love Kills Rhinstone Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Love Kills Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Tiger Rose Rhinstone Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy True To My Love Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Love Dragon Womens Swimwear (WWW.EdHardy4Sale.COM)
Ed Hardy Tiger Rhinstones 3 Ring Womens Swimwear
(WWW.EdHardy4Sale.COM)
and many many more.
==============================================================================
TOPIC: is this guy for real?
http://groups.google.com/group/comp.lang.c++/t/ba1889767ce49899?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jun 1 2009 2:49 pm
From: lanco
i found this website today from an email a co-worker sent me..
http://www.maverickmoneymakerstwentyfourseven.com
i watched his videos on this site, and i'm blown away thats he's
making $2,000,000 a year.
has anyone in this group tried this program?
please let me know!
==============================================================================
TOPIC: delete[]
http://groups.google.com/group/comp.lang.c++/t/53798a6cfd1056e2?hl=en
==============================================================================
== 1 of 6 ==
Date: Mon, Jun 1 2009 3:06 pm
From: "Martijn Mulder"
void main()
{
int*a=new int[10];
int*b=new int[100];
delete[]a;
a=b;
delete[]a;
}
In the code above, is de new'd memory correctly deleted? How does the
runtime know that first *a points to an array of 10 elements and later to an
array of 100 elements?
== 2 of 6 ==
Date: Mon, Jun 1 2009 3:25 pm
From: joshuamaurice@gmail.com
On Jun 1, 3:06 pm, "Martijn Mulder" <i@m> wrote:
> void main()
> {
> int*a=new int[10];
> int*b=new int[100];
> delete[]a;
> a=b;
> delete[]a;
>
> }
>
> In the code above, is de new'd memory correctly deleted?
Yes
> How does the
> runtime know that first *a points to an array of 10 elements and later to an
> array of 100 elements?
Magic. :)
Usually one of two approaches is employed (abbreviated):
1- When you allocate a chunk of 100 bytes, the runtime actually
allocates 104 bytes and stores the allocation size in the first 4
bytes, then returns the allocation pointer + 4 bytes. When you
deallocate it, the runtime looks at this header by taking the pointer
- 4 to get the allocation size.
2- A table is kept, mapping each allocation to its size.
== 3 of 6 ==
Date: Mon, Jun 1 2009 7:21 pm
From: Puppet_Sock
On Jun 1, 6:06 pm, "Martijn Mulder" <i@m> wrote:
> void main()
> {
> int*a=new int[10];
> int*b=new int[100];
> delete[]a;
> a=b;
> delete[]a;
>
> }
>
> In the code above, is de new'd memory correctly deleted? How does the
> runtime know that first *a points to an array of 10 elements and later to an
> array of 100 elements?
Technically, since the language does not define
*how* the implementation does it, it's off topic
here. As far as coding what you need to know is,
the calls to new will return different values
(always presuming that the allocation actually
works, that there is enough memory left) and that
the implementation knows how to find the memory
chunk through those values. And how to do things
like offsets from pointers to elements of an
allocated block, and so on.
Socks
== 4 of 6 ==
Date: Mon, Jun 1 2009 7:47 pm
From: Phlip
"Martijn Mulder" wrote:
> void main()
'void main' inhibits Republicans from attacking each other by accident. Always
use 'int main'.
--
Phlip
== 5 of 6 ==
Date: Mon, Jun 1 2009 7:51 pm
From: Phlip
Puppet_Sock wrote:
> Technically, since the language does not define
> *how* the implementation does it, it's off topic
> here.
Incorrect. Comparing implementations is a very important role for this
newsgroup, and one that we cannot trust to _any_ vendor-specific forum!
--
Phlip
== 6 of 6 ==
Date: Mon, Jun 1 2009 9:46 pm
From: blargg.ei3@gishpuppy.com (blargg)
Martijn Mulder wrote:
> void main()
int main()
> {
> int*a=new int[10];
> int*b=new int[100];
> delete[]a;
> a=b;
> delete[]a;
> }
>
> In the code above, is de new'd memory correctly deleted? How does the
> runtime know that first *a points to an array of 10 elements and later to an
> array of 100 elements?
Via a similar way that it knows that a has the value 10 below, and then
later on the value 100:
int a = 10;
int b = 100;
a = b;
==============================================================================
TOPIC: this by rvalue
http://groups.google.com/group/comp.lang.c++/t/95d234deae2a3409?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Jun 1 2009 4:16 pm
From: Jan Bielawski
I was reading up on the new C++0x features and have a question:
Is there a way to overload on the rvalue-ness of the invoking object
itself? In other words, distinguish between:
// contrived example
X x;
x.foo();
and:
X f();
f().foo();
A less contrived example would be a member X::operator+() which would
distinguish between the first and the second invocation in the line
below:
X x, y, z;
X xx = x + y + z
So the first + sign would resolve to <lvalue>.operator+(y), and the
second + sign would resolve to <rvalue>.operator+(z)
(where the second one is presumably moving instead of copying).
Is this available? Is it at all useful? It's as if there was a "&&"
qualifier (or whatever it's called) analogous to "const" in method
declaration:
X X::operator+(const X& rhs) {...} // as usual
X X::operator+(const X& rhs) && {...} // the one invoked on
rvalue
X X::operator+(const X& rhs) const {...} // the one invoked on
const
Does this even make any sense?
--
Jan
== 2 of 2 ==
Date: Mon, Jun 1 2009 11:42 pm
From: SG
On 2 Jun., 01:16, Jan Bielawski <film...@gmail.com> wrote:
> I was reading up on the new C++0x features and have a question:
>
> Is there a way to overload on the rvalue-ness of the invoking object
> itself? In other words, distinguish between:
>
> // contrived example
> X x;
> x.foo();
>
> and:
>
> X f();
> f().foo();
Yes. That's where "ref qualifiers" come in:
class X {
public:
void foo() &;
void foo() &&;
};
> A less contrived example would be a member X::operator+() which would
> distinguish between the first and the second invocation in the line
> below:
>
> X x, y, z;
> X xx = x + y + z
>
> So the first + sign would resolve to <lvalue>.operator+(y), and the
> second + sign would resolve to <rvalue>.operator+(z)
> (where the second one is presumably moving instead of copying).
Possible but unusable. I would write a free operator+ in terms of +=:
class X {
public:
...
X& operator=(X const&) &;
X& operator=(X &&) &;
X& operator+=(X const&) &;
X& operator+=(X &&) &;
...
};
inline X operator+(X const& lhs, X const& rhs) {
X temp = lhs;
temp += rhs;
return temp;
}
inline X operator+(X && lhs, X const& rhs) {
return std::move(lhs += rhs);
}
> Is this available? Is it at all useful? It's as if there was a "&&"
> qualifier (or whatever it's called) analogous to "const" in method
> declaration:
>
> X X::operator+(const X& rhs) {...} // as usual
> X X::operator+(const X& rhs) && {...} // invoked on rvalue
> X X::operator+(const X& rhs) const {...} // invoked on const
Almost. You can't overload the functions like this. You can't have two
member function which only differ in one lacking a ref qualifier and
the other one having some ref qualifier. To make this work you need to
add an lvalue ref qualifier ("&") for the first function. But what
would be the difference between the first and the third function? I
hope none. You should at least remove the first function.
Cheers!
SG
==============================================================================
TOPIC: hi...
http://groups.google.com/group/comp.lang.c++/t/77fa390e3bf2a1df?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jun 1 2009 9:59 pm
From: "bhakyadittpt@gmail.com"
respected sir or madam...
i was finished diploma IT... i know C++.... i need job
based on my qualification...
==============================================================================
TOPIC: Intel's Atom processors exposed
http://groups.google.com/group/comp.lang.c++/t/16637f8039fb3264?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jun 1 2009 10:52 pm
From: "whatnext@gmail.com"
First thing Tuesday morning and Intel is showing off it's new Atoms –
previously known as Silverthorne and Diamondville, these processors
will become part of a new set of brands in addition to the Centrino
we've seen for the last five years.
http://www.intel-intel99.blogspot.com
==============================================================================
TOPIC: C++ Gurus - Is C++ a good choice for public API(s)??? Are there clean
ways to solve known problems there?
http://groups.google.com/group/comp.lang.c++/t/faaac8999a2ece5e?hl=en
==============================================================================
== 1 of 1 ==
Date: Tues, Jun 2 2009 12:09 am
From: joshuamaurice@gmail.com
On Jun 1, 2:41 am, blargg....@gishpuppy.com (blargg) wrote:
> ariji...@gmail.com wrote:
> > I needed to build up a public API for an application at hand.
>
> > The data I am modelling maps very well to object oriented design, so I
> > am little inclined towards a C++ public API (i.e. my deliverables
> > would be a <xyz>.hpp file which will have a bunch of pure virtual
> > functions forming the interface and a lib<xyz>.so which will basically
> > contain the implementation for those interfaces).
>
> > But, I can think of 2 problems there:
> > 1) How do I guarantee that my shared library will work well with the
> > version of the C++ library/compiler my customer/user is having?
> > Issue in detail: I mean, I compile my shared library with version 'X'
> > of a Std CPP compiler and customer tries to use with version 'Y' of
> > StdCPP compiler. And then, if 'X' and 'Y' versions of CPP compiler are
> > not compatible, then we get into trouble. We have hit this several
> > times with different gcc versions. Just wondering, what is the best/
> > cleanest way to solve/get-around this problem?
>
> Write a C wrapper. If your interface were
>
> class Interface {
> public:
> virtual int f( double );
> };
>
> Interface* new_foo();
>
> you could write a C wrapper as
>
> typedef struct Interface Interface;
>
> Interface* xyz_new_foo( void );
> void xyz_delete( Interface* );
> int xyz_f( Interface*, double );
>
> and it would be accessible from many languages.
This
> If you then wanted C++
> users to have a more convenient interface, you could provide a client-side
> wrapper for the C interface. :)
and this. Specifically, provide a small wrapper class in a header only
that implements itself in terms of the C API, and give this header to
clients. The class will be compiled by the client's compiler, and all
calls to your library will go through a stable C API. You gain the
stability of the C API and a nice C++ interface class.
Note that it's not always convenient, reasonable or practical to do it
this way, but many times it is.
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en
To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
No comments:
Post a Comment