-
May 20th, 2015, 05:52 AM
#1
c++ stl map
Hello
I have the following map :
listOfPolicyRuleInfo CPCRF::m_mlistOfCliConfiguredPolicyRules;
where typedef map<string, PolicyRuleInfo> listOfPolicyRuleInfo;
where PolicyRuleInfo is a struct
struct PolicyRuleInfo{
BearerQoSInfo stBearerQoS;
TFTInfo stTFTInfo;
PolicyRuleInfo(){};
PolicyRuleInfo( BearerQoSInfo const& qos, TFTInfo const& tft)
: stBearerQoS(qos), stTFTInfo(tft)
{ }
};
listOfPolicyRuleInfo m_mlistOfCliConfiguredPolicyRules =
boost::assign::map_list_of("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
("PolicyRule_Voice_C", PolicyRuleInfo( BearerQoSInfo(5), TFTInfo()))
("PolicyRule_Voice_U", PolicyRuleInfo( BearerQoSInfo(1), TFTInfo()));
Above are the data strutures. Now within the code somewhere ,
listOfPolicyRuleInfo::iterator it = m_mlistOfCliConfiguredPolicyRules.find("PolicyRule _Fred");
I get error when i try to print the contents of it.
on gdb i see the list
(gdb)p m_mlistOfCliConfiguredPolicyRules
["PolicyRule_Fred"] = {stBearerQoS = {nQCI = 9, nMaxUlBitRate = 0, nMaxDlBitRate = 0,
nGuarUlBitRate = 0, nGuarDlBitRate = 0, nPriorityLevel = 15,
bPreEmptionCapabilityEnabled = false, bPreEmptionVulnerabilityEnabled = true,
bQoSModified = false}, stTFTInfo = {static IPV4CompLen = 9 '\t',
static PiNhCompLen = 2 '\002', static SinglePortCompLen = 3 '\003',
static PortRangeCompLen = 5 '\005', static TypeOfServiceCompLen = 3 '\003',
static FilterHdrLen = 3 '\003', nTFTLen = 0, eOpCode = 3653872, bEBit = false,
nNumPktFilters = 0 '\000', mFilterId2TFTFilters = std::map with 0 elements,
vTFTParams = std::vector of length 0, capacity 0}},
["PolicyRule_Voice_C"] = {stBearerQoS = {nQCI = 5, nMaxUlBitRate = 0, nMaxDlBitRate = 0,
nGuarUlBitRate = 0, nGuarDlBitRate = 0, nPriorityLevel = 15,
bPreEmptionCapabilityEnabled = false, bPreEmptionVulnerabilityEnabled = true,
bQoSModified = false}, stTFTInfo = {static IPV4CompLen = 9 '\t',
static PiNhCompLen = 2 '\002', static SinglePortCompLen = 3 '\003',
static PortRangeCompLen = 5 '\005', static TypeOfServiceCompLen = 3 '\003',
static FilterHdrLen = 3 '\003', nTFTLen = 0, eOpCode = 3943806, bEBit = false,
nNumPktFilters = 0 '\000', mFilterId2TFTFilters = std::map with 0 elements,
vTFTParams = std::vector of length 0, capacity 0}},
["PolicyRule_Voice_U"] = {stBearerQoS = {nQCI = 1, nMaxUlBitRate = 0, nMaxDlBitRate = 0,
nGuarUlBitRate = 0, nGuarDlBitRate = 0, nPriorityLevel = 15,
bPreEmptionCapabilityEnabled = false, bPreEmptionVulnerabilityEnabled = true,
bQoSModified = false}, stTFTInfo = {static IPV4CompLen = 9 '\t',
static PiNhCompLen = 2 '\002', static SinglePortCompLen = 3 '\003',
static PortRangeCompLen = 5 '\005', static TypeOfServiceCompLen = 3 '\003',
static FilterHdrLen = 3 '\003', nTFTLen = 0, eOpCode = 4870778, bEBit = false,
nNumPktFilters = 0 '\000', mFilterId2TFTFilters = std::map with 0 elements,
vTFTParams = std::vector of length 0, capacity 0}}
But
(gdb) p it
$6 = {first = Traceback (most recent call last):
File "/usr/lib/../share/gdb/python/libstdcxx/v6/printers.py", line 558, in to_string
return self.val['_M_dataplus']['_M_p'].lazy_string (length = len)
RuntimeError: Cannot access memory at address 0xfffffff4
, second = {stBearerQoS = {nQCI = 0, nMaxUlBitRate = 0, nMaxDlBitRate = 0,
nGuarUlBitRate = 172411760, nGuarDlBitRate = 172411760, nPriorityLevel = 0,
bPreEmptionCapabilityEnabled = false, bPreEmptionVulnerabilityEnabled = false,
bQoSModified = false}, stTFTInfo = {static IPV4CompLen = 9 '\t',
static PiNhCompLen = 2 '\002', static SinglePortCompLen = 3 '\003',
static PortRangeCompLen = 5 '\005', static TypeOfServiceCompLen = 3 '\003',
static FilterHdrLen = 3 '\003', nTFTLen = 0, eOpCode = 174849016, bEBit = 128,
nNumPktFilters = 251 '\373', mFilterId2TFTFilters = std::map with 0 elements,
vTFTParams = std::vector of length 0, capacity 0}}}
Could some c++ stl experts help me with this issue please ?
thanks,
~pdk
-
May 20th, 2015, 08:42 AM
#2
Re: c++ stl map
Code:
boost::assign::map_list_of("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
//
listOfPolicyRuleInfo::iterator it = m_mlistOfCliConfiguredPolicyRules.find("PolicyRule _Fred");
Did you check that 'it' is not equal to m_mlistOfCliConfiguredPolicyRules.end() ?
Note: in the argument to find, you have a space between "e" and "_" .
Should it be there ?
Last edited by Philip Nicoletti; May 20th, 2015 at 08:58 AM.
-
May 20th, 2015, 10:18 AM
#3
Re: c++ stl map
Thanks a lot for reply and hint.
Now while trying to debug, i have further reduced the changed the map structure to "unsigned int" to see if any issues in memory leaks...
Now changed the structure
// .h
typedef map<u8, u8> listOfPolicyRuleInfo;
class CPCRFublic CBaseClass
{
static map<u8, u8> m_mlistOfCliConfiguredPolicyRules;
}
//.cpp
std::map<u8, u8> m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of(Apn_Fred, 9);
void CPCRF::GxCCRequest(string imsi, bool isDefBearerCreation, string sApn, const BearerQoSInfo & stBearerQoS, CIPAddress ueIPAddress, BearerQoSInfo & stBearerQoSNegotiated)
{
switch(getApnCode(sApn))
{
case Apn_Fred:
{
listOfPolicyRuleInfo::iterator it = m_mlistOfCliConfiguredPolicyRules.find(Apn_Fred);
}
// Another .cpp file
std::map<u8, u8>::iterator it = CPCRF::m_mlistOfCliConfiguredPolicyRules.find(nApn);
if (it != CPCRF::m_mlistOfCliConfiguredPolicyRules.end())
{
sPolicyName = it->first;
// stQOS = it->second.stBearerQoS;
}
}
Another.cpp CGxDia.cpp:353: undefined reference to `CPCRF::m_mlistOfCliConfiguredPolicyRules'
while linking i get the above error...
Am i doing something basic wrong/..
-
May 20th, 2015, 10:22 AM
#4
Re: c++ stl map
You have:
Code:
//.cpp
std::map<u8, u8> m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of(Apn_Fred, 9);
I am guessing it should be:
Code:
//.cpp
std::map<u8, u8> CPCRF::m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of(Apn_Fred, 9);
-
May 20th, 2015, 10:24 AM
#5
Re: c++ stl map
Just a small point. When posting code, please use code tags so that the code is readable! Go Advanced, select the formatted code and click '#'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 20th, 2015, 10:26 AM
#6
Re: c++ stl map
You are amazingly brilliant ! . This issue is fixed (at least the linking), now i need to revert to earlier code
How do I add reputation here ?
Last edited by pdk5; May 20th, 2015 at 11:41 AM.
-
May 20th, 2015, 11:12 AM
#7
Re: c++ stl map
Reverted back to original code ..now
listOfPolicyRuleInfo CPCRF::m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of
("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
("PolicyRule_Voice_C", PolicyRuleInfo( BearerQoSInfo(5), TFTInfo()))
("PolicyRule_Voice_U", PolicyRuleInfo( BearerQoSInfo(1), TFTInfo()));
But at listOfPolicyRuleInfo::iterator it = CPCRF::m_mlistOfCliConfiguredPolicyRules.find("PolicyRule_Fred");
getting compilation error
ransrc/CGxDia.cpp:351: error: invalid conversion from 'const char*' to 'unsigned char'
sorry for the basic questions, but i am bit poort in c++/stl
-
May 20th, 2015, 11:19 AM
#8
Re: c++ stl map
sorry my mistake , have not changed this all places
Last edited by pdk5; May 20th, 2015 at 11:22 AM.
-
May 20th, 2015, 11:34 AM
#9
Re: c++ stl map
Had not changed in the declaration in the class
class CPCRF
{
static listOfPolicyRuleInfo m_mlistOfCliConfiguredPolicyRules;
}
from // static map<u8, u8> m_mlistOfCliConfiguredPolicyRules;
Now the issue is resolved..
This was mainly due to
listOfPolicyRuleInfo CPCRF::m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
was defined as :
listOfPolicyRuleInfo m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of("PolicyRule_Fred", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
Thanks a lot Philip for the quickly pointing out this issue ..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|