Bernard Escaillas
/
MidiTee
memory.h@0:71d791204057, 2011-06-07 (annotated)
- Committer:
- Midimetric
- Date:
- Tue Jun 07 13:32:20 2011 +0000
- Revision:
- 0:71d791204057
Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Midimetric | 0:71d791204057 | 1 | #ifndef MEMORY_H |
Midimetric | 0:71d791204057 | 2 | #define MEMORY_H |
Midimetric | 0:71d791204057 | 3 | |
Midimetric | 0:71d791204057 | 4 | //_____________________________________________________________________________ |
Midimetric | 0:71d791204057 | 5 | class Memory |
Midimetric | 0:71d791204057 | 6 | {//"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
Midimetric | 0:71d791204057 | 7 | private: |
Midimetric | 0:71d791204057 | 8 | public: |
Midimetric | 0:71d791204057 | 9 | char Name[16]; |
Midimetric | 0:71d791204057 | 10 | short Value; |
Midimetric | 0:71d791204057 | 11 | Memory() { Name[0] = 0; Value = 0; } |
Midimetric | 0:71d791204057 | 12 | Memory( char* n, short v ) { strncpy( Name, n, 16 ); Value = v; } |
Midimetric | 0:71d791204057 | 13 | ~Memory() {} |
Midimetric | 0:71d791204057 | 14 | }; |
Midimetric | 0:71d791204057 | 15 | //_____________________________________________________________________________ |
Midimetric | 0:71d791204057 | 16 | class MemList |
Midimetric | 0:71d791204057 | 17 | {//"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
Midimetric | 0:71d791204057 | 18 | private: |
Midimetric | 0:71d791204057 | 19 | short allocated_; // size of allocated list |
Midimetric | 0:71d791204057 | 20 | public: |
Midimetric | 0:71d791204057 | 21 | short Count; // size of initialized list |
Midimetric | 0:71d791204057 | 22 | Memory* List; // list of names |
Midimetric | 0:71d791204057 | 23 | |
Midimetric | 0:71d791204057 | 24 | MemList() : Count(0), List(NULL) {} |
Midimetric | 0:71d791204057 | 25 | |
Midimetric | 0:71d791204057 | 26 | ~MemList() |
Midimetric | 0:71d791204057 | 27 | { |
Midimetric | 0:71d791204057 | 28 | if( List != NULL ) free( List ); |
Midimetric | 0:71d791204057 | 29 | Count = allocated_ = 0; |
Midimetric | 0:71d791204057 | 30 | } |
Midimetric | 0:71d791204057 | 31 | void Add( Memory &m ) |
Midimetric | 0:71d791204057 | 32 | { |
Midimetric | 0:71d791204057 | 33 | int n = Find( m.Name ); |
Midimetric | 0:71d791204057 | 34 | if( n == -1 ) |
Midimetric | 0:71d791204057 | 35 | { |
Midimetric | 0:71d791204057 | 36 | if( Count == allocated_ ) List = (Memory*)realloc( List, ( allocated_ += 5 ) * sizeof( Memory ) ); |
Midimetric | 0:71d791204057 | 37 | List[ Count++ ] = m; |
Midimetric | 0:71d791204057 | 38 | } |
Midimetric | 0:71d791204057 | 39 | else |
Midimetric | 0:71d791204057 | 40 | List[n].Value = m.Value; |
Midimetric | 0:71d791204057 | 41 | } |
Midimetric | 0:71d791204057 | 42 | void Add( char* name, short value ) |
Midimetric | 0:71d791204057 | 43 | { |
Midimetric | 0:71d791204057 | 44 | int n = Find( name ); |
Midimetric | 0:71d791204057 | 45 | if( n == -1 ) |
Midimetric | 0:71d791204057 | 46 | { |
Midimetric | 0:71d791204057 | 47 | if( Count == allocated_ ) List = (Memory*)realloc( List, ( allocated_ += 5 ) * sizeof( Memory ) ); |
Midimetric | 0:71d791204057 | 48 | List[ Count++ ] = Memory( name, value ); |
Midimetric | 0:71d791204057 | 49 | } |
Midimetric | 0:71d791204057 | 50 | else |
Midimetric | 0:71d791204057 | 51 | List[n].Value = value; |
Midimetric | 0:71d791204057 | 52 | } |
Midimetric | 0:71d791204057 | 53 | short Find( char* name ) |
Midimetric | 0:71d791204057 | 54 | { |
Midimetric | 0:71d791204057 | 55 | for( short i = 0 ; i < Count ; i++ ) |
Midimetric | 0:71d791204057 | 56 | if( strcmp( List[i].Name, name ) == 0 ) |
Midimetric | 0:71d791204057 | 57 | return i; |
Midimetric | 0:71d791204057 | 58 | return -1; |
Midimetric | 0:71d791204057 | 59 | } |
Midimetric | 0:71d791204057 | 60 | short Get( char* name ) |
Midimetric | 0:71d791204057 | 61 | { |
Midimetric | 0:71d791204057 | 62 | for( short i = 0 ; i < Count ; i++ ) |
Midimetric | 0:71d791204057 | 63 | if( strcmp( List[i].Name, name ) == 0 ) |
Midimetric | 0:71d791204057 | 64 | return List[i].Value; |
Midimetric | 0:71d791204057 | 65 | return 0; |
Midimetric | 0:71d791204057 | 66 | } |
Midimetric | 0:71d791204057 | 67 | void Set( char* name, short value ) |
Midimetric | 0:71d791204057 | 68 | { |
Midimetric | 0:71d791204057 | 69 | for( short i = 0 ; i < Count ; i++ ) |
Midimetric | 0:71d791204057 | 70 | if( strcmp( List[i].Name, name ) == 0 ) |
Midimetric | 0:71d791204057 | 71 | { |
Midimetric | 0:71d791204057 | 72 | List[i].Value = value; |
Midimetric | 0:71d791204057 | 73 | break; |
Midimetric | 0:71d791204057 | 74 | } |
Midimetric | 0:71d791204057 | 75 | } |
Midimetric | 0:71d791204057 | 76 | }; |
Midimetric | 0:71d791204057 | 77 | |
Midimetric | 0:71d791204057 | 78 | #endif |