<commit_before>
/*
 * enumeration.c
 *
 * (C) Copyright IBM Corp. 2005
 *
 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
 * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
 * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
 *
 * You can obtain a current copy of the Eclipse Public License from
 * http://www.opensource.org/licenses/eclipse-1.0.php
 *
 * Author:        <NAME>
 * Contributions: <NAME> <<EMAIL>>
 *
 * Description:
 *
 * CMPIEnumeration implementation.
 *
*/


#include "native.h"


struct native_enum {
   CMPIEnumeration enumeration;
   int refCount;
   int mem_state;

   CMPICount current;
   CMPIArray *data;
};


extern void adjustArrayElementRefCount(CMPIArray * array, int n);
static struct native_enum *__new_enumeration(int, CMPIArray *, CMPIStatus *);


/*****************************************************************************/

static CMPIStatus __eft_release(CMPIEnumeration * enumeration)
{
   struct native_enum *e = (struct native_enum *) enumeration;

   if (e->mem_state && e->mem_state != MEM_RELEASED) {
      e->data->ft->release(e->data);
      memUnlinkEncObj(e->mem_state);
      e->mem_state = MEM_RELEASED;
      free(enumeration);
      CMReturn(CMPI_RC_OK);
   }
   
   CMReturn(CMPI_RC_ERR_FAILED);
}


static CMPIEnumeration *__eft_clone(const CMPIEnumeration * enumeration,
                                    CMPIStatus * rc)
{
   CMPIStatus tmp;
   struct native_enum *e = (struct native_enum *) enumeration;
   CMPIArray *data = CMClone(e->data, &tmp);

   if (tmp.rc != CMPI_RC_OK) {
      if (rc) CMSetStatus(rc, CMPI_RC_ERR_FAILED);
      return NULL;
   }

   return (CMPIEnumeration *) __new_enumeration(MEM_NOT_TRACKED, data, rc);
}


static CMPIData __eft_getNext(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
   return CMGetArrayElementAt(e->data, e->current++, rc);
}


static CMPIBoolean __eft_hasNext(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
   return (e->current < CMGetArrayCount(e->data, rc));
}


static CMPIArray *__eft_toArray(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
   rc->rc = CMPI_RC_OK;
   return e->data;
}

static CMPIEnumerationFT eft = {
   NATIVE_FT_VERSION,<commit_msg>Small fix to test for optional CMPIStatus parameter. Thanks Anas !<commit_after>
/*
 * enumeration.c
 *
 * (C) Copyright IBM Corp. 2005
 *
 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
 * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
 * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
 *
 * You can obtain a current copy of the Eclipse Public License from
 * http://www.opensource.org/licenses/eclipse-1.0.php
 *
 * Author:        <NAME>
 * Contributions: <NAME> <<EMAIL>>
 *
 * Description:
 *
 * CMPIEnumeration implementation.
 *
*/


#include "native.h"


struct native_enum {
   CMPIEnumeration enumeration;
   int refCount;
   int mem_state;

   CMPICount current;
   CMPIArray *data;
};


extern void adjustArrayElementRefCount(CMPIArray * array, int n);
static struct native_enum *__new_enumeration(int, CMPIArray *, CMPIStatus *);


/*****************************************************************************/

static CMPIStatus __eft_release(CMPIEnumeration * enumeration)
{
   struct native_enum *e = (struct native_enum *) enumeration;

   if (e->mem_state && e->mem_state != MEM_RELEASED) {
      e->data->ft->release(e->data);
      memUnlinkEncObj(e->mem_state);
      e->mem_state = MEM_RELEASED;
      free(enumeration);
      CMReturn(CMPI_RC_OK);
   }
   
   CMReturn(CMPI_RC_ERR_FAILED);
}


static CMPIEnumeration *__eft_clone(const CMPIEnumeration * enumeration,
                                    CMPIStatus * rc)
{
   CMPIStatus tmp;
   struct native_enum *e = (struct native_enum *) enumeration;
   CMPIArray *data = CMClone(e->data, &tmp);

   if (tmp.rc != CMPI_RC_OK) {
      if (rc) CMSetStatus(rc, CMPI_RC_ERR_FAILED);
      return NULL;
   }

   return (CMPIEnumeration *) __new_enumeration(MEM_NOT_TRACKED, data, rc);
}


static CMPIData __eft_getNext(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
   return CMGetArrayElementAt(e->data, e->current++, rc);
}


static CMPIBoolean __eft_hasNext(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
   return (e->current < CMGetArrayCount(e->data, rc));
}


static CMPIArray *__eft_toArray(const CMPIEnumeration * enumeration, CMPIStatus * rc)
{
   struct native_enum *e = (struct native_enum *) enumeration;
	if ( rc ) CMSetStatus ( rc, CMPI_RC_OK );
   return e->data;
}

static CMPIEnumerationFT eft = {
   NATIVE_FT_VERSION,
{'fraction_non_alphanumeric': 0.13601299228583028, 'fraction_numerical': 0.00243605359317905, 'mean_word_length': 3.9418254764292877, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3569748', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1649, 'n_words': 392}