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 2341
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 a data entry field (like
Shift-Home), the
program stops at line 1014 of wx-2.5.3-msw.ansi\wx\_core.py.
def __getitem__(self, index):
try:
x = self.Get()
except IndexError:
|
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 code I never even knew existed. Among these are <em> and
<strong>. What's the difference between these two and <i> and <b>?
--
Torbjørn Pettersen
Editor/Webmaster
|
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 null references another,
FK_LASTLYOID bigint not null references lastly,
unique (FK_OTHEROID,FK_ANOTHEROID))
|
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"
onclick="__doPostBack('SitesRadioButtonList_3','')"
language="javascript" />
|
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 the most significant bit in
a given element in an array of unsigned longs. Now I realise there may
be a more efficient way to do this, and if you know a better way please
let me know.
| |
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 table payment.
I use the Find-Method of the Session class to query some objects:
ArrayList find = (ArrayList)Program.Session.Find("from payment where
|
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 interface. Please help me resolve the error
I was able to implement the non Generics version
|
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.
Example 1:
// Legacy Function: Renders the Footer of the Theme
function themefooter() {
global $engine, $index, $themepath;
|
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
on various queries.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |