473,396 Members | 1,929 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,396 software developers and data experts.

map<unsigned int index,vector<DebugInfo> >

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 2325
weaknessforcats
9,208 Expert Mod 8TB
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
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...
129
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...
10
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...
3
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"...
12
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...
1
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...
5
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...
5
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. ...
2
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...
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
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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...
0
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...

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.