I am having an issue with my multimap insert. I have looked high and low for a possible solution to this problem. What I am trying to do is make an dynamic hierarchy data structure that has a root element then child elements under it holding values. I thought using a 3 dimensional multimap would be the best way but hey I am still a newbie. If you can think of a more efficient way to do it I am all for it.

a sample of the data is:

me {
	name: stats.devish.net;
	desc: DNet Stats Server;
	numeric: 343;
	bind: ipAddress;
	quitprefix: Quit:;
};
connect {
	host: ipAddress;
	port: 7867;
	pass: ********;
}

What I am having problems is the line that is inserting the child elements into the higharchy on line 13 below.

// storage class for our dynamic conf blocks
std::set<const char*> block_names;
std::set< const char*>::iterator blockit;

//storage class for block elements

typedef std::multimap<const char*,const char*> eTYPE;
std::multimap<const char*, eTYPE > blocks;
void Conf::Run()
{
//populate "me" core block
Conf::addClass("me");
blocks.insert(std::multimap::value_type("me", eTYPE::value_type("name", "dnet")));


//populate "connect" core block
Conf::addClass("connect");

}

If you need anything from me let me know. Thank you for your time. :)

Edited 6 Years Ago by matthewl: n/a

What is the error you are getting? Can you provide the smallest compilable piece of code that will produce this error, along with sample input, expected output, and current output?

Dave

Here is the error:

make -C src  dnetstats
g++ -pipe -fPIC -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute -Wall -g1 -I/home/matthew/svn/dnetstats/src/include -pedantic -c confreader.cpp
confreader.cpp: In member function ‘void Conf::Run()’:
confreader.cpp:34: error: ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::multimap’ used without template parameters
make[1]: *** [confreader.o] Error 1
make: *** [server] Error 2

In me previous post I included the sample data which will be my input. As for expected result is that the value from the child elements to be dynamically stored in memory like a multimap would as for current output there is none do to the server is just initializing and it will be reading the conf file after it loads the higharchy to validate if there is any missing elements in the conf file. I am sorry if I did not include enough of my source in my previous post. I thought I have included all the definitions and declarations of the variables and functions you needed on a minimal scale.

btw I have attched the source so you can see what line 34 does.

Sorry.

Edited 6 Years Ago by matthewl: n/a

Attachments
/*
    DNet IRC Stats Server -- confreader base 
    Copyright (C) 2010  DNet Team
    Contact us at info@devish.net

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
*/
 #include "confreader.h"

// storage class for our dynamic conf blocks
std::set<const char*> block_names;
std::set< const char*>::iterator blockit;

//storage class for block elements

typedef std::multimap<const char*,const char*> eTYPE;
std::multimap<const char*, eTYPE > blocks;
void Conf::Run()
{
//populate "me" core block
Conf::addClass("me");
blocks.insert(std::multimap::value_type("me", eTYPE::value_type("name", "dnet")));
//populate "connect" core block
Conf::addClass("connect");

}

 /** Adds a way we can add a class block check on the fly
	 *
	 * @param char* Name of the class block
	 */
	 void Conf::addClass(const char* name)
	 {
	 	block_names.insert(name);
	 }
	 
	 /** Deletes a class block check on the fly (will destory all data for block)
	 *
	 * @param char* Name of the class block
	 */
	 void Conf::delClass(const char* name)
	 {
	 	 std::set<const char*>::iterator it;
	 	 it = block_names.find(name);
	 	 block_names.find(name);
	 }
	  /** Searchs for class block  in block_names to see if it is added
	 *
	 * @param char* Name of the class block
	 */
	 int Conf::searchClass(const char* name)
	 {
	        std::set<const char*>::iterator it;
	 	it = block_names.find(name);
	 	if(blockit == block_names.end()) return false;
	 	else return true;
	 }
	 /** Adds a way we can add a element to class block on the fly
	 *
	 * @param char* Name of the class block to add too
	 * @param char* The type of element: uses standard C++ variable types
	 * @param char* Name of the element
	 */
	 void Conf::addElement(char* name, char* type, char* element)
	 {
	 }
	 
	  /** Deletes a element on the fly (will destory data)
	 *
	 * @param char* Name of the class block
	 * @param char* Name of the element
	 */
	 void Conf::delElement(char* block, char* element)
	 {
	 }
/*
    DNet IRC Stats Server -- Main Header file 
    Copyright (C) 2010  DNet Team
    Contact us at info@devish.net

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
*/
#ifndef __CONFREADER_H__
#define __CONFREADER_H__

//include our auto headers
#include "config.h"

//our headers we need
#include "classbase.h"
#include "dnetstats.h"

//include required system libraries
#include <ctime>
#include <cstdarg>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdio>

#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <bitset>
#include <set>


class Conf;
class Base;

class Conf : public Base
{
public:
	 
	/** Intialize conf system */
	 void Run(); 
	/** Adds a way we can add a class block check on the fly
	 *
	 * @param string Name of the class block
	 */
	 void addClass(const char* name);
	 
	 /** Deletes a class block check on the fly (will destory all data for block)
	 *
	 * @param char* Name of the class block
	 */
	 void delClass(const char* name);
	 /** Searchs for class block  in block_names to see if it is added
	 *
	 * @param char* Name of the class block
	 */
	 int searchClass(const char* name);

	 
	 /** Adds a way we can add a element to class block on the fly
	 *
	 * @param char* Name of the class block to add too
	 * @param char* The type of element: uses standard C++ variable types
	 * @param char* Name of the element
	 */
	 void addElement(char* block, char* type, char* element);
	 
	 
	  /** Deletes a element on the fly (will destory data)
	 *
	 * @param char* Name of the class block
	 * @param char* Name of the element
	 */
	 void delElement(char* block, char* element);
};
#endif

I was able to solve this problem using this sample code below:

typedef struct {
     const char* element;
     const char* value;
} elem;

multimap<const char*, elem> t;
int main(int argc, char** argv) {
    elem data;
    data.element = "a";
    data.value = "c";
    t.insert(pair<const char*, elem>("b",data));
This question has already been answered. Start a new discussion instead.