<commit_before>
// (c) COPYRIGHT URI/MIT 1994-1996
// Please read the full copyright statement in the file COPYRIGH.  
//
// Authors:
//      jhrg,jimg       <NAME> (<EMAIL>)

//
// jhrg 7/29/94

// $Log: AttrTable.cc,v $
// Revision 1.20  1998/08/06 16:06:42  jimg
// Now prints aliases as such rather than replicating the aliased entry.
//
// Revision 1.19  1997/08/09 21:18:41  jimg
// Changed/fixed the type comparison in attr_append so that code which calls
// unsigned int `UInt32' won't break (the type is called Uint32, but the das
// parser and scanner accept UInt32 as well).
//
// Revision 1.18  1997/07/15 21:58:04  jimg
// Formatting.
//
// Revision 1.17  1997/06/06 03:12:44  jimg
// Added mfuncs with char * parameters for some of the calls. See AttrTable.h
//
// Revision 1.16  1997/05/13 23:32:11  jimg
// Added changes to handle the new Alias and lexical scoping rules.
//
// Revision 1.15  1997/01/13 16:56:03  jimg
// Changed the name of the private member `map' to `attr_map' to avoid a name
// collision with the STL'd map class.
//
// Revision 1.14  1996/08/13 20:49:30  jimg
// Added __unused__ to definition of char rcsid[].
//
// Revision 1.13  1996/05/31 23:29:21  jimg
// Updated copyright notice.
//
// Revision 1.12  1996/04/05 00:21:18  jimg
// Compiled with g++ -Wall and fixed various warnings.
//
// Revision 1.11  1995/07/09  21:28:50  jimg
// Added copyright notice.
//
// Revision 1.10  1995/02/10  02:27:53  jimg
// Fixed an error where two attributes could be declared with the same name
// (for the same variable) if they hade different types.
//
// Revision 1.9  1994/12/21  03:03:37  reza
// Added overloading functions for get_attr_num().
//
// Revision 1.8  1994/12/07  21:09:24  jimg
// Added support for vectors of attributes (using XPlex from libg++).
//
// Revision 1.7  1994/10/13  15:43:29  jimg
// Added a new version of append_attr that takes (const char *)s and modified
// the version that takes strings to take (const String &).
//
// Revision 1.6  1994/10/05  16:38:17  jimg
// Changed internal representation of the attribute table from a Map
// to a DLList<>.
//
// Revision 1.5  1994/09/27  22:42:44  jimg
// Changed definition of the class AttrTable; it no longer inherits from
// AttrVHMap, instead it uses that class (contains a member that is an instance
// of AttrVHMap).
// Added mfuncs to AttrTable so that the new member could be set/accessed.
//
// Revision 1.4  1994/09/09  15:26:39  jimg
// Removed operator<< and added print() since I have no good way to define
// operator>>. It seems best to define all operators from a set (like <<, >>)
// or none at all. Since parse() is the input mfunc, it seems that output
// should be a mfunc too.
//
// Revision 1.3  1994/08/02  20:11:27  jimg
// Changes operator<< so that it writes a parsable version of the
// attribute table.
//' comments and rcsid[] variables (syntax errors due to //
// comments caused compilation failures.
// das.tab.c and .h are commited now as well.
//
// Revision 1.1  1994/08/02  18:32:04  jimg
// The implementation of AttrTable. This file defined ostream &operator<< and
// a static class variable String empty (it is initialized to "").
//

#include "config_dap.h"

static char rcsid[] __unused__ ="$Id: AttrTable.cc,v 1.20 1998/08/06 16:06:42 jimg Exp $";

#ifdef __GNUG__
#pragma implementation
#endif

#include <assert.h>

#include <ostream.h>

#include "AttrTable.h"

// Private member functions

// When CON_ONLY is true, stop recurring when at the last container.
// This ensures that the Pix returned will reference the AttrTable which
// containes the attribute - not the attribute itself.
Pix 
AttrTable::find(const String &target, bool cont_only = false)
{
    if (target.contains(".")) {
	String name = (String)target; // cast away const
	String container = name.before(".");
	String field = name.after(".");
	
	Pix p = simple_find(container);
	if ((p) && attr_map(p).type == Attr_container) {
	    if (cont_only && !field.contains("."))
		return p;
	    else
		return attr_map(p).value.attributes->find(field, cont_only);
	}
	else
	    return 0;
    }
    else
	return simple_find(target);
}

Pix
AttrTable::simple_find(const String &target)
{
    for (Pix p = attr_map.first(); p; attr_map.next(p))
	if (target == attr_map(p).name)
	    return p;
    return 0;
}

String 
AttrTable::AttrType_to_String(const AttrType at)
{
    switch (at) {
      case Attr_container: return "Container";
      case Attr_byte: return "Byte";
      case Attr_int32: return "Int32";
      case Attr_uint32: return "Uint32";
      case Attr_float64: return "Float64";
      case Attr_string: return "String";
      case Attr_url: return "Url";
      default: return "";
    }
}

AttrType
AttrTable::String_to_AttrType(const String &s)
{
    String s2 = capitalize(s);
    if (s2 == "Container")
	return Attr_container;
    else if (s2 == "Byte")
	return Attr_byte;
    else if (s2 == "Int32")
	return Attr_int32;
    else if (s2 == "Uint32")
	return Attr_uint32;
    else if (s2 == "UInt32")	// Support two spellings...
	return Attr_uint32;
    else if (s2 == "Float64")
	return Attr_float64;
    else if (s2 == "String")
	return Attr_string;
    else if (s2 == "Url")
	return Attr_url;
    else 
	return Attr_unknown;
}

// Public member functions

AttrTable::AttrTable()
{
}

AttrTable::~AttrTable()
{
    for (Pix p = attr_map.first(); p; attr_map.next(p))
	// Don't delete the referenced objects in an alias!
	if (!attr_map(p).is_alias)
	    if (attr_map(p).type == Attr_container)
		delete attr_map(p).value.attributes;
	    else
		delete attr_map(p).value.attr;
}
<commit_msg>Added instrumentation. Used while I was removing DASVHMap.<commit_after>
// (c) COPYRIGHT URI/MIT 1994-1996
// Please read the full copyright statement in the file COPYRIGH.  
//
// Authors:
//      jhrg,jimg       <NAME> (<EMAIL>)

//
// jhrg 7/29/94

// $Log: AttrTable.cc,v $
// Revision 1.21  1998/11/24 06:50:07  jimg
// Added instrumentation. Used while I was removing DASVHMap.
//
// Revision 1.20  1998/08/06 16:06:42  jimg
// Now prints aliases as such rather than replicating the aliased entry.
//
// Revision 1.19  1997/08/09 21:18:41  jimg
// Changed/fixed the type comparison in attr_append so that code which calls
// unsigned int `UInt32' won't break (the type is called Uint32, but the das
// parser and scanner accept UInt32 as well).
//
// Revision 1.18  1997/07/15 21:58:04  jimg
// Formatting.
//
// Revision 1.17  1997/06/06 03:12:44  jimg
// Added mfuncs with char * parameters for some of the calls. See AttrTable.h
//
// Revision 1.16  1997/05/13 23:32:11  jimg
// Added changes to handle the new Alias and lexical scoping rules.
//
// Revision 1.15  1997/01/13 16:56:03  jimg
// Changed the name of the private member `map' to `attr_map' to avoid a name
// collision with the STL'd map class.
//
// Revision 1.14  1996/08/13 20:49:30  jimg
// Added __unused__ to definition of char rcsid[].
//
// Revision 1.13  1996/05/31 23:29:21  jimg
// Updated copyright notice.
//
// Revision 1.12  1996/04/05 00:21:18  jimg
// Compiled with g++ -Wall and fixed various warnings.
//
// Revision 1.11  1995/07/09  21:28:50  jimg
// Added copyright notice.
//
// Revision 1.10  1995/02/10  02:27:53  jimg
// Fixed an error where two attributes could be declared with the same name
// (for the same variable) if they hade different types.
//
// Revision 1.9  1994/12/21  03:03:37  reza
// Added overloading functions for get_attr_num().
//
// Revision 1.8  1994/12/07  21:09:24  jimg
// Added support for vectors of attributes (using XPlex from libg++).
//
// Revision 1.7  1994/10/13  15:43:29  jimg
// Added a new version of append_attr that takes (const char *)s and modified
// the version that takes strings to take (const String &).
//
// Revision 1.6  1994/10/05  16:38:17  jimg
// Changed internal representation of the attribute table from a Map
// to a DLList<>.
//
// Revision 1.5  1994/09/27  22:42:44  jimg
// Changed definition of the class AttrTable; it no longer inherits from
// AttrVHMap, instead it uses that class (contains a member that is an instance
// of AttrVHMap).
// Added mfuncs to AttrTable so that the new member could be set/accessed.
//
// Revision 1.4  1994/09/09  15:26:39  jimg
// Removed operator<< and added print() since I have no good way to define
// operator>>. It seems best to define all operators from a set (like <<, >>)
// or none at all. Since parse() is the input mfunc, it seems that output
// should be a mfunc too.
//
// Revision 1.3  1994/08/02  20:11:27  jimg
// Changes operator<< so that it writes a parsable version of the
// attribute table.
//' comments and rcsid[] variables (syntax errors due to //
// comments caused compilation failures.
// das.tab.c and .h are commited now as well.
//
// Revision 1.1  1994/08/02  18:32:04  jimg
// The implementation of AttrTable. This file defined ostream &operator<< and
// a static class variable String empty (it is initialized to "").
//

#include "config_dap.h"

static char rcsid[] __unused__ ="$Id: AttrTable.cc,v 1.21 1998/11/24 06:50:07 jimg Exp $";

#ifdef __GNUG__
#pragma implementation
#endif

#include <assert.h>

#include <ostream.h>

#include "AttrTable.h"
#include "debug.h"

// Private member functions

// When CON_ONLY is true, stop recurring when at the last container.
// This ensures that the Pix returned will reference the AttrTable which
// containes the attribute - not the attribute itself.
Pix 
AttrTable::find(const String &target, bool cont_only = false)
{
    if (target.contains(".")) {
	String name = (String)target; // cast away const
	String container = name.before(".");
	String field = name.after(".");
	
	Pix p = simple_find(container);
	if ((p) && attr_map(p).type == Attr_container) {
	    if (cont_only && !field.contains("."))
		return p;
	    else
		return attr_map(p).value.attributes->find(field, cont_only);
	}
	else
	    return 0;
    }
    else
	return simple_find(target);
}

Pix
AttrTable::simple_find(const String &target)
{
    for (Pix p = attr_map.first(); p; attr_map.next(p))
	if (target == attr_map(p).name)
	    return p;
    return 0;
}

String 
AttrTable::AttrType_to_String(const AttrType at)
{
    switch (at) {
      case Attr_container: return "Container";
      case Attr_byte: return "Byte";
      case Attr_int32: return "Int32";
      case Attr_uint32: return "Uint32";
      case Attr_float64: return "Float64";
      case Attr_string: return "String";
      case Attr_url: return "Url";
      default: return "";
    }
}

AttrType
AttrTable::String_to_AttrType(const String &s)
{
    String s2 = capitalize(s);
    if (s2 == "Container")
	return Attr_container;
    else if (s2 == "Byte")
	return Attr_byte;
    else if (s2 == "Int32")
	return Attr_int32;
    else if (s2 == "Uint32")
	return Attr_uint32;
    else if (s2 == "UInt32")	// Support two spellings...
	return Attr_uint32;
    else if (s2 == "Float64")
	return Attr_float64;
    else if (s2 == "String")
	return Attr_string;
    else if (s2 == "Url")
	return Attr_url;
    else 
	return Attr_unknown;
}

// Public member functions

AttrTable::AttrTable()
{
}

AttrTable::~AttrTable()
{
    DBG(cerr << "Entering ~AttrTable" << endl);

    if (attr_map.empty()) {
	DBG(cerr << "Found empty attr table" << endl);
	goto exit;
    }

    for (Pix p = attr_map.first(); p; attr_map.next(p))
	// Don't delete the referenced objects in an alias!
	if (!attr_map(p).is_alias) {
	    DBG(cerr << "attr_map(p).type: " << attr_map(p).type << endl);
	    DBG(cerr << "attr_map(p).name: " << attr_map(p).name << endl);
	    if (attr_map(p).type == Attr_container)
		delete attr_map(p).value.attributes;
	    else
		delete attr_map(p).value.attr;
	}

 exit:
    DBG(cerr << "Leaving ~AttrTable" << endl);
    return;
}

{'fraction_non_alphanumeric': 0.12832497662955725, 'fraction_numerical': 0.0677317923005014, 'mean_word_length': 3.0551343900758097, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5642577', 'n_tokens_mistral': 4607, 'n_tokens_neox': 4045, 'n_words': 1396}