argument_list.cpp

Go to the documentation of this file.
00001 #ifndef ARGUMENT_LIST_IMPLEMENTATION_FILE
00002 #define ARGUMENT_LIST_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : argument_list                                                     *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "argument_list.h"
00019 #include "wp_implementation.h"
00020 #include "strings.h"
00021 
00022 #include <basis/array.cpp>
00023 
00024 argument_list::argument_list()
00025 : array<argument_holder>(0), created_list(NIL) {}
00026 
00027 argument_list::argument_list(const argument_list &to_copy)
00028 : array<argument_holder>(0), created_list(NIL)
00029 { *this = to_copy; }
00030 
00031 argument_list::~argument_list() { zap_created_list(); }
00032 
00033 int argument_list::number() const { return length(); }
00034 
00035 void argument_list::zap_created_list()
00036 { if (created_list) { delete [] created_list; created_list = NIL; } }
00037 
00038 void argument_list::add(String argument_name, int contents)
00039 { add(argument_name, long(contents)); }
00040 
00041 void argument_list::add(String argument_name, XtArgVal contents)
00042 {
00043   zap_created_list();
00044   argument_holder to_store;
00045   to_store.name = argument_name;
00046   to_store.argument = contents;
00047   insert(length(), 1);
00048   put(length() - 1, to_store);
00049 }
00050 
00051 void argument_list::add(String argument_name, window_string contents)
00052 { zap_created_list(); add(argument_name, XtArgVal(contents)); }
00053 
00054 void argument_list::add(String argument_name, const istring &contents)
00055 { zap_created_list(); add(argument_name, window_string(contents.s())); }
00056 
00057 void argument_list::remove(String argument_name)
00058 {
00059   FUNCDEF("remove");
00060 LOG("untested argument_list remove called");
00061   zap_created_list();
00062   for (int i = 0; i < length(); i++)
00063     if (istring(get(i).name) == istring(argument_name)) zap(i, i);
00064 }
00065 
00066 Arg *argument_list::generate()
00067 {
00068   if (created_list) return created_list;
00069   if (!length()) return NIL;
00070   created_list = new Arg[length()];
00071   for (int i = 0; i < length(); i++) {
00072     XtSetArg(created_list[i], get(i).name, get(i).argument);
00073   }
00074   return created_list;
00075 }
00076 
00077 void argument_list::apply(window_handle to_apply_to)
00078 {
00079   FUNCDEF("apply");
00080   if (!to_apply_to) {
00081     LOG("argument_list::apply: NIL window handle!");
00082     return;
00083   }
00084   XtSetValues(to_apply_to, generate(), number());
00085 }  
00086 
00087 argument_list &argument_list::operator = (const argument_list &to_copy)
00088 {
00089   if (this == &to_copy) return *this;
00090   created_list = NIL;
00091   array<argument_holder>::operator =(to_copy);
00092   return *this;
00093 }
00094 
00095 
00096 #endif //ARGUMENT_LIST_IMPLEMENTATION_FILE
00097 

Generated on Thu Nov 20 04:28:51 2008 for HOOPLE Libraries by  doxygen 1.5.1