473,623 Members | 3,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

map<unsigned int index,vector<De bugInfo> >

3 New Member
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
Expand|Select|Wrap|Line Numbers
  1. 00000001 #include <iostream>
  2. 00000002 #include <vector>
  3. 00000003 #include <string>
  4. 00000004 #include <map>
  5. 00000005 using namespace std;
  6. 00000006 /**
  7. 00000007  * __FILE__
  8. 00000008  * __LINE__
  9. 00000009  * __BASE_FILE__
  10. 00000010  *
  11. 00000011  */
  12. 00000012
  13. 00000013
  14. 00000014 /**
  15. 00000015  * one single "display debug" item of a vector
  16. 00000016  */
  17. 00000017 struct AtomicDebugInfo {
  18. 00000018     string *message;
  19. 00000019     unsigned int line;
  20. 00000020 };
  21. 00000021 /**
  22. 00000022  * the first item of the map holds additional data
  23. 00000023  * same as AtomicDebugInfo but with additional attributes
  24. 00000024  */
  25. 00000025 struct StartDebugInfo {
  26. 00000026     string *message;
  27. 00000027     unsigned int line;
  28. 00000028     unsigned int attributes;
  29. 00000029 };
  30. 00000030 /**
  31. 00000031  * use this so we need only a vector of it, undependently of the position
  32. 00000032  * in the vector. In this way we can also have per-item attributes
  33. 00000033  */
  34. 00000034 union DebugInfo {
  35. 00000035     struct AtomicDebugInfo item;
  36. 00000036     struct StartDebugInfo top;
  37. 00000037 };
  38. 00000038
  39. 00000039
  40. 00000040 /**
  41. 00000041  * a demonstrative debugging class
  42. 00000042  */
  43. 00000043
  44. 00000044 typedef map<unsigned int,vector<DebugInfo> > Calls;
  45. 00000045
  46. 00000046 class Debug {
  47. 00000047 private:
  48. 00000048     unsigned int index;//which frame of the map this instance owns
  49. 00000049     static Calls calls;
  50. 00000050 public:
  51. 00000051     Debug(string msg,unsigned int line,unsigned int index);
  52. 00000052     static void Out();
  53. 00000053 };
  54. 00000054
  55. 00000055 //allocate static memory
  56. 00000056 map<unsigned int,vector<DebugInfo> > Debug::calls;
  57. 00000057
  58. 00000058
  59. 00000059 Debug::Debug(string msg,unsigned int line,unsigned int index) {
  60. 00000060     //How to insert one StartDebugInfo into Debug::calls ?
  61. 00000061     //One certainly needs to cast from DebugInfo
  62. 00000062     //But how ?
  63. 00000063     //Debug::calls.insert(index,
  64. 00000064 }
  65. 00000065
  66. 00000066 void Debug::Out() {
  67. 00000067     Calls::iterator iter;
  68. 00000068     iter = Debug::calls.begin();
  69. 00000069     cout << "dumping out debugging info" << endl;
  70. 00000070     while(iter != Debug::calls.end()) {
  71. 00000071         //cout << iter->first << endl;
  72. 00000072         iter++;
  73. 00000073     }
  74. 00000074 }
  75. 00000075
  76. 00000076 #define D(msg,index) Debug((msg),__LINE__,(index))
  77. 00000077
  78. 00000078
  79. 00000079 int main(void) {
  80. 00000080     /*
  81. 00000081     //using the class Debug would go like this
  82. 00000082     Debug *d1 = new D("foo",0);
  83. 00000083     Debug *d2 = new D("foo",123);
  84. 00000084     */
  85. 00000085     return EXIT_SUCCESS;
  86. 00000086 }
  87. 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.
Apr 30 '07 #1
1 2341
weaknessforcats
9,208 Recognized Expert Moderator Expert
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".
Apr 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1149
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:
129
64540
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
10
26092
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))
3
3806
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" />
12
2187
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.
1
3519
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
5
9370
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
5
1914
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;
2
2492
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.
0
8221
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, 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...
0
8603
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 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...
1
8317
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,...
0
8463
tracyyun
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...
0
7134
agi2029
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...
0
5560
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();...
0
4067
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...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.