This is a demonstrative code which could be used for debugging purposes. And yet I don't know how to insert the necessary data on line 63, purely syntactically speaking ? I'm a beginner with STL, and from what I've read insert() accepts references for almost all of its overloaded versions. If so, what could one do so those element's memory space doesn't wipe out? I suppose one should use the heap. In rest I hope the code speaks for itself, it's a demonstrative rewrite of a code using heavily VC++ preprocessor's features for mingw - 00000001 #include <iostream>
-
00000002 #include <vector>
-
00000003 #include <string>
-
00000004 #include <map>
-
00000005 using namespace std;
-
00000006 /**
-
00000007 * __FILE__
-
00000008 * __LINE__
-
00000009 * __BASE_FILE__
-
00000010 *
-
00000011 */
-
00000012
-
00000013
-
00000014 /**
-
00000015 * one single "display debug" item of a vector
-
00000016 */
-
00000017 struct AtomicDebugInfo {
-
00000018 string *message;
-
00000019 unsigned int line;
-
00000020 };
-
00000021 /**
-
00000022 * the first item of the map holds additional data
-
00000023 * same as AtomicDebugInfo but with additional attributes
-
00000024 */
-
00000025 struct StartDebugInfo {
-
00000026 string *message;
-
00000027 unsigned int line;
-
00000028 unsigned int attributes;
-
00000029 };
-
00000030 /**
-
00000031 * use this so we need only a vector of it, undependently of the position
-
00000032 * in the vector. In this way we can also have per-item attributes
-
00000033 */
-
00000034 union DebugInfo {
-
00000035 struct AtomicDebugInfo item;
-
00000036 struct StartDebugInfo top;
-
00000037 };
-
00000038
-
00000039
-
00000040 /**
-
00000041 * a demonstrative debugging class
-
00000042 */
-
00000043
-
00000044 typedef map<unsigned int,vector<DebugInfo> > Calls;
-
00000045
-
00000046 class Debug {
-
00000047 private:
-
00000048 unsigned int index;//which frame of the map this instance owns
-
00000049 static Calls calls;
-
00000050 public:
-
00000051 Debug(string msg,unsigned int line,unsigned int index);
-
00000052 static void Out();
-
00000053 };
-
00000054
-
00000055 //allocate static memory
-
00000056 map<unsigned int,vector<DebugInfo> > Debug::calls;
-
00000057
-
00000058
-
00000059 Debug::Debug(string msg,unsigned int line,unsigned int index) {
-
00000060 //How to insert one StartDebugInfo into Debug::calls ?
-
00000061 //One certainly needs to cast from DebugInfo
-
00000062 //But how ?
-
00000063 //Debug::calls.insert(index,
-
00000064 }
-
00000065
-
00000066 void Debug::Out() {
-
00000067 Calls::iterator iter;
-
00000068 iter = Debug::calls.begin();
-
00000069 cout << "dumping out debugging info" << endl;
-
00000070 while(iter != Debug::calls.end()) {
-
00000071 //cout << iter->first << endl;
-
00000072 iter++;
-
00000073 }
-
00000074 }
-
00000075
-
00000076 #define D(msg,index) Debug((msg),__LINE__,(index))
-
00000077
-
00000078
-
00000079 int main(void) {
-
00000080 /*
-
00000081 //using the class Debug would go like this
-
00000082 Debug *d1 = new D("foo",0);
-
00000083 Debug *d2 = new D("foo",123);
-
00000084 */
-
00000085 return EXIT_SUCCESS;
-
00000086 }
-
00000087
As I'm a beginner in STL, the sintax overwhelms me, so please show me how to write it syntactically and forgive my bad english. Thanks.
1 2325
You need to use inheritance.
Your base class is DebugInfo.
AtomicDebugInfo derives from DeugInfo as adds the message and the line.
StartDebugInfo derives from AtomicDebugInfo and adds attributes.
When you create a StartDebugInfo object it will contain message, line and atrtributes.
Next, you write functions using DebugInfo pointer or reference arguments and you pass in your StartDebugInfo object as a DebugInfo object.
Virtual functions in DebugInfo will be overriden in your derived classes so you can call your derived class methods.
If you need to call methods in your derived class that are not in your base class, then research the Visitor design pattern. It's in the book "Design Patterns".
Sign in to post your reply or Sign up for a free account.
Similar topics
by: It's me |
last post by:
I've built a Python application using PythonCard 1.9 and Python 2.3 running
under Windows XP. Everything works except that when I use the keyboard
instead of the mouse to do certain operations in...
|
by: Torbjørn Pettersen |
last post by:
I've started cleaning up my HTML and implementing CSS. So far I've
used FrontPage, but am switching over to DreamWeaver.
Reading a bit on W3Schools.com and W3.org I see there are a lot
of HTML...
|
by: BuddhaBuddy |
last post by:
Platform is DB2/NT 7.2.9
The table was created like this:
CREATE TABLE MYTEST (
MYTESTOID bigint not null primary key,
FK_OTHEROID bigint not null references other,
FK_ANOTHEROID bigint not...
|
by: Josef K. |
last post by:
Asp.net generates the following html when producing RadioButton lists:
<td><input
id="RadioButtonList_3"
type="radio"
name="MyRadioButtonList"
value="644"...
|
by: Mick_fae_Glesga |
last post by:
OK, the solution to this is probably blindingly obvious to everyone,
but... surely it can't be right.
I am compiling with borland bcc32 free compiler
this piece of code is designed to identify...
|
by: blabla120 |
last post by:
Hi folks,
I am net to NHibernate, and I hava a read baisc/general question.
In my database (PostgreSQL), I have an unique index laying on the field
transaktionsnummer which is located in the...
|
by: Shikari Shambu |
last post by:
Hi,
I am trying to implement a collection that implements IEnumerable<T>. I
keep getting the following error
'IEnumerator<...>.Current' in explicit interface declaration is not a member
of...
|
by: planetbrett |
last post by:
I have read through php.net manuals and have not see any mention about
what these operands actually do. I have seen them used in a bunch of
different code lately and don't really understand.
...
|
by: BD |
last post by:
Hi, all.
My background is more Oracle than db2. My skills at SQL tuning are
quite limited.
I'm running 8.2 on Windows.
I'm tasked with some SQL optimization, and am doing some explain plans...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |