Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source demo lang Array_S.h
Document Actions

Array_S.h

by Michael L Powell last modified 2007-01-26 03:20

Click here to get the file

Size 1.4 kB - File type text/plain

File contents

/*ident	"@(#)cls4:demo/lang/Array_S.h	1.1" */
/*#########################################################################
#                       Copyright (c) 1991 AT&T
#                         All Rights Reserved   
#
#                THIS IS PROPRIETARY SOURCE CODE OF AT&T
#       
#                     This code has been published in
#                         C++ Primer, 2nd Edition 
#			    by Stanley Lippman
#                    Addison_Wesley Publishing Company
#
#########################################################################*/
#ifndef ARRAY_S_H_
#define ARRAY_S_H_
#include "Array.h"

template <class Type>
class Array_Sort : public virtual Array<Type> {
protected:
    void set_bit() { dirty_bit = 1; }
    void clear_bit() { dirty_bit = 0; }
    void check_bit() { 
      if (dirty_bit) { sort(0,size-1); clear_bit(); }
    }
public:
    Array_Sort(const Array_Sort&);
    Array_Sort(int sz=ArraySize);

    Array_Sort(Type* arr, int sz) 
        : Array<Type>(arr, sz)
	{ sort(0,size-1); clear_bit(); }

    Type& operator[](int ix) 
	{ set_bit(); return ia[ix]; }

    void print(ostream& os = cout) 
	{ check_bit(); Array<Type>::print(os); }

    Type min() { check_bit(); return ia[0]; }
    Type max() { check_bit(); return ia[size-1]; }

    int is_dirty() const { return dirty_bit; }
    int find(Type);
    void grow(); 

protected:
    char dirty_bit;
};

#endif
« October 2014 »
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: