int_array.h

Go to the documentation of this file.
00001 /*
00002  * int_array.h
00003  *
00004  * Programmer(s): Chris Harvey, Michael Paluszek, David Wilson, Lavanya Swetharanyan, Wil Turner
00005  *
00006  * Copyright 1996-2004, Princeton Satellite Systems. All rights reserved.
00007  *
00008  * The ml_int_array class is a utility for certain matrix manipulations. 
00009  *
00010  */
00011 
00012 #ifndef __INT_ARRAY__
00013 #define __INT_ARRAY__
00014 
00020 
00021 #define ML_MAX_NUM_LEN  100
00022 #include <signal.h>
00023 #include <stdio.h>
00024 #include <unistd.h>
00025 
00026 extern "C++"
00027 {
00028 
00030 
00033 typedef enum
00034 {
00035     ml_equal_to,                    
00036     ml_not_equal_to,                
00037     ml_less_than,                   
00038     ml_greater_than,                
00039     ml_less_than_or_equal_to,       
00040     ml_greater_than_or_equal_to     
00041 } ml_comparison;
00042 
00043 void ml_print_trace(int fd);
00044 
00045 inline void ml_error_void(const char *fnc, const char *msg)
00046 {
00047     #ifdef ML_ERR_WARN
00048     ml_print_trace(2);
00049     fprintf (stderr,"There was an error in function %s:\n%s\n", fnc ? fnc : "(no function name supplied)", msg ? msg : "(no error message available)");
00050     #ifdef ML_ERR_ABRT
00051     #ifdef PSS_OS_WINDOWS
00052     assert(0);
00053     #else
00054     raise(SIGABRT);
00055     #endif
00056     #endif
00057     #endif    
00058 }
00059 
00061 class ml_int_array
00062 {
00063     public:
00069 
00070         ml_int_array();
00072         ml_int_array(int msize, const int *v = NULL);
00074         ml_int_array(const ml_int_array &a);
00076         ml_int_array(int start, int finish);
00078         ml_int_array(char *s);
00080         ml_int_array(void *bf);
00081         // Destructor
00082         ~ml_int_array();
00083 
00085         int get(int index) const;
00087         int &operator()(int index);
00089         void operator=(int *vals);
00091         void operator=(int val);
00093         ml_int_array &operator=(const ml_int_array &a);
00094 
00096         int length() const;
00098         int is_empty() const;
00100         ml_int_array find(ml_comparison op, int target) const;
00102         void display(char *s = NULL) const;
00104         char *to_string();
00106         void *to_binary(unsigned short *size = NULL) const;
00108         int is_unique() const;
00110         int sum() const;
00112         int *get_c_arr(int &s) const;
00114         int operator==(const ml_int_array &a);
00116         int operator!=(const ml_int_array &a);
00118         ml_int_array subset(int start, int end);
00120         ml_int_array subset(const ml_int_array &indices);
00121 
00123         void sort(int direction = 0);
00125         void remove(const ml_int_array &indices);
00127         void remove(int index);
00129         void append(ml_int_array b);
00131         void append(int val);
00133         void insert(int index,int val);
00135         void zero();
00137         void ones();
00139         void fliplr();
00141         void setdiff(const ml_int_array &b);
00143     private:
00144         int *arr;
00145         int len;
00146         int real_len;
00147         char *buff;
00148         int buffsize;
00149 };
00150 
00151 }
00152 
00153 #endif